Skip to content

Commit 510eab3

Browse files
authored
Merge pull request #88 from humhub/fix/45-save-button-visibility
Hide the save button when user has no permission to manage translations
2 parents 4250e18 + 6742428 commit 510eab3

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Changelog
2222
- Enh #82: Migration to Bootstrap 5 for HumHub 1.18
2323
- Enh #83: Improved Module Test GitHub Actions
2424
- Enh #84: Implemented `module-coding-standards`
25+
- Fix #88: Hide the save button when user has no permission to manage translations
2526

2627
1.0.0 (June 10, 2020)
2728
-----------------------

models/forms/TranslationForm.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected function loadMessages()
216216
protected function autoTranslateEmptyValues(int $queryStart = 1)
217217
{
218218
// Get target language code
219-
$targetLanguageCode = strtr($this->language, static::HUMHUB_LANGUAGE_CODE_TO_GOOGLE_TRANSLATE);
219+
$targetLanguageCode = strtr((string)$this->language, static::HUMHUB_LANGUAGE_CODE_TO_GOOGLE_TRANSLATE);
220220

221221
// Check if code is supported by Google translate
222222
if (!in_array($targetLanguageCode, static::GOOGLE_TRANSLATE_SUPPORTED_LANGUAGES)) {
@@ -294,13 +294,19 @@ protected function autoTranslateEmptyValues(int $queryStart = 1)
294294
}
295295
}
296296

297+
public function canManage(): bool
298+
{
299+
return $this->space instanceof Space
300+
&& $this->space->can(ManageTranslations::class);
301+
}
302+
297303
/**
298304
* @return bool
299305
* @throws \yii\base\Exception
300306
*/
301307
public function save()
302308
{
303-
if (!$this->space || !$this->space->can(ManageTranslations::class)) {
309+
if (!$this->canManage()) {
304310
return false;
305311
}
306312

widgets/views/translationForm.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515

1616
$errors = null;
1717

18-
if($model->hasErrors()) {
18+
if ($model->hasErrors()) {
1919
$errors = Html::errorSummary($model, [
20-
'header' => '<strong>'.Yii::t('TranslationModule.base', 'The translations for {settings} could not be loaded:', $model->getMessageSettingString()).'</strong>',
20+
'header' => '<strong>' . Yii::t('TranslationModule.base', 'The translations for {settings} could not be loaded:', $model->getMessageSettingString()) . '</strong>',
2121
]);
2222

2323
// Fallback to default selection
2424
$model = new TranslationForm();
2525
$model->load([]);
2626

27-
if(!$model->validate()) {
27+
if (!$model->validate()) {
2828
throw new NotFoundHttpException();
2929
}
3030
}
3131

3232
$hasParentLanguage = $model->getParentLanguage() !== null;
33+
$canManage = $model->canManage();
3334
?>
3435

3536
<?= Html::beginTag('div', $options) ?>
@@ -72,7 +73,7 @@
7273

7374
<div class="panel-body">
7475

75-
<?php if(!empty($errors)) : ?>
76+
<?php if (!empty($errors)) : ?>
7677

7778
<div class="alert alert-danger">
7879
<?= $errors ?>
@@ -95,7 +96,7 @@
9596
</div>
9697

9798
<p class="clearfix" style="margin-bottom:0">
98-
<?= Button::save()->submit()->right() ?>
99+
<?= $canManage ? Button::save()->submit()->right() : '' ?>
99100
</p>
100101

101102
<hr class="mt-0">
@@ -111,21 +112,27 @@
111112
<div class="elem">
112113
<div class="pre"><?= Html::encode($original) ?></div>
113114
<div>
114-
<?= Button::light('<span>' . Yii::t('TranslationModule.base', 'Adopt original language') . '</span>')
115+
<?= $canManage
116+
? Button::light('<span>' . Yii::t('TranslationModule.base', 'Adopt original language') . '</span>')
115117
->icon('arrow-right')
116118
->action('copyOriginal')
117119
->tooltip(Yii::t('TranslationModule.base', 'Adopt original language'))
118-
->loader(false) ?>
120+
->loader(false)
121+
: '' ?>
119122
</div>
120123
</div>
121124
<div class="elem <?= $model->getTranslationFieldClass($original) ?>">
122125
<div>
123-
<?= Html::textArea(TranslationLog::tid($original), $translated, [
124-
'class' => 'form-control translation ' . (empty($translated) ? 'empty' : 'translated'),
125-
'placeholder' => $model->parentMessages[$original] ?? '',
126-
]) ?>
126+
<?php if ($canManage) : ?>
127+
<?= Html::textArea(TranslationLog::tid($original), $translated, [
128+
'class' => 'form-control translation ' . (empty($translated) ? 'empty' : 'translated'),
129+
'placeholder' => $model->parentMessages[$original] ?? '',
130+
]) ?>
131+
<?php else : ?>
132+
<div class="pre"><?= Html::encode($translated) ?></div>
133+
<?php endif; ?>
127134

128-
<?php if(!empty($model->getHelpBlockMessage($original))) : ?>
135+
<?php if (!empty($model->getHelpBlockMessage($original))) : ?>
129136
<p class="form-text"><?= Html::encode($model->getHelpBlockMessage($original)) ?></p>
130137
<?php endif; ?>
131138
</div>
@@ -136,13 +143,14 @@
136143
->tooltip(Yii::t('TranslationModule.base', 'View translation history'))
137144
->loader(false) ?>
138145

139-
<?= $hasParentLanguage ?
140-
Button::success('<span>' . Yii::t('TranslationModule.base', 'Confirm translation') . '</span>')
146+
<?= $hasParentLanguage && $canManage
147+
? Button::success('<span>' . Yii::t('TranslationModule.base', 'Confirm translation') . '</span>')
141148
->icon('check')
142149
->action('copyParent')
143150
->tooltip(Yii::t('TranslationModule.base', 'Confirm translation'))
144151
->cssClass($translated === '' ? '' : 'translation-confirm-approved')
145-
->loader(false) : '' ?>
152+
->loader(false)
153+
: '' ?>
146154
</div>
147155
</div>
148156
</div>
@@ -152,7 +160,7 @@
152160
<hr>
153161

154162
<p class="clearfix">
155-
<?= Button::save()->submit()->right() ?>
163+
<?= $canManage ? Button::save()->submit()->right() : '' ?>
156164
</p>
157165
<?php endif; ?>
158166
</div>

0 commit comments

Comments
 (0)