diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 6ce46087d8042..9b38f7324d55a 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -610,7 +610,7 @@ public function getEditableFieldsForUser(string $userId): DataResponse { $targetUser = $currentLoggedInUser; } - // Editing self (display, email) + // Editing self (display) if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { if ( $targetUser->getBackend() instanceof ISetDisplayNameBackend @@ -618,6 +618,9 @@ public function getEditableFieldsForUser(string $userId): DataResponse { ) { $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME; } + } + // Editing self (email) + if ($this->config->getSystemValue('allow_user_to_change_email_address', true) !== false) { $permittedFields[] = IAccountManager::PROPERTY_EMAIL; } @@ -753,7 +756,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon $permittedFields = []; if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { - // Editing self (display, email) + // Editing self (display) if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { if ( $targetUser->getBackend() instanceof ISetDisplayNameBackend @@ -762,8 +765,12 @@ public function editUser(string $userId, string $key, string $value): DataRespon $permittedFields[] = self::USER_FIELD_DISPLAYNAME; $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME; } + } + // Editing self (email) + if ($this->config->getSystemValue('allow_user_to_change_email_address', true) !== false) { $permittedFields[] = IAccountManager::PROPERTY_EMAIL; } + $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX; $permittedFields[] = IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX; diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 56a47f23a5cc4..093b565d7c78a 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -2127,6 +2127,12 @@ public function testEditUserSelfEditChangeLanguage() { ['allow_user_to_change_display_name', true, true], ['force_language', false, false], ]); + $this->config->expects($this->any()) + ->method('getSystemValue') + ->willReturnMap([ + ['allow_user_to_change_email_address', true, true], + ['force_language', false, false], + ]); $loggedInUser = $this->createMock(IUser::class); $loggedInUser @@ -2184,7 +2190,13 @@ public function testEditUserSelfEditChangeLanguageButForced($forced) { ['allow_user_to_change_display_name', true, true], ['force_language', false, $forced], ]); - + $this->config->expects($this->any()) + ->method('getSystemValue') + ->willReturnMap([ + ['allow_user_to_change_email_address', true, true], + ['force_language', false, $forced], + ]); + $loggedInUser = $this->createMock(IUser::class); $loggedInUser ->expects($this->any()) @@ -4171,6 +4183,12 @@ public function testGetEditableFields(bool $allowedToChangeDisplayName, string $ $this->equalTo('allow_user_to_change_display_name'), $this->anything() )->willReturn($allowedToChangeDisplayName); + $this->config + ->method('getSystemValue') + ->with( + $this->equalTo('allow_user_to_change_email_address'), + $this->anything() + )->willReturn($allowedToChangeDisplayName); $user = $this->createMock(IUser::class); $this->userSession->method('getUser') diff --git a/apps/settings/lib/Controller/UsersController.php b/apps/settings/lib/Controller/UsersController.php index 89a850c19809a..d54f2048436b4 100644 --- a/apps/settings/lib/Controller/UsersController.php +++ b/apps/settings/lib/Controller/UsersController.php @@ -419,9 +419,14 @@ public function setUserSettings(?string $avatarScope = null, IAccountManager::PROPERTY_FEDIVERSE => ['value' => $fediverse, 'scope' => $fediverseScope], ]; $allowUserToChangeDisplayName = $this->config->getSystemValueBool('allow_user_to_change_display_name', true); + $allowUserToChangeEmailAddress = $this->config->getSystemValueBool('allow_user_to_change_email_address', true); foreach ($updatable as $property => $data) { if ($allowUserToChangeDisplayName === false - && in_array($property, [IAccountManager::PROPERTY_DISPLAYNAME, IAccountManager::PROPERTY_EMAIL], true)) { + && in_array($property, [IAccountManager::PROPERTY_DISPLAYNAME], true)) { + continue; + } + if ($allowUserToChangeEmailAddress === false + && in_array($property, [IAccountManager::PROPERTY_EMAIL], true)) { continue; } $property = $userAccount->getProperty($property); @@ -494,7 +499,7 @@ protected function saveUserSettings(IAccount $userAccount): void { if ($oldEmailAddress !== strtolower($userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue())) { // this is the only permission a backend provides and is also used // for the permission of setting a email address - if (!$userAccount->getUser()->canChangeDisplayName()) { + if (!$userAccount->getUser()->canChangeEmailAddress()) { throw new ForbiddenException($this->l10n->t('Unable to change email address')); } $userAccount->getUser()->setSystemEMailAddress($userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue()); diff --git a/apps/settings/lib/Settings/Personal/PersonalInfo.php b/apps/settings/lib/Settings/Personal/PersonalInfo.php index 535c160652763..0f5bf5d17afca 100644 --- a/apps/settings/lib/Settings/Personal/PersonalInfo.php +++ b/apps/settings/lib/Settings/Personal/PersonalInfo.php @@ -172,6 +172,7 @@ public function getForm(): TemplateResponse { $accountParameters = [ 'avatarChangeSupported' => $user->canChangeAvatar(), 'displayNameChangeSupported' => $user->canChangeDisplayName(), + 'emailAddressChangeSupported' => $user->canChangeEmailAddress(), 'federationEnabled' => $federationEnabled, 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, ]; diff --git a/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue b/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue index 613b90356c3d7..53714c7c67f32 100644 --- a/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue +++ b/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue @@ -31,7 +31,7 @@ :scope.sync="primaryEmail.scope" @add-additional="onAddAdditionalEmail" /> -