@@ -69,6 +71,7 @@ A user logs into Nextcloud with their LDAP or AD credentials, and is granted acc
OCA\User_LDAP\Settings\Admin
+ OCA\User_LDAP\Settings\AppSettings
OCA\User_LDAP\Settings\Section
diff --git a/apps/user_ldap/composer/composer/autoload_classmap.php b/apps/user_ldap/composer/composer/autoload_classmap.php
index 48fe59a9a51cc..771b30b2be801 100644
--- a/apps/user_ldap/composer/composer/autoload_classmap.php
+++ b/apps/user_ldap/composer/composer/autoload_classmap.php
@@ -61,6 +61,7 @@
'OCA\\User_LDAP\\Mapping\\GroupMapping' => $baseDir . '/../lib/Mapping/GroupMapping.php',
'OCA\\User_LDAP\\Mapping\\UserMapping' => $baseDir . '/../lib/Mapping/UserMapping.php',
'OCA\\User_LDAP\\Migration\\GroupMappingMigration' => $baseDir . '/../lib/Migration/GroupMappingMigration.php',
+ 'OCA\\User_LDAP\\Migration\\RearrangeMarkRemnantsAsDisabled' => $baseDir . '/../lib/Migration/RearrangeMarkRemnantsAsDisabled.php',
'OCA\\User_LDAP\\Migration\\RemoveRefreshTime' => $baseDir . '/../lib/Migration/RemoveRefreshTime.php',
'OCA\\User_LDAP\\Migration\\SetDefaultProvider' => $baseDir . '/../lib/Migration/SetDefaultProvider.php',
'OCA\\User_LDAP\\Migration\\UUIDFix' => $baseDir . '/../lib/Migration/UUIDFix.php',
@@ -83,6 +84,7 @@
'OCA\\User_LDAP\\Service\\BirthdateParserService' => $baseDir . '/../lib/Service/BirthdateParserService.php',
'OCA\\User_LDAP\\Service\\UpdateGroupsService' => $baseDir . '/../lib/Service/UpdateGroupsService.php',
'OCA\\User_LDAP\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
+ 'OCA\\User_LDAP\\Settings\\AppSettings' => $baseDir . '/../lib/Settings/AppSettings.php',
'OCA\\User_LDAP\\Settings\\Section' => $baseDir . '/../lib/Settings/Section.php',
'OCA\\User_LDAP\\SetupChecks\\LdapConnection' => $baseDir . '/../lib/SetupChecks/LdapConnection.php',
'OCA\\User_LDAP\\SetupChecks\\LdapInvalidUuids' => $baseDir . '/../lib/SetupChecks/LdapInvalidUuids.php',
diff --git a/apps/user_ldap/composer/composer/autoload_static.php b/apps/user_ldap/composer/composer/autoload_static.php
index dd5ad0322af37..bc02462714a93 100644
--- a/apps/user_ldap/composer/composer/autoload_static.php
+++ b/apps/user_ldap/composer/composer/autoload_static.php
@@ -76,6 +76,7 @@ class ComposerStaticInitUser_LDAP
'OCA\\User_LDAP\\Mapping\\GroupMapping' => __DIR__ . '/..' . '/../lib/Mapping/GroupMapping.php',
'OCA\\User_LDAP\\Mapping\\UserMapping' => __DIR__ . '/..' . '/../lib/Mapping/UserMapping.php',
'OCA\\User_LDAP\\Migration\\GroupMappingMigration' => __DIR__ . '/..' . '/../lib/Migration/GroupMappingMigration.php',
+ 'OCA\\User_LDAP\\Migration\\RearrangeMarkRemnantsAsDisabled' => __DIR__ . '/..' . '/../lib/Migration/RearrangeMarkRemnantsAsDisabled.php',
'OCA\\User_LDAP\\Migration\\RemoveRefreshTime' => __DIR__ . '/..' . '/../lib/Migration/RemoveRefreshTime.php',
'OCA\\User_LDAP\\Migration\\SetDefaultProvider' => __DIR__ . '/..' . '/../lib/Migration/SetDefaultProvider.php',
'OCA\\User_LDAP\\Migration\\UUIDFix' => __DIR__ . '/..' . '/../lib/Migration/UUIDFix.php',
@@ -98,6 +99,7 @@ class ComposerStaticInitUser_LDAP
'OCA\\User_LDAP\\Service\\BirthdateParserService' => __DIR__ . '/..' . '/../lib/Service/BirthdateParserService.php',
'OCA\\User_LDAP\\Service\\UpdateGroupsService' => __DIR__ . '/..' . '/../lib/Service/UpdateGroupsService.php',
'OCA\\User_LDAP\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
+ 'OCA\\User_LDAP\\Settings\\AppSettings' => __DIR__ . '/..' . '/../lib/Settings/AppSettings.php',
'OCA\\User_LDAP\\Settings\\Section' => __DIR__ . '/..' . '/../lib/Settings/Section.php',
'OCA\\User_LDAP\\SetupChecks\\LdapConnection' => __DIR__ . '/..' . '/../lib/SetupChecks/LdapConnection.php',
'OCA\\User_LDAP\\SetupChecks\\LdapInvalidUuids' => __DIR__ . '/..' . '/../lib/SetupChecks/LdapInvalidUuids.php',
diff --git a/apps/user_ldap/js/wizard/wizardTabAdvanced.js b/apps/user_ldap/js/wizard/wizardTabAdvanced.js
index 8f0d0aa79732e..10bb2efd17ccf 100644
--- a/apps/user_ldap/js/wizard/wizardTabAdvanced.js
+++ b/apps/user_ldap/js/wizard/wizardTabAdvanced.js
@@ -66,10 +66,6 @@ OCA = OCA || {};
$element: $('#ldap_attributes_for_user_search'),
setMethod: 'setSearchAttributesUsers'
},
- ldap_mark_remnants_as_disabled: {
- $element: $('#ldap_mark_remnants_as_disabled'),
- setMethod: 'setMarkRemnantsAsDisabled'
- },
ldap_group_display_name: {
$element: $('#ldap_group_display_name'),
setMethod: 'setGroupDisplayName'
@@ -282,15 +278,6 @@ OCA = OCA || {};
this.setElementValue(this.managedItems.ldap_attributes_for_user_search.$element, attributes);
},
- /**
- * enables or disables marking remnants as disabled
- *
- * @param {string} markRemnantsAsDisabled contains an int
- */
- setMarkRemnantsAsDisabled: function(markRemnantsAsDisabled) {
- this.setElementValue(this.managedItems.ldap_mark_remnants_as_disabled.$element, markRemnantsAsDisabled);
- },
-
/**
* sets the display name attribute for groups
*
diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php
index 612a46d618e68..5092cff73261f 100644
--- a/apps/user_ldap/lib/Configuration.php
+++ b/apps/user_ldap/lib/Configuration.php
@@ -7,6 +7,7 @@
*/
namespace OCA\User_LDAP;
+use OCP\IAppConfig;
use Psr\Log\LoggerInterface;
/**
@@ -296,6 +297,9 @@ public function readConfiguration(): void {
case 'ldapGroupDisplayName':
$readMethod = 'getLcValue';
break;
+ case 'markRemnantsAsDisabled':
+ $readMethod = 'getGlobalAppValueAsBool';
+ break;
case 'ldapUserDisplayName':
default:
// user display name does not lower case because
@@ -340,6 +344,7 @@ public function saveConfiguration(): void {
case 'ldapIgnoreNamingRules':
case 'ldapUuidUserAttribute':
case 'ldapUuidGroupAttribute':
+ case 'markRemnantsAsDisabled':
continue 2;
}
if (is_null($value)) {
@@ -414,6 +419,14 @@ protected function getLcValue(string $varName): string {
return mb_strtolower($this->getValue($varName), 'UTF-8');
}
+ protected function getGlobalAppValueAsBool(string $varName): bool {
+ static $appConfig;
+ 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 \OC::$server->getConfig()->getSystemValue($varName, false);
@@ -514,7 +527,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,
@@ -593,7 +606,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',
diff --git a/apps/user_ldap/lib/Migration/RearrangeMarkRemnantsAsDisabled.php b/apps/user_ldap/lib/Migration/RearrangeMarkRemnantsAsDisabled.php
new file mode 100644
index 0000000000000..182b6cce0f260
--- /dev/null
+++ b/apps/user_ldap/lib/Migration/RearrangeMarkRemnantsAsDisabled.php
@@ -0,0 +1,54 @@
+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_contains($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);
+ }
+ }
+}
diff --git a/apps/user_ldap/lib/Settings/AppSettings.php b/apps/user_ldap/lib/Settings/AppSettings.php
new file mode 100644
index 0000000000000..1fb2ad4a5c7f4
--- /dev/null
+++ b/apps/user_ldap/lib/Settings/AppSettings.php
@@ -0,0 +1,43 @@
+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;
+ }
+}
diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php
index 4273563ff0273..92822de8bd0c9 100644
--- a/apps/user_ldap/lib/User_LDAP.php
+++ b/apps/user_ldap/lib/User_LDAP.php
@@ -18,11 +18,10 @@
use OCP\Notification\IManager as INotificationManager;
use OCP\User\Backend\ICountMappedUsersBackend;
use OCP\User\Backend\ICountUsersBackend;
-use OCP\User\Backend\IProvideEnabledStateBackend;
use OCP\UserInterface;
use Psr\Log\LoggerInterface;
-class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend {
+class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend {
protected INotificationManager $notificationManager;
protected UserPluginManager $userPluginManager;
protected LoggerInterface $logger;
@@ -632,14 +631,6 @@ public function createUser($username, $password) {
return false;
}
- public function isUserEnabled(string $uid, callable $queryDatabaseValue): bool {
- if ($this->deletedUsersIndex->isUserMarked($uid) && ((int)$this->access->connection->markRemnantsAsDisabled === 1)) {
- return false;
- } else {
- return $queryDatabaseValue();
- }
- }
-
public function setUserEnabled(string $uid, bool $enabled, callable $queryDatabaseValue, callable $setDatabaseValue): bool {
$setDatabaseValue($enabled);
return $enabled;
diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php
index d3197296d7c0c..b57ce7c920646 100644
--- a/apps/user_ldap/lib/User_Proxy.php
+++ b/apps/user_ldap/lib/User_Proxy.php
@@ -10,6 +10,7 @@
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
+use OCP\IAppConfig;
use OCP\IUserBackend;
use OCP\Notification\IManager as INotificationManager;
use OCP\User\Backend\ICountMappedUsersBackend;
@@ -38,6 +39,7 @@ public function __construct(
UserPluginManager $userPluginManager,
LoggerInterface $logger,
DeletedUsersIndex $deletedUsersIndex,
+ protected IAppConfig $appConfig,
) {
parent::__construct($ldap, $accessFactory);
$this->helper = $helper;
@@ -422,7 +424,10 @@ public function createUser($username, $password) {
}
public function isUserEnabled(string $uid, callable $queryDatabaseValue): bool {
- return $this->handleRequest($uid, 'isUserEnabled', [$uid, $queryDatabaseValue]);
+ if (!$this->treatRemnantsAsDisabled()) {
+ return $queryDatabaseValue();
+ }
+ return !$this->deletedUsersIndex->isUserMarked($uid);
}
public function setUserEnabled(string $uid, bool $enabled, callable $queryDatabaseValue, callable $setDatabaseValue): bool {
@@ -430,7 +435,7 @@ public function setUserEnabled(string $uid, bool $enabled, callable $queryDataba
}
public function getDisabledUserList(?int $limit = null, int $offset = 0, string $search = ''): array {
- if ((int)$this->getAccess(array_key_first($this->backends) ?? '')->connection->markRemnantsAsDisabled !== 1) {
+ if (!$this->treatRemnantsAsDisabled()) {
return [];
}
$disabledUsers = $this->deletedUsersIndex->getUsers();
@@ -453,4 +458,12 @@ public function getDisabledUserList(?int $limit = null, int $offset = 0, string
)
);
}
+
+ protected function treatRemnantsAsDisabled(): bool {
+ static $setting;
+ if (!$setting) {
+ $setting = $this->appConfig->getValueBool('user_ldap', 'markRemnantsAsDisabled', false);
+ }
+ return $setting;
+ }
}
diff --git a/apps/user_ldap/src/AppSettings.vue b/apps/user_ldap/src/AppSettings.vue
new file mode 100644
index 0000000000000..9df4f3e2e653a
--- /dev/null
+++ b/apps/user_ldap/src/AppSettings.vue
@@ -0,0 +1,53 @@
+
+
+
+
+
+ -
+
+ {{ t('user_ldap', 'Disable users missing from LDAP') }}
+
+
+
+
+
+
+
+
diff --git a/apps/user_ldap/src/app-settings.js b/apps/user_ldap/src/app-settings.js
new file mode 100644
index 0000000000000..7e95d3af21148
--- /dev/null
+++ b/apps/user_ldap/src/app-settings.js
@@ -0,0 +1,16 @@
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+import { translate } from '@nextcloud/l10n'
+import Vue from 'vue'
+
+import AppSettings from './AppSettings.vue'
+
+Vue.prototype.t = translate
+export default new Vue({
+ el: '#user_ldap-app-settings',
+ // eslint-disable-next-line vue/match-component-file-name
+ name: 'AppSettings',
+ render: h => h(AppSettings),
+})
diff --git a/apps/user_ldap/templates/app-settings.php b/apps/user_ldap/templates/app-settings.php
new file mode 100644
index 0000000000000..c6a9d2d4acebe
--- /dev/null
+++ b/apps/user_ldap/templates/app-settings.php
@@ -0,0 +1,13 @@
+
+
+
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index 4fb24655000d8..265d0a953fb28 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -97,7 +97,6 @@
t('Optional. An LDAP attribute to be added to the display name in brackets. Results in e.g. »John Doe (john.doe@example.org)«.'));?>