Fix user settings updating on disabled visibility "Guest" (#5779)

* Fix user settings updating on disabled visibility "Guest"

* Display "Hidden" visibility for users

* Update CHANGELOG_DEV.md (#5779)

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
Yuriy Bakhtin 2022-07-07 15:19:52 +03:00 committed by GitHub
parent abd740e1e1
commit f8d4334b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 9 deletions

View File

@ -1,6 +1,7 @@
1.12.0-beta.2 (Unreleased)
-----------------------------
- Enh #5788: Limit picker results for country filter on "People" page
- Fix #5779: Fix user settings updating on disabled visibility "Guest"
1.12.0-beta.1 (June 27, 2022)
-----------------------------

View File

@ -159,7 +159,7 @@ class User extends ContentContainerActiveRecord implements IdentityInterface, Se
}],
[['created_by', 'updated_by'], 'integer'],
[['status'], 'in', 'range' => array_keys(self::getStatusOptions())],
[['visibility'], 'in', 'range' => array_keys(self::getVisibilityOptions())],
[['visibility'], 'in', 'range' => array_keys(self::getVisibilityOptions()), 'on' => Profile::SCENARIO_EDIT_ADMIN],
[['tagsField', 'blockedUsersField'], 'safe'],
[['guid'], 'string', 'max' => 45],
[['time_zone'], 'validateTimeZone'],

View File

@ -8,15 +8,17 @@
namespace humhub\modules\user\models\forms;
use humhub\modules\user\helpers\AuthHelper;
use humhub\modules\user\models\User;
use Yii;
use yii\base\Model;
/**
* Form Model for changing basic account settings
*
* @since 0.9
*/
class AccountSettings extends \yii\base\Model
class AccountSettings extends Model
{
public $tags;
@ -36,7 +38,8 @@ class AccountSettings extends \yii\base\Model
[['show_introduction_tour'], 'boolean'],
[['timeZone'], 'in', 'range' => \DateTimeZone::listIdentifiers()],
['language', 'in', 'range' => array_keys(Yii::$app->i18n->getAllowedLanguages())],
['visibility', 'in', 'range' => array_keys(User::getVisibilityOptions(false))],
['visibility', 'in', 'range' => array_keys($this->getVisibilityOptions()),
'when' => function (self $model) {return $model->isVisibilityEditable();}],
];
}
@ -62,4 +65,42 @@ class AccountSettings extends \yii\base\Model
];
}
public function getTags(): array
{
return is_array($this->tags) ? $this->tags : [];
}
public function isHiddenUser(): bool
{
return Yii::$app->user->getIdentity()->visibility == User::VISIBILITY_HIDDEN;
}
public function isVisibilityViewable(): bool
{
return AuthHelper::isGuestAccessEnabled();
}
public function isVisibilityEditable(): bool
{
return Yii::$app->user->isAdmin() ||
($this->isVisibilityViewable() && !$this->isHiddenUser());
}
public function getVisibilityOptions(): array
{
$options = [
User::VISIBILITY_REGISTERED_ONLY => Yii::t('UserModule.account', 'Registered users only'),
];
if (AuthHelper::isGuestAccessEnabled()) {
$options[User::VISIBILITY_ALL] = Yii::t('UserModule.account', 'Visible for all (also unregistered users)');
}
if ($this->isHiddenUser() || Yii::$app->user->isAdmin()) {
$options[User::VISIBILITY_HIDDEN] = Yii::t('AdminModule.user', 'Invisible');
}
return $options;
}
}

View File

@ -2,10 +2,8 @@
use humhub\libs\TimezoneHelper;
use humhub\modules\content\widgets\ContainerTagPicker;
use humhub\modules\user\helpers\AuthHelper;
use humhub\modules\ui\form\widgets\ActiveForm;
use humhub\modules\user\models\forms\AccountSettings;
use humhub\modules\user\models\User;
use humhub\modules\user\widgets\UserPickerField;
/* @var AccountSettings $model */
@ -24,10 +22,9 @@ use humhub\modules\user\widgets\UserPickerField;
<?= $form->field($model, 'timeZone')->dropDownList(TimezoneHelper::generateList(true), ['data-ui-select2' => '']); ?>
<?php if (AuthHelper::isGuestAccessEnabled()): ?>
<?= $form->field($model, 'visibility')->dropDownList([
User::VISIBILITY_REGISTERED_ONLY => Yii::t('UserModule.account', 'Registered users only'),
User::VISIBILITY_ALL => Yii::t('UserModule.account', 'Visible for all (also unregistered users)'),
<?php if ($model->isVisibilityViewable()): ?>
<?= $form->field($model, 'visibility')->dropDownList($model->getVisibilityOptions(), [
'disabled' => !$model->isVisibilityEditable()
]); ?>
<?php endif; ?>