diff --git a/CHANGELOG_DEV.md b/CHANGELOG_DEV.md index 2f4c84c309..f5eb708c93 100644 --- a/CHANGELOG_DEV.md +++ b/CHANGELOG_DEV.md @@ -42,3 +42,4 @@ - Enh #4671: Implemented live poll result sharing by BroadCastChannel - Enh #4829: Renamed account "Security" page and make it optional - Enh #4818: Added database related checks (Driver, Collation, Table Engine) +- Fix #4831: Validate username by pattern only on change or for new users diff --git a/protected/humhub/modules/user/models/User.php b/protected/humhub/modules/user/models/User.php index dc8137a103..4045a00cbd 100644 --- a/protected/humhub/modules/user/models/User.php +++ b/protected/humhub/modules/user/models/User.php @@ -150,7 +150,9 @@ class User extends ContentContainerActiveRecord implements IdentityInterface, Se [['username'], 'unique'], [['username'], 'string', 'max' => $userModule->maximumUsernameLength, 'min' => $userModule->minimumUsernameLength], // Client validation is disable due to invalid client pattern validation - [['username'], 'match', 'pattern' => $userModule->validUsernameRegexp, 'message' => Yii::t('UserModule.base', 'Username contains invalid characters.'), 'enableClientValidation' => false], + [['username'], 'match', 'pattern' => $userModule->validUsernameRegexp, 'message' => Yii::t('UserModule.base', 'Username contains invalid characters.'), 'enableClientValidation' => false, 'when' => function ($model, $attribute) { + return $model->getAttribute($attribute) !== $model->getOldAttribute($attribute); + }], [['status', 'created_by', 'updated_by', 'visibility'], 'integer'], [['tags'], 'string'], [['guid'], 'string', 'max' => 45],