-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[stable30] fix(settings): Handle email change restriction separately from display name change restriction #51900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
| use OCP\UserInterface; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Psr\Log\LoggerInterface; | ||
| use RuntimeException; | ||
| use Test\TestCase; | ||
|
|
||
| class UsersControllerTest extends TestCase { | ||
|
|
@@ -1639,6 +1640,8 @@ public function testEditUserRegularUserSelfEditChangeEmailValid() { | |
| ->method('getBackend') | ||
| ->willReturn($backend); | ||
|
|
||
| $this->config->method('getSystemValue')->willReturnCallback(fn (string $key, mixed $default) => $default); | ||
|
|
||
| $this->assertEquals([], $this->api->editUser('UserToEdit', 'email', '[email protected]')->getData()); | ||
| } | ||
|
|
||
|
|
@@ -1833,6 +1836,8 @@ public function testEditUserRegularUserSelfEditChangeEmailInvalid() { | |
| ->method('getBackend') | ||
| ->willReturn($backend); | ||
|
|
||
| $this->config->method('getSystemValue')->willReturnCallback(fn (string $key, mixed $default) => $default); | ||
|
|
||
| $this->api->editUser('UserToEdit', 'email', 'demo.org'); | ||
| } | ||
|
|
||
|
|
@@ -4224,7 +4229,8 @@ public function testResendWelcomeMessageFailed() { | |
|
|
||
| public function dataGetEditableFields() { | ||
| return [ | ||
| [false, ISetDisplayNameBackend::class, [ | ||
| [false, true, ISetDisplayNameBackend::class, [ | ||
| IAccountManager::PROPERTY_EMAIL, | ||
| IAccountManager::COLLECTION_EMAIL, | ||
| IAccountManager::PROPERTY_PHONE, | ||
| IAccountManager::PROPERTY_ADDRESS, | ||
|
|
@@ -4237,8 +4243,49 @@ public function dataGetEditableFields() { | |
| IAccountManager::PROPERTY_BIOGRAPHY, | ||
| IAccountManager::PROPERTY_PROFILE_ENABLED, | ||
| ]], | ||
| [true, ISetDisplayNameBackend::class, [ | ||
| [true, false, ISetDisplayNameBackend::class, [ | ||
| IAccountManager::PROPERTY_DISPLAYNAME, | ||
| IAccountManager::COLLECTION_EMAIL, | ||
| IAccountManager::PROPERTY_PHONE, | ||
| IAccountManager::PROPERTY_ADDRESS, | ||
| IAccountManager::PROPERTY_WEBSITE, | ||
| IAccountManager::PROPERTY_TWITTER, | ||
| IAccountManager::PROPERTY_FEDIVERSE, | ||
| IAccountManager::PROPERTY_ORGANISATION, | ||
| IAccountManager::PROPERTY_ROLE, | ||
| IAccountManager::PROPERTY_HEADLINE, | ||
| IAccountManager::PROPERTY_BIOGRAPHY, | ||
| IAccountManager::PROPERTY_PROFILE_ENABLED, | ||
| ]], | ||
| [true, true, ISetDisplayNameBackend::class, [ | ||
| IAccountManager::PROPERTY_DISPLAYNAME, | ||
| IAccountManager::PROPERTY_EMAIL, | ||
| IAccountManager::COLLECTION_EMAIL, | ||
| IAccountManager::PROPERTY_PHONE, | ||
| IAccountManager::PROPERTY_ADDRESS, | ||
| IAccountManager::PROPERTY_WEBSITE, | ||
| IAccountManager::PROPERTY_TWITTER, | ||
| IAccountManager::PROPERTY_FEDIVERSE, | ||
| IAccountManager::PROPERTY_ORGANISATION, | ||
| IAccountManager::PROPERTY_ROLE, | ||
| IAccountManager::PROPERTY_HEADLINE, | ||
| IAccountManager::PROPERTY_BIOGRAPHY, | ||
| IAccountManager::PROPERTY_PROFILE_ENABLED, | ||
| ]], | ||
| [false, false, ISetDisplayNameBackend::class, [ | ||
| IAccountManager::COLLECTION_EMAIL, | ||
| IAccountManager::PROPERTY_PHONE, | ||
| IAccountManager::PROPERTY_ADDRESS, | ||
| IAccountManager::PROPERTY_WEBSITE, | ||
| IAccountManager::PROPERTY_TWITTER, | ||
| IAccountManager::PROPERTY_FEDIVERSE, | ||
| IAccountManager::PROPERTY_ORGANISATION, | ||
| IAccountManager::PROPERTY_ROLE, | ||
| IAccountManager::PROPERTY_HEADLINE, | ||
| IAccountManager::PROPERTY_BIOGRAPHY, | ||
| IAccountManager::PROPERTY_PROFILE_ENABLED, | ||
| ]], | ||
| [false, true, UserInterface::class, [ | ||
| IAccountManager::PROPERTY_EMAIL, | ||
| IAccountManager::COLLECTION_EMAIL, | ||
| IAccountManager::PROPERTY_PHONE, | ||
|
|
@@ -4252,7 +4299,20 @@ public function dataGetEditableFields() { | |
| IAccountManager::PROPERTY_BIOGRAPHY, | ||
| IAccountManager::PROPERTY_PROFILE_ENABLED, | ||
| ]], | ||
| [true, UserInterface::class, [ | ||
| [true, false, UserInterface::class, [ | ||
| IAccountManager::COLLECTION_EMAIL, | ||
| IAccountManager::PROPERTY_PHONE, | ||
| IAccountManager::PROPERTY_ADDRESS, | ||
| IAccountManager::PROPERTY_WEBSITE, | ||
| IAccountManager::PROPERTY_TWITTER, | ||
| IAccountManager::PROPERTY_FEDIVERSE, | ||
| IAccountManager::PROPERTY_ORGANISATION, | ||
| IAccountManager::PROPERTY_ROLE, | ||
| IAccountManager::PROPERTY_HEADLINE, | ||
| IAccountManager::PROPERTY_BIOGRAPHY, | ||
| IAccountManager::PROPERTY_PROFILE_ENABLED, | ||
| ]], | ||
| [true, true, UserInterface::class, [ | ||
| IAccountManager::PROPERTY_EMAIL, | ||
| IAccountManager::COLLECTION_EMAIL, | ||
| IAccountManager::PROPERTY_PHONE, | ||
|
|
@@ -4266,6 +4326,19 @@ public function dataGetEditableFields() { | |
| IAccountManager::PROPERTY_BIOGRAPHY, | ||
| IAccountManager::PROPERTY_PROFILE_ENABLED, | ||
| ]], | ||
| [false, false, UserInterface::class, [ | ||
| IAccountManager::COLLECTION_EMAIL, | ||
| IAccountManager::PROPERTY_PHONE, | ||
| IAccountManager::PROPERTY_ADDRESS, | ||
| IAccountManager::PROPERTY_WEBSITE, | ||
| IAccountManager::PROPERTY_TWITTER, | ||
| IAccountManager::PROPERTY_FEDIVERSE, | ||
| IAccountManager::PROPERTY_ORGANISATION, | ||
| IAccountManager::PROPERTY_ROLE, | ||
| IAccountManager::PROPERTY_HEADLINE, | ||
| IAccountManager::PROPERTY_BIOGRAPHY, | ||
| IAccountManager::PROPERTY_PROFILE_ENABLED, | ||
| ]], | ||
| ]; | ||
| } | ||
|
|
||
|
|
@@ -4276,13 +4349,12 @@ public function dataGetEditableFields() { | |
| * @param string $userBackend | ||
| * @param array $expected | ||
| */ | ||
| public function testGetEditableFields(bool $allowedToChangeDisplayName, string $userBackend, array $expected) { | ||
| $this->config | ||
| ->method('getSystemValue') | ||
| ->with( | ||
| $this->equalTo('allow_user_to_change_display_name'), | ||
| $this->anything() | ||
| )->willReturn($allowedToChangeDisplayName); | ||
| public function testGetEditableFields(bool $allowedToChangeDisplayName, bool $allowedToChangeEmail, string $userBackend, array $expected): void { | ||
| $this->config->method('getSystemValue')->willReturnCallback(fn (string $key, mixed $default) => match ($key) { | ||
| 'allow_user_to_change_display_name' => $allowedToChangeDisplayName, | ||
| 'allow_user_to_change_email' => $allowedToChangeEmail, | ||
| default => throw new RuntimeException('Unexpected system config key: ' . $key), | ||
| }); | ||
|
|
||
| $user = $this->createMock(IUser::class); | ||
| $this->userSession->method('getUser') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,6 +148,7 @@ | |
| $accountParameters = [ | ||
| 'avatarChangeSupported' => $user->canChangeAvatar(), | ||
| 'displayNameChangeSupported' => $user->canChangeDisplayName(), | ||
| 'emailChangeSupported' => $user->canChangeEmail(), | ||
Check noticeCode scanning / Psalm UndefinedInterfaceMethod Note
Method OCP\IUser::canChangeEmail does not exist
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems legit @susnux ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes but intentional. |
||
| 'federationEnabled' => $federationEnabled, | ||
| 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, | ||
| ]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OC\Core\Migrations; | ||
|
|
||
| use OCP\IConfig; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
|
|
||
| /** | ||
| * Add `allow_user_to_change_email` system config | ||
| */ | ||
| class Version32000Date20250402182800 extends SimpleMigrationStep { | ||
|
|
||
| public function __construct( | ||
| private IConfig $config, | ||
| ) { | ||
| } | ||
|
|
||
| public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { | ||
| $allowDisplayName = $this->config->getSystemValue('allow_user_to_change_display_name', null); | ||
| $allowEmail = $this->config->getSystemValue('allow_user_to_change_email', null); | ||
|
|
||
| // if displayname was set, but not the email setting, then set the email setting to the same as the email setting | ||
| if ($allowDisplayName !== null && $allowEmail === null) { | ||
| $this->config->setSystemValue('allow_user_to_change_email', $allowDisplayName === true); | ||
| } | ||
| } | ||
|
|
||
| } |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Check notice
Code scanning / Psalm
PossiblyNullReference Note