Skip to content

Commit d4c876b

Browse files
committed
refactor: add migration for email setting
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 517ab56 commit d4c876b

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ public function getEditableFieldsForUser(string $userId): DataResponse {
757757
}
758758

759759
// Fallback to display name value to avoid changing behavior with the new option.
760-
if ($this->config->getSystemValue('allow_user_to_change_email', $allowDisplayNameChange)) {
760+
if ($this->config->getSystemValue('allow_user_to_change_email', true)) {
761761
$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
762762
}
763763

@@ -918,8 +918,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
918918
$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
919919
}
920920

921-
// Fallback to display name value to avoid changing behavior with the new option.
922-
if ($this->config->getSystemValue('allow_user_to_change_email', $allowDisplayNameChange)) {
921+
if ($this->config->getSystemValue('allow_user_to_change_email', true)) {
923922
$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
924923
}
925924

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
namespace OC\Core\Migrations;
8+
9+
use OCP\IConfig;
10+
use OCP\Migration\IOutput;
11+
use OCP\Migration\SimpleMigrationStep;
12+
13+
/**
14+
* Add `allow_user_to_change_email` system config
15+
*/
16+
class Version32000Date20250402182800 extends SimpleMigrationStep {
17+
18+
public function __construct(
19+
private IConfig $config,
20+
) {
21+
}
22+
23+
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
24+
$allowDisplayName = $this->config->getSystemValue('allow_user_to_change_display_name', null);
25+
$allowEmail = $this->config->getSystemValue('allow_user_to_change_email', null);
26+
27+
// if displayname was set, but not the email setting, then set the email setting to the same as the email setting
28+
if ($allowDisplayName !== null && $allowEmail === null) {
29+
$this->config->setSystemValue('allow_user_to_change_email', $allowDisplayName === true);
30+
}
31+
}
32+
33+
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,7 @@
14501450
'OC\\Core\\Migrations\\Version31000Date20240101084401' => $baseDir . '/core/Migrations/Version31000Date20240101084401.php',
14511451
'OC\\Core\\Migrations\\Version31000Date20240814184402' => $baseDir . '/core/Migrations/Version31000Date20240814184402.php',
14521452
'OC\\Core\\Migrations\\Version31000Date20250213102442' => $baseDir . '/core/Migrations/Version31000Date20250213102442.php',
1453+
'OC\\Core\\Migrations\\Version32000Date20250402182800' => $baseDir . '/core/Migrations/Version32000Date20250402182800.php',
14531454
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
14541455
'OC\\Core\\ResponseDefinitions' => $baseDir . '/core/ResponseDefinitions.php',
14551456
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
14991499
'OC\\Core\\Migrations\\Version31000Date20240101084401' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20240101084401.php',
15001500
'OC\\Core\\Migrations\\Version31000Date20240814184402' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20240814184402.php',
15011501
'OC\\Core\\Migrations\\Version31000Date20250213102442' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20250213102442.php',
1502+
'OC\\Core\\Migrations\\Version32000Date20250402182800' => __DIR__ . '/../../..' . '/core/Migrations/Version32000Date20250402182800.php',
15021503
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
15031504
'OC\\Core\\ResponseDefinitions' => __DIR__ . '/../../..' . '/core/ResponseDefinitions.php',
15041505
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',

lib/private/User/User.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,7 @@ public function canChangeDisplayName() {
448448
}
449449

450450
public function canChangeEmail(): bool {
451-
// Fallback to display name value to avoid changing behavior with the new option.
452-
return $this->config->getSystemValueBool('allow_user_to_change_email', $this->config->getSystemValueBool('allow_user_to_change_display_name', true));
451+
return $this->config->getSystemValueBool('allow_user_to_change_email', true);
453452
}
454453

455454
/**

0 commit comments

Comments
 (0)