diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-10-24 16:39:43 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-10-24 16:54:41 +0200 |
commit | 142f9913a6158a65fd92878bb554829b32b185fe (patch) | |
tree | bf284561b67d4d12e26f2e0ad70b2f865c797a87 | |
parent | 6435191a6e96600db9efbad8514d6c2eff1375d1 (diff) | |
download | nextcloud-server-142f9913a6158a65fd92878bb554829b32b185fe.tar.gz nextcloud-server-142f9913a6158a65fd92878bb554829b32b185fe.zip |
Expose mapped user count from LDAP and use that for user limit check
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | apps/user_ldap/lib/User_LDAP.php | 9 | ||||
-rw-r--r-- | apps/user_ldap/lib/User_Proxy.php | 18 | ||||
-rw-r--r-- | lib/private/Support/Subscription/Registry.php | 8 |
3 files changed, 29 insertions, 6 deletions
diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index 5a445100052..650c974da81 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -45,14 +45,15 @@ use OCA\User_LDAP\Exceptions\NotOnLDAP; 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\IUserBackend; use OCP\UserInterface; use Psr\Log\LoggerInterface; -class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend { +class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend { /** @var \OCP\IConfig */ protected $ocConfig; @@ -598,6 +599,10 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I return $entries; } + public function countMappedUsers(): int { + return $this->access->getUserMapper()->count(); + } + /** * Backend name to be shown in user management * @return string the name of the backend to be shown diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php index 93420bbb470..b98fa8da0ff 100644 --- a/apps/user_ldap/lib/User_Proxy.php +++ b/apps/user_ldap/lib/User_Proxy.php @@ -33,11 +33,14 @@ namespace OCA\User_LDAP; 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\UserInterface; -class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP, ICountUsersBackend { +class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend { private $backends = []; /** @var User_LDAP */ private $refBackend = null; @@ -390,6 +393,19 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, } /** + * Count the number of mapped users + */ + public function countMappedUsers(): int { + $this->setup(); + + $users = 0; + foreach ($this->backends as $backend) { + $users += $backend->countMappedUsers(); + } + return $users; + } + + /** * Return access for LDAP interaction. * * @param string $uid diff --git a/lib/private/Support/Subscription/Registry.php b/lib/private/Support/Subscription/Registry.php index 87070e7a0dc..7aafa539a0b 100644 --- a/lib/private/Support/Subscription/Registry.php +++ b/lib/private/Support/Subscription/Registry.php @@ -34,15 +34,15 @@ use OCP\IGroupManager; use OCP\IServerContainer; use OCP\IUserManager; use OCP\Notification\IManager; -use OCP\User\Backend\ICountUsersBackend; use OCP\Support\Subscription\Exception\AlreadyRegisteredException; use OCP\Support\Subscription\IRegistry; use OCP\Support\Subscription\ISubscription; use OCP\Support\Subscription\ISupportedApps; +use OCP\User\Backend\ICountMappedUsersBackend; +use OCP\User\Backend\ICountUsersBackend; use Psr\Log\LoggerInterface; class Registry implements IRegistry { - /** @var ISubscription */ private $subscription = null; @@ -189,7 +189,9 @@ class Registry implements IRegistry { $userCount = 0; $backends = $this->userManager->getBackends(); foreach ($backends as $backend) { - if ($backend->implementsActions(Backend::COUNT_USERS)) { + if ($backend instanceof ICountMappedUsersBackend) { + $userCount += $backend->countMappedUsers(); + } elseif ($backend->implementsActions(Backend::COUNT_USERS)) { /** @var ICountUsersBackend $backend */ $backendUsers = $backend->countUsers(); if ($backendUsers !== false) { |