From e7859f0dacbda051c2decb2e0d62345435ac2fd9 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 2 Apr 2025 18:33:38 +0200 Subject: [PATCH] refactor: add migration for email setting Signed-off-by: Ferdinand Thiessen --- .../lib/Controller/UsersController.php | 5 ++- .../Version32000Date20250402182800.php | 33 +++++++++++++++++++ lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/User/User.php | 3 +- 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 core/Migrations/Version32000Date20250402182800.php diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 4b3db45f518..6629440482d 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -757,7 +757,7 @@ class UsersController extends AUserDataOCSController { } // Fallback to display name value to avoid changing behavior with the new option. - if ($this->config->getSystemValue('allow_user_to_change_email', $allowDisplayNameChange)) { + if ($this->config->getSystemValue('allow_user_to_change_email', true)) { $permittedFields[] = IAccountManager::PROPERTY_EMAIL; } @@ -918,8 +918,7 @@ class UsersController extends AUserDataOCSController { $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME; } - // Fallback to display name value to avoid changing behavior with the new option. - if ($this->config->getSystemValue('allow_user_to_change_email', $allowDisplayNameChange)) { + if ($this->config->getSystemValue('allow_user_to_change_email', true)) { $permittedFields[] = IAccountManager::PROPERTY_EMAIL; } diff --git a/core/Migrations/Version32000Date20250402182800.php b/core/Migrations/Version32000Date20250402182800.php new file mode 100644 index 00000000000..c63e95766f5 --- /dev/null +++ b/core/Migrations/Version32000Date20250402182800.php @@ -0,0 +1,33 @@ +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); + } + } + +} diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 52e3075e413..5f51750ac98 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1453,6 +1453,7 @@ return array( 'OC\\Core\\Migrations\\Version31000Date20240101084401' => $baseDir . '/core/Migrations/Version31000Date20240101084401.php', 'OC\\Core\\Migrations\\Version31000Date20240814184402' => $baseDir . '/core/Migrations/Version31000Date20240814184402.php', 'OC\\Core\\Migrations\\Version31000Date20250213102442' => $baseDir . '/core/Migrations/Version31000Date20250213102442.php', + 'OC\\Core\\Migrations\\Version32000Date20250402182800' => $baseDir . '/core/Migrations/Version32000Date20250402182800.php', 'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php', 'OC\\Core\\ResponseDefinitions' => $baseDir . '/core/ResponseDefinitions.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index e98bc3e1aaa..c06999c6480 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1502,6 +1502,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Core\\Migrations\\Version31000Date20240101084401' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20240101084401.php', 'OC\\Core\\Migrations\\Version31000Date20240814184402' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20240814184402.php', 'OC\\Core\\Migrations\\Version31000Date20250213102442' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20250213102442.php', + 'OC\\Core\\Migrations\\Version32000Date20250402182800' => __DIR__ . '/../../..' . '/core/Migrations/Version32000Date20250402182800.php', 'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php', 'OC\\Core\\ResponseDefinitions' => __DIR__ . '/../../..' . '/core/ResponseDefinitions.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', diff --git a/lib/private/User/User.php b/lib/private/User/User.php index f04977314e2..9d61aaf48e0 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -448,8 +448,7 @@ class User implements IUser { } public function canChangeEmail(): bool { - // Fallback to display name value to avoid changing behavior with the new option. - return $this->config->getSystemValueBool('allow_user_to_change_email', $this->config->getSystemValueBool('allow_user_to_change_display_name', true)); + return $this->config->getSystemValueBool('allow_user_to_change_email', true); } /**