@@ -70,6 +72,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 36259880928e2..70a1c56780f4a 100644
--- a/apps/user_ldap/composer/composer/autoload_classmap.php
+++ b/apps/user_ldap/composer/composer/autoload_classmap.php
@@ -62,6 +62,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',
@@ -84,6 +85,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 be985838393f4..08e6366c88ba3 100644
--- a/apps/user_ldap/composer/composer/autoload_static.php
+++ b/apps/user_ldap/composer/composer/autoload_static.php
@@ -77,6 +77,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',
@@ -99,6 +100,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 b4a5b84720421..e463d33b55eb0 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 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;
+ 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',
diff --git a/apps/user_ldap/lib/Migration/RearrangeMarkRemnantsAsDisabled.php b/apps/user_ldap/lib/Migration/RearrangeMarkRemnantsAsDisabled.php
new file mode 100644
index 0000000000000..ca40e1301acf3
--- /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_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);
+ }
+ }
+}
diff --git a/apps/user_ldap/lib/Settings/AppSettings.php b/apps/user_ldap/lib/Settings/AppSettings.php
new file mode 100644
index 0000000000000..f838c0150e8b7
--- /dev/null
+++ b/apps/user_ldap/lib/Settings/AppSettings.php
@@ -0,0 +1,49 @@
+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 c3f56f5ff9b47..9811f6528ae2d 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\ILimitAwareCountUsersBackend;
-use OCP\User\Backend\IProvideEnabledStateBackend;
use OCP\UserInterface;
use Psr\Log\LoggerInterface;
-class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ILimitAwareCountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend {
+class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ILimitAwareCountUsersBackend, ICountMappedUsersBackend {
public function __construct(
Access $access,
protected INotificationManager $notificationManager,
@@ -616,14 +615,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 0d41f495ce9ba..ffa07ef7c61d4 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;
@@ -30,6 +31,7 @@ public function __construct(
private UserPluginManager $userPluginManager,
private LoggerInterface $logger,
private DeletedUsersIndex $deletedUsersIndex,
+ protected IAppConfig $appConfig,
) {
parent::__construct($helper, $ldap, $accessFactory);
}
@@ -400,7 +402,10 @@ public function createUser($username, $password) {
}
public function isUserEnabled(string $uid, callable $queryDatabaseValue): bool {
- return $this->handleRequest($uid, 'isUserEnabled', [$uid, $queryDatabaseValue]);
+ if ($this->treatRemnantsAsDisabled() && $this->deletedUsersIndex->isUserMarked($uid)) {
+ return false;
+ }
+ return $queryDatabaseValue();
}
public function setUserEnabled(string $uid, bool $enabled, callable $queryDatabaseValue, callable $setDatabaseValue): bool {
@@ -408,7 +413,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();
@@ -431,4 +436,8 @@ public function getDisabledUserList(?int $limit = null, int $offset = 0, string
)
);
}
+
+ protected function treatRemnantsAsDisabled(): bool {
+ return $this->appConfig->getValueBool('user_ldap', 'markRemnantsAsDisabled', false);
+ }
}
diff --git a/apps/user_ldap/src/AppSettings.vue b/apps/user_ldap/src/AppSettings.vue
new file mode 100644
index 0000000000000..70ba761551641
--- /dev/null
+++ b/apps/user_ldap/src/AppSettings.vue
@@ -0,0 +1,52 @@
+
+
+
+
+
+ -
+
+ {{ 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 9117a9f533caa..34f228e1213f8 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)«.'));?>