summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-05-16 12:32:56 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-05-24 17:52:15 +0200
commit10c135ca3414544a92febbc45b39d358c8383757 (patch)
tree17137dc89af559ed083dd36824ba78803a8e58d1
parent6689a3e37b5bc71a66462c547072ad7555958c05 (diff)
downloadnextcloud-server-10c135ca3414544a92febbc45b39d358c8383757.tar.gz
nextcloud-server-10c135ca3414544a92febbc45b39d358c8383757.zip
Added disabled count per groups
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r--apps/provisioning_api/lib/Controller/GroupsController.php7
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Group/Database.php35
-rw-r--r--lib/private/Group/Group.php22
-rw-r--r--lib/private/Group/MetaData.php12
-rw-r--r--lib/private/User/Manager.php48
-rw-r--r--lib/public/Group/Backend/ICountDisabledInGroup.php36
8 files changed, 151 insertions, 11 deletions
diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php
index c2958bc4778..9d64bb2251a 100644
--- a/apps/provisioning_api/lib/Controller/GroupsController.php
+++ b/apps/provisioning_api/lib/Controller/GroupsController.php
@@ -111,7 +111,12 @@ class GroupsController extends AUserData {
$groups = $this->groupManager->search($search, $limit, $offset);
$groups = array_map(function($group) {
/** @var IGroup $group */
- return ['id' => $group->getGID(), 'displayname' => $group->getDisplayName()];
+ return [
+ 'id' => $group->getGID(),
+ 'displayname' => $group->getDisplayName(),
+ 'usercount' => $group->count(),
+ 'disabled' => $group->countDisabled()
+ ];
}, $groups);
return new DataResponse(['groups' => $groups]);
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index c6475f8c889..d457d2e758b 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -188,6 +188,7 @@ return array(
'OCP\\GroupInterface' => $baseDir . '/lib/public/GroupInterface.php',
'OCP\\Group\\Backend\\ABackend' => $baseDir . '/lib/public/Group/Backend/ABackend.php',
'OCP\\Group\\Backend\\IAddToGroupBackend' => $baseDir . '/lib/public/Group/Backend/IAddToGroupBackend.php',
+ 'OCP\\Group\\Backend\\ICountDisabledInGroup' => $baseDir . '/lib/public/Group/Backend/ICountDisabledInGroup.php',
'OCP\\Group\\Backend\\ICountUsersBackend' => $baseDir . '/lib/public/Group/Backend/ICountUsersBackend.php',
'OCP\\Group\\Backend\\ICreateGroupBackend' => $baseDir . '/lib/public/Group/Backend/ICreateGroupBackend.php',
'OCP\\Group\\Backend\\IDeleteGroupBackend' => $baseDir . '/lib/public/Group/Backend/IDeleteGroupBackend.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index f334733a2c9..88f8248b7f2 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -218,6 +218,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\GroupInterface' => __DIR__ . '/../../..' . '/lib/public/GroupInterface.php',
'OCP\\Group\\Backend\\ABackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ABackend.php',
'OCP\\Group\\Backend\\IAddToGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IAddToGroupBackend.php',
+ 'OCP\\Group\\Backend\\ICountDisabledInGroup' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICountDisabledInGroup.php',
'OCP\\Group\\Backend\\ICountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICountUsersBackend.php',
'OCP\\Group\\Backend\\ICreateGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICreateGroupBackend.php',
'OCP\\Group\\Backend\\IDeleteGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IDeleteGroupBackend.php',
diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php
index 639df3de0de..90aacdf0020 100644
--- a/lib/private/Group/Database.php
+++ b/lib/private/Group/Database.php
@@ -5,6 +5,7 @@
* @author Aaron Wood <aaronjwood@gmail.com>
* @author Loki3000 <github@labcms.ru>
* @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license AGPL-3.0
*
@@ -40,8 +41,10 @@
namespace OC\Group;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Group\Backend\ABackend;
use OCP\Group\Backend\IAddToGroupBackend;
+use OCP\Group\Backend\ICountDisabledInGroup;
use OCP\Group\Backend\ICountUsersBackend;
use OCP\Group\Backend\ICreateGroupBackend;
use OCP\Group\Backend\IDeleteGroupBackend;
@@ -53,6 +56,7 @@ use OCP\IDBConnection;
*/
class Database extends ABackend
implements IAddToGroupBackend,
+ ICountDisabledInGroup,
ICountUsersBackend,
ICreateGroupBackend,
IDeleteGroupBackend,
@@ -373,4 +377,35 @@ class Database extends ABackend
return $count;
}
+ /**
+ * get the number of disabled users in a group
+ *
+ * @param string $search
+ * @return int|bool
+ */
+ public function countDisabledInGroup(string $gid): int {
+ $this->fixDI();
+
+ $query = $this->dbConn->getQueryBuilder();
+ $query->select($query->createFunction('COUNT(Distinct uid)'))
+ ->from('preferences', 'p')
+ ->innerJoin('p', 'group_user', 'g', 'p.userid = g.uid')
+ ->where($query->expr()->eq('appid', $query->createNamedParameter('core')))
+ ->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('enabled')))
+ ->andWhere($query->expr()->eq('configvalue', $query->createNamedParameter('false'), IQueryBuilder::PARAM_STR))
+ ->andWhere($query->expr()->eq('gid', $query->createNamedParameter($gid), IQueryBuilder::PARAM_STR));
+
+ $result = $query->execute();
+ $count = $result->fetchColumn();
+ $result->closeCursor();
+
+ if ($count !== false) {
+ $count = (int)$count;
+ } else {
+ $count = 0;
+ }
+
+ return $count;
+ }
+
}
diff --git a/lib/private/Group/Group.php b/lib/private/Group/Group.php
index 6795f0e2f53..cc6315263d4 100644
--- a/lib/private/Group/Group.php
+++ b/lib/private/Group/Group.php
@@ -10,6 +10,7 @@
* @author Robin McCorkell <robin@mccorkell.me.uk>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Vincent Petry <pvince81@owncloud.com>
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license AGPL-3.0
*
@@ -31,6 +32,7 @@ namespace OC\Group;
use OCP\IGroup;
use OCP\IUser;
+use OCP\Group\Backend\ICountDisabledInGroup;
class Group implements IGroup {
/** @var null|string */
@@ -237,6 +239,26 @@ class Group implements IGroup {
}
/**
+ * returns the number of disabled users
+ *
+ * @return int|bool
+ */
+ public function countDisabled() {
+ $users = false;
+ foreach ($this->backends as $backend) {
+ if($backend instanceOf ICountDisabledInGroup) {
+ if($users === false) {
+ //we could directly add to a bool variable, but this would
+ //be ugly
+ $users = 0;
+ }
+ $users += $backend->countDisabledInGroup($this->gid);
+ }
+ }
+ return $users;
+ }
+
+ /**
* search for users in the group by displayname
*
* @param string $search
diff --git a/lib/private/Group/MetaData.php b/lib/private/Group/MetaData.php
index 99594301990..1e89472bc30 100644
--- a/lib/private/Group/MetaData.php
+++ b/lib/private/Group/MetaData.php
@@ -8,6 +8,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Stephan Peijnik <speijnik@anexia-it.com>
* @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license AGPL-3.0
*
@@ -28,6 +29,7 @@
namespace OC\Group;
use OCP\IUserSession;
+use OCP\IGroupManager;
class MetaData {
const SORT_NONE = 0;
@@ -40,7 +42,7 @@ class MetaData {
protected $isAdmin;
/** @var array */
protected $metaData = array();
- /** @var \OCP\IGroupManager */
+ /** @var IGroupManager */
protected $groupManager;
/** @var bool */
protected $sorting = false;
@@ -50,13 +52,14 @@ class MetaData {
/**
* @param string $user the uid of the current user
* @param bool $isAdmin whether the current users is an admin
- * @param \OCP\IGroupManager $groupManager
+ * @param IGroupManager $groupManager
+ * @param IUserManager $userManager
* @param IUserSession $userSession
*/
public function __construct(
$user,
$isAdmin,
- \OCP\IGroupManager $groupManager,
+ IGroupManager $groupManager,
IUserSession $userSession
) {
$this->user = $user;
@@ -155,13 +158,14 @@ class MetaData {
* creates an array containing the group meta data
* @param \OCP\IGroup $group
* @param string $userSearch
- * @return array with the keys 'id', 'name' and 'usercount'
+ * @return array with the keys 'id', 'name', 'usercount' and 'disabled'
*/
private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) {
return array(
'id' => $group->getGID(),
'name' => $group->getDisplayName(),
'usercount' => $this->sorting === self::SORT_USERCOUNT ? $group->count($userSearch) : 0,
+ 'disabled' => $group->countDisabled()
);
}
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index b5054bd1851..17712321933 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -420,12 +420,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 +433,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;
}
/**
diff --git a/lib/public/Group/Backend/ICountDisabledInGroup.php b/lib/public/Group/Backend/ICountDisabledInGroup.php
new file mode 100644
index 00000000000..fa07bcf7e5b
--- /dev/null
+++ b/lib/public/Group/Backend/ICountDisabledInGroup.php
@@ -0,0 +1,36 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @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\Group\Backend;
+
+/**
+ * @since 14.0.0
+ */
+interface ICountDisabledInGroup {
+
+ /**
+ * @since 14.0.0
+ */
+ public function countDisabledInGroup(string $gid): int;
+}