diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 4cab2341b00be..f340fe6f0b96d 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -739,7 +739,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 @@ -747,6 +747,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; } @@ -897,7 +900,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 @@ -906,8 +909,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 d2b0a3a4c3863..39914c753e179 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -2101,6 +2101,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 @@ -2158,7 +2164,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()) @@ -4152,16 +4164,24 @@ public function dataGetEditableFields() { * @dataProvider dataGetEditableFields * * @param bool $allowedToChangeDisplayName + * @param bool $allowedToChangeEmailAddress * @param string $userBackend * @param array $expected */ - public function testGetEditableFields(bool $allowedToChangeDisplayName, string $userBackend, array $expected) { + public function testGetEditableFields(bool $allowedToChangeDisplayName,bool $allowedToChangeEmailAddress, string $userBackend, array $expected) { $this->config ->method('getSystemValue') ->with( $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($allowedToChangeEmailAddress); $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 4ee359b6fe9b6..99b7bd974aa65 100644 --- a/apps/settings/lib/Controller/UsersController.php +++ b/apps/settings/lib/Controller/UsersController.php @@ -377,9 +377,14 @@ public function setUserSettings(?string $avatarScope = null, IAccountManager::PROPERTY_BIRTHDATE => ['value' => $birthdate, 'scope' => $birthdateScope], ]; $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); @@ -454,7 +459,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 bfac996de2ff4..23d9d54835b55 100644 --- a/apps/settings/lib/Settings/Personal/PersonalInfo.php +++ b/apps/settings/lib/Settings/Personal/PersonalInfo.php @@ -148,6 +148,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 8fd1792272449..7f1983fd952c6 100644 --- a/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue +++ b/apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue @@ -13,6 +13,7 @@ :scope.sync="primaryEmail.scope" @add-additional="onAddAdditionalEmail" /> +