summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-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
4 files changed, 107 insertions, 10 deletions
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;
}
/**