-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
turn LDAP's treat remnants as disabled feature config-independent #46992
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
Open
blizzz
wants to merge
4
commits into
master
Choose a base branch
from
fix/noid/ldap-remnants-as-disabled-global
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| */ | ||
| namespace OCA\User_LDAP; | ||
|
|
||
| use OCP\IAppConfig; | ||
| use OCP\IConfig; | ||
| use OCP\Server; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
@@ -62,7 +63,7 @@ | |
| * @property string $ldapExpertUsernameAttr | ||
| * @property string $ldapExpertUUIDUserAttr | ||
| * @property string $ldapExpertUUIDGroupAttr | ||
| * @property string $markRemnantsAsDisabled | ||
| * @property bool $markRemnantsAsDisabled | ||
| * @property string $lastJpegPhotoLookup | ||
| * @property string $ldapNestedGroups | ||
| * @property string $ldapPagingSize | ||
|
|
@@ -320,6 +321,9 @@ public function readConfiguration(): void { | |
| case 'ldapAttributePronouns': | ||
| $readMethod = 'getLcValue'; | ||
| break; | ||
| case 'markRemnantsAsDisabled': | ||
| $readMethod = 'getGlobalAppValueAsBool'; | ||
| break; | ||
| case 'ldapUserDisplayName': | ||
| default: | ||
| // user display name does not lower case because | ||
|
|
@@ -364,6 +368,7 @@ public function saveConfiguration(): void { | |
| case 'ldapIgnoreNamingRules': | ||
| case 'ldapUuidUserAttribute': | ||
| case 'ldapUuidGroupAttribute': | ||
| case 'markRemnantsAsDisabled': | ||
| continue 2; | ||
| } | ||
| if (is_null($value)) { | ||
|
|
@@ -438,6 +443,14 @@ protected function getLcValue(string $varName): string { | |
| return mb_strtolower($this->getValue($varName), 'UTF-8'); | ||
| } | ||
|
|
||
| protected function getGlobalAppValueAsBool(string $varName): bool { | ||
| static $appConfig; | ||
|
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. Same as the other one, static var is scary. Cache in a property or do not cache. (There is no way to reset the static var ever, while, the property can be reset by trashing the object and building a new one) |
||
| if (!$appConfig) { | ||
| $appConfig = \OCP\Server::get(IAppConfig::class); | ||
| } | ||
| return $appConfig->getValueBool('user_ldap', $varName, false); | ||
| } | ||
|
|
||
| protected function getSystemValue(string $varName): string { | ||
| //FIXME: if another system value is added, softcode the default value | ||
| return Server::get(IConfig::class)->getSystemValue($varName, false); | ||
|
|
@@ -538,7 +551,7 @@ public function getDefaults(): array { | |
| 'ldap_expert_uuid_group_attr' => '', | ||
| 'has_memberof_filter_support' => 0, | ||
| 'use_memberof_to_detect_membership' => 1, | ||
| 'ldap_mark_remnants_as_disabled' => 0, | ||
| 'backend_mark_remnants_as_disabled' => 0, | ||
| 'last_jpegPhoto_lookup' => 0, | ||
| 'ldap_nested_groups' => 0, | ||
| 'ldap_paging_size' => 500, | ||
|
|
@@ -618,7 +631,7 @@ public function getConfigTranslationArray(): array { | |
| 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr', | ||
| 'has_memberof_filter_support' => 'hasMemberOfFilterSupport', | ||
| 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership', | ||
| 'ldap_mark_remnants_as_disabled' => 'markRemnantsAsDisabled', | ||
| 'backend_mark_remnants_as_disabled' => 'markRemnantsAsDisabled', | ||
| 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup', | ||
| 'ldap_nested_groups' => 'ldapNestedGroups', | ||
| 'ldap_paging_size' => 'ldapPagingSize', | ||
|
|
||
54 changes: 54 additions & 0 deletions
54
apps/user_ldap/lib/Migration/RearrangeMarkRemnantsAsDisabled.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\User_LDAP\Migration; | ||
|
|
||
| use OCP\IAppConfig; | ||
| use OCP\IDBConnection; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\IRepairStep; | ||
|
|
||
| class RearrangeMarkRemnantsAsDisabled implements IRepairStep { | ||
| public function __construct( | ||
| protected IAppConfig $appConfig, | ||
| protected IDBConnection $dbc, | ||
| ) { | ||
|
|
||
| } | ||
| public function getName(): string { | ||
| return 'Rearrange the configuration of ldap_mark_remnants_as_disabled'; | ||
| } | ||
|
|
||
| public function run(IOutput $output): void { | ||
| $allKeys = $this->appConfig->getKeys('user_ldap'); | ||
|
|
||
| if (in_array('backend_mark_remnants_as_disabled', $allKeys, true)) { | ||
| return; | ||
| } | ||
|
|
||
| // if it was enabled for at least one configuration, use it as global configuration | ||
| $filteredKeys = array_filter($allKeys, static function (string $key): bool { | ||
| return str_ends_with($key, 'ldap_mark_remnants_as_disabled'); | ||
| }); | ||
| $newValue = false; | ||
| foreach ($filteredKeys as $filteredKey) { | ||
| $newValue = $newValue || $this->appConfig->getValueBool('user_ldap', $filteredKey); | ||
| } | ||
|
|
||
| // set the new value | ||
| $this->appConfig->setValueBool('user_ldap', 'backend_mark_remnants_as_disabled', $newValue); | ||
| if ($newValue) { | ||
| $output->info('The option "Disable missing users from LDAP" is activated.'); | ||
| } | ||
|
|
||
| // clean up now that the new value is saved | ||
| foreach ($filteredKeys as $filteredKey) { | ||
| $this->appConfig->deleteKey('user_ldap', $filteredKey); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OCA\User_LDAP\Settings; | ||
|
|
||
| use OCP\AppFramework\Http\TemplateResponse; | ||
| use OCP\AppFramework\Services\IInitialState; | ||
| use OCP\IAppConfig; | ||
| use OCP\IL10N; | ||
| use OCP\Settings\IDelegatedSettings; | ||
|
|
||
| class AppSettings implements IDelegatedSettings { | ||
|
|
||
| public function __construct( | ||
| protected IL10N $l, | ||
| protected IInitialState $initialState, | ||
| protected IAppConfig $appConfig, | ||
| ) { | ||
| } | ||
|
|
||
| public function getName(): ?string { | ||
| return $this->l->t('Configuration-independent settings'); | ||
| } | ||
|
|
||
| public function getAuthorizedAppConfig(): array { | ||
| return []; | ||
| } | ||
|
|
||
| public function getForm(): TemplateResponse { | ||
| $this->initialState->provideInitialState('config', [ | ||
| 'backend_mark_remnants_as_disabled' => $this->appConfig->getValueBool('user_ldap', 'backend_mark_remnants_as_disabled'), | ||
| ]); | ||
|
|
||
| return new TemplateResponse('user_ldap', 'app-settings'); | ||
| } | ||
|
|
||
| public function getSection(): string { | ||
| return 'ldap'; | ||
| } | ||
|
|
||
| public function getPriority(): int { | ||
| return 9; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <!-- | ||
| - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| - SPDX-License-Identifier: AGPL-3.0-or-later | ||
| --> | ||
|
|
||
| <template> | ||
| <NcSettingsSection :name="t('user_ldap', 'Configuration-independent settings')"> | ||
| <ul class="user_ldap__app-settings-list"> | ||
| <li> | ||
| <NcCheckboxRadioSwitch :checked="config.backend_mark_remnants_as_disabled" | ||
| type="switch" | ||
| @update:checked="updateBoolSetting('backend_mark_remnants_as_disabled')"> | ||
| {{ t('user_ldap', 'Disable users missing from LDAP') }} | ||
| </NcCheckboxRadioSwitch> | ||
| </li> | ||
| </ul> | ||
| </NcSettingsSection> | ||
| </template> | ||
|
|
||
| <script> | ||
| import { showError, showSuccess } from '@nextcloud/dialogs' | ||
| import { loadState } from '@nextcloud/initial-state' | ||
|
|
||
| import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' | ||
| import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js' | ||
|
|
||
| export default { | ||
| name: 'AppSettings', | ||
| components: { | ||
| NcCheckboxRadioSwitch, | ||
| NcSettingsSection, | ||
| }, | ||
|
|
||
| data() { | ||
| return { | ||
| config: loadState('user_ldap', 'config'), | ||
| } | ||
| }, | ||
|
|
||
| methods: { | ||
| async updateBoolSetting(setting) { | ||
| OCP.AppConfig.setValue('user_ldap', setting, this.config[setting] ? '0' : '1', { | ||
| success: () => { | ||
| showSuccess(t('user_ldap', 'Settings saved')) | ||
| this.config[setting] = !this.config[setting] | ||
| }, | ||
| error: () => showError(t('user_ldap', 'Error while saving settings')), | ||
| }) | ||
| }, | ||
| }, | ||
| } | ||
| </script> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.