aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/User
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2018-05-25 15:54:47 +0200
committerGitHub <noreply@github.com>2018-05-25 15:54:47 +0200
commit760b28ba4c7d4a9b6126aa4063238c2959eb263e (patch)
tree3671b2c23d7a9316a3b66e0e23d7062a65a30464 /lib/private/User
parentd4a0af7e5ec0d0e97dda2d826574779dab82260c (diff)
parent4644841ba67e1e1f606011b51148303f59be3960 (diff)
downloadnextcloud-server-760b28ba4c7d4a9b6126aa4063238c2959eb263e.tar.gz
nextcloud-server-760b28ba4c7d4a9b6126aa4063238c2959eb263e.zip
Merge pull request #9488 from nextcloud/disabled-users-fix
Added disabled count per groups & fixed disabled users query
Diffstat (limited to 'lib/private/User')
-rw-r--r--lib/private/User/Manager.php67
1 files changed, 61 insertions, 6 deletions
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index b5054bd1851..6784359538d 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -34,6 +34,7 @@ namespace OC\User;
use OC\Hooks\PublicEmitter;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IUser;
+use OCP\IGroup;
use OCP\IUserBackend;
use OCP\IUserManager;
use OCP\IConfig;
@@ -385,6 +386,24 @@ class Manager extends PublicEmitter implements IUserManager {
}
/**
+ * returns how many users per backend exist in the requested groups (if supported by backend)
+ *
+ * @param IGroup[] $groups an array of gid to search in
+ * @return array|int an array of backend class as key and count number as value
+ * if $hasLoggedIn is true only an int is returned
+ */
+ public function countUsersOfGroups(array $groups) {
+ $users = [];
+ foreach($groups as $group) {
+ $usersIds = array_map(function($user) {
+ return $user->getUID();
+ }, $group->getUsers());
+ $users = array_merge($users, $usersIds);
+ }
+ return count(array_unique($users));
+ }
+
+ /**
* The callback is executed for each user on each backend.
* If the callback returns false no further users will be retrieved.
*
@@ -420,12 +439,12 @@ class Manager extends PublicEmitter implements IUserManager {
}
/**
- * returns how many users have logged in once
+ * returns how many users are disabled
*
* @return int
* @since 12.0.0
*/
- public function countDisabledUsers() {
+ public function countDisabledUsers(): int {
$queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$queryBuilder->select($queryBuilder->createFunction('COUNT(*)'))
->from('preferences')
@@ -433,12 +452,48 @@ class Manager extends PublicEmitter implements IUserManager {
->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR));
- $query = $queryBuilder->execute();
+
+ $result = $queryBuilder->execute();
+ $count = $result->fetchColumn();
+ $result->closeCursor();
+
+ if ($count !== false) {
+ $count = (int)$count;
+ } else {
+ $count = 0;
+ }
- $result = (int)$query->fetchColumn();
- $query->closeCursor();
+ return $count;
+ }
- return $result;
+ /**
+ * returns how many users are disabled in the requested groups
+ *
+ * @param array $groups groupids to search
+ * @return int
+ * @since 14.0.0
+ */
+ public function countDisabledUsersOfGroups(array $groups): int {
+ $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $queryBuilder->select($queryBuilder->createFunction('COUNT(Distinct uid)'))
+ ->from('preferences', 'p')
+ ->innerJoin('p', 'group_user', 'g', 'p.userid = g.uid')
+ ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core')))
+ ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
+ ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR))
+ ->andWhere($queryBuilder->expr()->in('gid', $queryBuilder->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY)));
+
+ $result = $queryBuilder->execute();
+ $count = $result->fetchColumn();
+ $result->closeCursor();
+
+ if ($count !== false) {
+ $count = (int)$count;
+ } else {
+ $count = 0;
+ }
+
+ return $count;
}
/**