Fix visibility of email requiring on backoffice add user form (#5264)

This commit is contained in:
Yuriy Bakhtin 2021-08-26 17:18:12 +03:00 committed by GitHub
parent 6c0afe347e
commit 9ad36945ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View File

@ -19,6 +19,7 @@ HumHub Changelog
- Fix #5238: Typo in Offline Page Text
- Fix #5247: Fix translate with not defined language
- Fix #5252: Removed "strong>" from the Dutch translations
- Fix #5262: Fix visibility of email requiring on backoffice add user form
1.9.0 (July 22, 2021)

View File

@ -36,7 +36,6 @@ use Yii;
use yii\base\Exception;
use yii\db\ActiveQuery;
use yii\db\Expression;
use yii\db\Query;
use yii\web\IdentityInterface;
/**
@ -143,7 +142,7 @@ class User extends ContentContainerActiveRecord implements IdentityInterface, Se
*/
public function rules()
{
/* @var $userModule \humhub\modules\user\Module */
/* @var $userModule Module */
$userModule = Yii::$app->getModule('user');
return [
@ -165,13 +164,32 @@ class User extends ContentContainerActiveRecord implements IdentityInterface, Se
[['email'], 'unique'],
[['email'], 'email'],
[['email'], 'string', 'max' => 150],
[['email'], 'required', 'when' => function ($model, $attribute) use ($userModule) {
return $userModule->emailRequired;
[['email'], 'required', 'when' => function () {
return $this->isEmailRequired();
}],
[['guid'], 'unique'],
];
}
public function isEmailRequired(): bool
{
/* @var $userModule Module */
$userModule = Yii::$app->getModule('user');
return $userModule->emailRequired;
}
/**
* @inheritdoc
*/
public function isAttributeRequired($attribute)
{
if ($attribute === 'email') {
return $this->isEmailRequired();
}
return parent::isAttributeRequired($attribute);
}
/**
* Validate attribute time zone
* Force time zone to NULL if browser's time zone cannot be found on server side