aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib/User_Proxy.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/lib/User_Proxy.php')
-rw-r--r--apps/user_ldap/lib/User_Proxy.php142
1 files changed, 50 insertions, 92 deletions
diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php
index 96415491e41..0d41f495ce9 100644
--- a/apps/user_ldap/lib/User_Proxy.php
+++ b/apps/user_ldap/lib/User_Proxy.php
@@ -1,107 +1,47 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christopher Schäpers <kondou@ts.unde.re>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roger Szabo <roger.szabo@web.de>
- * @author root <root@localhost.localdomain>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vinicius Cubas Brand <vinicius@eita.org.br>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP;
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
-use OCP\IConfig;
use OCP\IUserBackend;
-use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager;
use OCP\User\Backend\ICountMappedUsersBackend;
-use OCP\User\Backend\ICountUsersBackend;
+use OCP\User\Backend\ILimitAwareCountUsersBackend;
use OCP\User\Backend\IProvideEnabledStateBackend;
use OCP\UserInterface;
use Psr\Log\LoggerInterface;
-class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend {
- /** @var User_LDAP[] */
- private array $backends = [];
- private ?User_LDAP $refBackend = null;
-
- private bool $isSetUp = false;
- private Helper $helper;
- private IConfig $ocConfig;
- private INotificationManager $notificationManager;
- private IUserSession $userSession;
- private UserPluginManager $userPluginManager;
- private LoggerInterface $logger;
- private DeletedUsersIndex $deletedUsersIndex;
-
+/**
+ * @template-extends Proxy<User_LDAP>
+ */
+class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ILimitAwareCountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend {
public function __construct(
- Helper $helper,
+ private Helper $helper,
ILDAPWrapper $ldap,
AccessFactory $accessFactory,
- IConfig $ocConfig,
- INotificationManager $notificationManager,
- IUserSession $userSession,
- UserPluginManager $userPluginManager,
- LoggerInterface $logger,
- DeletedUsersIndex $deletedUsersIndex,
+ private INotificationManager $notificationManager,
+ private UserPluginManager $userPluginManager,
+ private LoggerInterface $logger,
+ private DeletedUsersIndex $deletedUsersIndex,
) {
- parent::__construct($ldap, $accessFactory);
- $this->helper = $helper;
- $this->ocConfig = $ocConfig;
- $this->notificationManager = $notificationManager;
- $this->userSession = $userSession;
- $this->userPluginManager = $userPluginManager;
- $this->logger = $logger;
- $this->deletedUsersIndex = $deletedUsersIndex;
+ parent::__construct($helper, $ldap, $accessFactory);
}
- protected function setup(): void {
- if ($this->isSetUp) {
- return;
- }
-
- $serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true);
- foreach ($serverConfigPrefixes as $configPrefix) {
- $this->backends[$configPrefix] = new User_LDAP(
- $this->getAccess($configPrefix),
- $this->ocConfig,
- $this->notificationManager,
- $this->userSession,
- $this->userPluginManager,
- $this->logger,
- $this->deletedUsersIndex,
- );
-
- if (is_null($this->refBackend)) {
- $this->refBackend = &$this->backends[$configPrefix];
- }
- }
-
- $this->isSetUp = true;
+ protected function newInstance(string $configPrefix): User_LDAP {
+ return new User_LDAP(
+ $this->getAccess($configPrefix),
+ $this->notificationManager,
+ $this->userPluginManager,
+ $this->logger,
+ $this->deletedUsersIndex,
+ );
}
/**
@@ -254,8 +194,8 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP
/**
* check if a user exists on LDAP
*
- * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
- * name or an instance of that user
+ * @param string|User $user either the Nextcloud user
+ * name or an instance of that user
*/
public function userExistsOnLDAP($user, bool $ignoreCache = false): bool {
$id = ($user instanceof User) ? $user->getUsername() : $user;
@@ -329,7 +269,7 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP
}
/**
- * checks whether the user is allowed to change his avatar in Nextcloud
+ * checks whether the user is allowed to change their avatar in Nextcloud
*
* @param string $uid the Nextcloud user name
* @return boolean either the user can or cannot
@@ -394,17 +334,21 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP
/**
* Count the number of users
- *
- * @return int|false
*/
- public function countUsers() {
+ public function countUsers(int $limit = 0): int|false {
$this->setup();
$users = false;
foreach ($this->backends as $backend) {
- $backendUsers = $backend->countUsers();
+ $backendUsers = $backend->countUsers($limit);
if ($backendUsers !== false) {
$users = (int)$users + $backendUsers;
+ if ($limit > 0) {
+ if ($users >= $limit) {
+ break;
+ }
+ $limit -= $users;
+ }
}
}
return $users;
@@ -463,11 +407,25 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP
return $this->handleRequest($uid, 'setUserEnabled', [$uid, $enabled, $queryDatabaseValue, $setDatabaseValue]);
}
- public function getDisabledUserList(?int $limit = null, int $offset = 0): array {
+ public function getDisabledUserList(?int $limit = null, int $offset = 0, string $search = ''): array {
+ if ((int)$this->getAccess(array_key_first($this->backends) ?? '')->connection->markRemnantsAsDisabled !== 1) {
+ return [];
+ }
+ $disabledUsers = $this->deletedUsersIndex->getUsers();
+ if ($search !== '') {
+ $disabledUsers = array_filter(
+ $disabledUsers,
+ fn (OfflineUser $user): bool
+ => mb_stripos($user->getOCName(), $search) !== false
+ || mb_stripos($user->getUID(), $search) !== false
+ || mb_stripos($user->getDisplayName(), $search) !== false
+ || mb_stripos($user->getEmail(), $search) !== false,
+ );
+ }
return array_map(
fn (OfflineUser $user) => $user->getOCName(),
array_slice(
- $this->deletedUsersIndex->getUsers(),
+ $disabledUsers,
$offset,
$limit
)