Skip to content

Commit 7b6bdaa

Browse files
committed
fix(LDAP): add migration step to set and clean up config value
- *ldap_mark_remnants_as_disabled were old values and removed now, after - combining their value and storing into current backend_mark_remnants_as_disabled Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 4816050 commit 7b6bdaa

7 files changed

Lines changed: 63 additions & 6 deletions

File tree

apps/user_ldap/appinfo/info.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
A user logs into Nextcloud with their LDAP or AD credentials, and is granted access based on an authentication request handled by the LDAP or AD server. Nextcloud does not store LDAP or AD passwords, rather these credentials are used to authenticate a user and then Nextcloud uses a session for the user ID. More information is available in the LDAP User and Group Backend documentation.
1515

1616
</description>
17-
<version>1.23.0</version>
17+
<version>1.23.1</version>
1818
<licence>agpl</licence>
1919
<author>Dominik Schmidt</author>
2020
<author>Arthur Schiwon</author>
@@ -42,6 +42,7 @@ A user logs into Nextcloud with their LDAP or AD credentials, and is granted acc
4242
<post-migration>
4343
<step>OCA\User_LDAP\Migration\UUIDFixInsert</step>
4444
<step>OCA\User_LDAP\Migration\RemoveRefreshTime</step>
45+
<step>OCA\User_LDAP\Migration\RearrangeMarkRemnantsAsDisabled</step>
4546
</post-migration>
4647
<install>
4748
<step>OCA\User_LDAP\Migration\SetDefaultProvider</step>

apps/user_ldap/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
'OCA\\User_LDAP\\Mapping\\GroupMapping' => $baseDir . '/../lib/Mapping/GroupMapping.php',
6363
'OCA\\User_LDAP\\Mapping\\UserMapping' => $baseDir . '/../lib/Mapping/UserMapping.php',
6464
'OCA\\User_LDAP\\Migration\\GroupMappingMigration' => $baseDir . '/../lib/Migration/GroupMappingMigration.php',
65+
'OCA\\User_LDAP\\Migration\\RearrangeMarkRemnantsAsDisabled' => $baseDir . '/../lib/Migration/RearrangeMarkRemnantsAsDisabled.php',
6566
'OCA\\User_LDAP\\Migration\\RemoveRefreshTime' => $baseDir . '/../lib/Migration/RemoveRefreshTime.php',
6667
'OCA\\User_LDAP\\Migration\\SetDefaultProvider' => $baseDir . '/../lib/Migration/SetDefaultProvider.php',
6768
'OCA\\User_LDAP\\Migration\\UUIDFix' => $baseDir . '/../lib/Migration/UUIDFix.php',

apps/user_ldap/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ComposerStaticInitUser_LDAP
7777
'OCA\\User_LDAP\\Mapping\\GroupMapping' => __DIR__ . '/..' . '/../lib/Mapping/GroupMapping.php',
7878
'OCA\\User_LDAP\\Mapping\\UserMapping' => __DIR__ . '/..' . '/../lib/Mapping/UserMapping.php',
7979
'OCA\\User_LDAP\\Migration\\GroupMappingMigration' => __DIR__ . '/..' . '/../lib/Migration/GroupMappingMigration.php',
80+
'OCA\\User_LDAP\\Migration\\RearrangeMarkRemnantsAsDisabled' => __DIR__ . '/..' . '/../lib/Migration/RearrangeMarkRemnantsAsDisabled.php',
8081
'OCA\\User_LDAP\\Migration\\RemoveRefreshTime' => __DIR__ . '/..' . '/../lib/Migration/RemoveRefreshTime.php',
8182
'OCA\\User_LDAP\\Migration\\SetDefaultProvider' => __DIR__ . '/..' . '/../lib/Migration/SetDefaultProvider.php',
8283
'OCA\\User_LDAP\\Migration\\UUIDFix' => __DIR__ . '/..' . '/../lib/Migration/UUIDFix.php',

apps/user_ldap/lib/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ public function getDefaults(): array {
551551
'ldap_expert_uuid_group_attr' => '',
552552
'has_memberof_filter_support' => 0,
553553
'use_memberof_to_detect_membership' => 1,
554-
'ldap_mark_remnants_as_disabled' => 0,
554+
'backend_mark_remnants_as_disabled' => 0,
555555
'last_jpegPhoto_lookup' => 0,
556556
'ldap_nested_groups' => 0,
557557
'ldap_paging_size' => 500,
@@ -631,7 +631,7 @@ public function getConfigTranslationArray(): array {
631631
'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr',
632632
'has_memberof_filter_support' => 'hasMemberOfFilterSupport',
633633
'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership',
634-
'ldap_mark_remnants_as_disabled' => 'markRemnantsAsDisabled',
634+
'backend_mark_remnants_as_disabled' => 'markRemnantsAsDisabled',
635635
'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup',
636636
'ldap_nested_groups' => 'ldapNestedGroups',
637637
'ldap_paging_size' => 'ldapPagingSize',
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\User_LDAP\Migration;
10+
11+
use OCP\IAppConfig;
12+
use OCP\IDBConnection;
13+
use OCP\Migration\IOutput;
14+
use OCP\Migration\IRepairStep;
15+
16+
class RearrangeMarkRemnantsAsDisabled implements IRepairStep {
17+
public function __construct(
18+
protected IAppConfig $appConfig,
19+
protected IDBConnection $dbc,
20+
) {
21+
22+
}
23+
public function getName(): string {
24+
return 'Rearrange the configuration of ldap_mark_remnants_as_disabled';
25+
}
26+
27+
public function run(IOutput $output): void {
28+
$allKeys = $this->appConfig->getKeys('user_ldap');
29+
30+
if (in_array('backend_mark_remnants_as_disabled', $allKeys, true)) {
31+
return;
32+
}
33+
34+
// if it was enabled for at least one configuration, use it as global configuration
35+
$filteredKeys = array_filter($allKeys, static function (string $key): bool {
36+
return str_ends_with($key, 'ldap_mark_remnants_as_disabled');
37+
});
38+
$newValue = false;
39+
foreach ($filteredKeys as $filteredKey) {
40+
$newValue = $newValue || $this->appConfig->getValueBool('user_ldap', $filteredKey);
41+
}
42+
43+
// set the new value
44+
$this->appConfig->setValueBool('user_ldap', 'backend_mark_remnants_as_disabled', $newValue);
45+
if ($newValue) {
46+
$output->info('The option "Disable missing users from LDAP" is activated.');
47+
}
48+
49+
// clean up now that the new value is saved
50+
foreach ($filteredKeys as $filteredKey) {
51+
$this->appConfig->deleteKey('user_ldap', $filteredKey);
52+
}
53+
}
54+
}

apps/user_ldap/lib/Settings/AppSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getAuthorizedAppConfig(): array {
3333

3434
public function getForm(): TemplateResponse {
3535
$this->initialState->provideInitialState('config', [
36-
'ldap_mark_remnants_as_disabled' => $this->appConfig->getValueBool('user_ldap', 'ldap_mark_remnants_as_disabled'),
36+
'backend_mark_remnants_as_disabled' => $this->appConfig->getValueBool('user_ldap', 'backend_mark_remnants_as_disabled'),
3737
]);
3838

3939
return new TemplateResponse('user_ldap', 'settings-global');

apps/user_ldap/src/AppSettings.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<NcSettingsSection :name="t('user_ldap', 'Configuration-independent settings')">
88
<ul class="user_ldap__app-settings-list">
99
<li>
10-
<NcCheckboxRadioSwitch :checked="config.ldap_mark_remnants_as_disabled"
10+
<NcCheckboxRadioSwitch :checked="config.backend_mark_remnants_as_disabled"
1111
type="switch"
12-
@update:checked="updateBoolSetting('ldap_mark_remnants_as_disabled')">
12+
@update:checked="updateBoolSetting('backend_mark_remnants_as_disabled')">
1313
{{ t('user_ldap', 'Disable users missing from LDAP') }}
1414
</NcCheckboxRadioSwitch>
1515
</li>

0 commit comments

Comments
 (0)