]> source.dussan.org Git - nextcloud-server.git/commitdiff
Expose mapped user count from LDAP and use that for user limit check
authorCôme Chilliet <come.chilliet@nextcloud.com>
Mon, 24 Oct 2022 14:39:43 +0000 (16:39 +0200)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 25 Oct 2022 12:50:56 +0000 (14:50 +0200)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
apps/user_ldap/lib/User_LDAP.php
apps/user_ldap/lib/User_Proxy.php
lib/private/Support/Subscription/Registry.php

index 5a4451000526260b2e43392600862b60f2df00d4..650c974da81733cf8aabc8e626292f7a163e3f85 100644 (file)
@@ -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
index 93420bbb470b47aeb8512f3c7f35100fbe2e03fd..b98fa8da0ff5e5e04b89e9b602c73ccac83893cc 100644 (file)
@@ -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;
@@ -389,6 +392,19 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
                return $users;
        }
 
+       /**
+        * 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.
         *
index 87070e7a0dcb879acc4035d2377bc915295eba67..7aafa539a0bc85dc38d5c8b01b61e003c4e3fc5e 100644 (file)
@@ -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) {