Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/user_ldap/lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@
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;

Expand Down Expand Up @@ -598,6 +599,10 @@ public function countUsers() {
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
Expand Down
18 changes: 17 additions & 1 deletion apps/user_ldap/lib/User_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@

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;
Expand Down Expand Up @@ -389,6 +392,19 @@ public function countUsers() {
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.
*
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@
'OCP\\UserStatus\\IUserStatus' => $baseDir . '/lib/public/UserStatus/IUserStatus.php',
'OCP\\User\\Backend\\ABackend' => $baseDir . '/lib/public/User/Backend/ABackend.php',
'OCP\\User\\Backend\\ICheckPasswordBackend' => $baseDir . '/lib/public/User/Backend/ICheckPasswordBackend.php',
'OCP\\User\\Backend\\ICountMappedUsersBackend' => $baseDir . '/lib/public/User/Backend/ICountMappedUsersBackend.php',
'OCP\\User\\Backend\\ICountUsersBackend' => $baseDir . '/lib/public/User/Backend/ICountUsersBackend.php',
'OCP\\User\\Backend\\ICreateUserBackend' => $baseDir . '/lib/public/User/Backend/ICreateUserBackend.php',
'OCP\\User\\Backend\\ICustomLogout' => $baseDir . '/lib/public/User/Backend/ICustomLogout.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\UserStatus\\IUserStatus' => __DIR__ . '/../../..' . '/lib/public/UserStatus/IUserStatus.php',
'OCP\\User\\Backend\\ABackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ABackend.php',
'OCP\\User\\Backend\\ICheckPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICheckPasswordBackend.php',
'OCP\\User\\Backend\\ICountMappedUsersBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICountMappedUsersBackend.php',
'OCP\\User\\Backend\\ICountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICountUsersBackend.php',
'OCP\\User\\Backend\\ICreateUserBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICreateUserBackend.php',
'OCP\\User\\Backend\\ICustomLogout' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICustomLogout.php',
Expand Down
8 changes: 5 additions & 3 deletions lib/private/Support/Subscription/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
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;

Expand Down Expand Up @@ -189,7 +189,9 @@ private function getUserCount(): int {
$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) {
Expand Down
39 changes: 39 additions & 0 deletions lib/public/User/Backend/ICountMappedUsersBackend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2022 Côme Chilliet <[email protected]>
*
* @author Côme Chilliet <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCP\User\Backend;

/**
* @since 24.0.7
*/
interface ICountMappedUsersBackend {
/**
* @since 24.0.7
*
* @return int The number of users already mapped to a Nextcloud account
*/
public function countMappedUsers(): int;
}