aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Group/MetaData.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Group/MetaData.php')
-rw-r--r--lib/private/Group/MetaData.php89
1 files changed, 23 insertions, 66 deletions
diff --git a/lib/private/Group/MetaData.php b/lib/private/Group/MetaData.php
index 5449cdbe29a..77432eea5ff 100644
--- a/lib/private/Group/MetaData.php
+++ b/lib/private/Group/MetaData.php
@@ -1,37 +1,14 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Stephan Peijnik <speijnik@anexia-it.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OC\Group;
use OC\Group\Manager as GroupManager;
+use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUserSession;
@@ -40,35 +17,22 @@ class MetaData {
public const SORT_USERCOUNT = 1; // May have performance issues on LDAP backends
public const SORT_GROUPNAME = 2;
- /** @var string */
- protected $user;
- /** @var bool */
- protected $isAdmin;
/** @var array */
protected $metaData = [];
- /** @var GroupManager */
- protected $groupManager;
- /** @var bool */
- protected $sorting = false;
- /** @var IUserSession */
- protected $userSession;
+ /** @var int */
+ protected $sorting = self::SORT_NONE;
/**
* @param string $user the uid of the current user
* @param bool $isAdmin whether the current users is an admin
- * @param IGroupManager $groupManager
- * @param IUserSession $userSession
*/
public function __construct(
- $user,
- $isAdmin,
- IGroupManager $groupManager,
- IUserSession $userSession
- ) {
- $this->user = $user;
- $this->isAdmin = (bool)$isAdmin;
- $this->groupManager = $groupManager;
- $this->userSession = $userSession;
+ private string $user,
+ private bool $isAdmin,
+ private bool $isDelegatedAdmin,
+ private IGroupManager $groupManager,
+ private IUserSession $userSession,
+ ) {
}
/**
@@ -77,11 +41,10 @@ class MetaData {
* [0] array containing meta data about admin groups
* [1] array containing meta data about unprivileged groups
* @param string $groupSearch only effective when instance was created with
- * isAdmin being true
+ * isAdmin being true
* @param string $userSearch the pattern users are search for
- * @return array
*/
- public function get($groupSearch = '', $userSearch = '') {
+ public function get(string $groupSearch = '', string $userSearch = ''): array {
$key = $groupSearch . '::' . $userSearch;
if (isset($this->metaData[$key])) {
return $this->metaData[$key];
@@ -124,10 +87,8 @@ class MetaData {
/**
* sets the sort mode, see SORT_* constants for supported modes
- *
- * @param int $sortMode
*/
- public function setSorting($sortMode) {
+ public function setSorting(int $sortMode): void {
switch ($sortMode) {
case self::SORT_USERCOUNT:
case self::SORT_GROUPNAME:
@@ -146,7 +107,7 @@ class MetaData {
* @param int $sortIndex the sort key index, by reference
* @param array $data the group's meta data as returned by generateGroupMetaData()
*/
- private function addEntry(&$entries, &$sortKeys, &$sortIndex, $data) {
+ private function addEntry(array &$entries, array &$sortKeys, int &$sortIndex, array $data): void {
$entries[] = $data;
if ($this->sorting === self::SORT_USERCOUNT) {
$sortKeys[$sortIndex] = $data['usercount'];
@@ -159,11 +120,9 @@ class MetaData {
/**
* creates an array containing the group meta data
- * @param \OCP\IGroup $group
- * @param string $userSearch
* @return array with the keys 'id', 'name', 'usercount' and 'disabled'
*/
- private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) {
+ private function generateGroupMetaData(IGroup $group, string $userSearch): array {
return [
'id' => $group->getGID(),
'name' => $group->getDisplayName(),
@@ -178,9 +137,8 @@ class MetaData {
* sorts the result array, if applicable
* @param array $entries the result array, by reference
* @param array $sortKeys the array containing the sort keys
- * @param return null
*/
- private function sort(&$entries, $sortKeys) {
+ private function sort(array &$entries, array $sortKeys): void {
if ($this->sorting === self::SORT_USERCOUNT) {
array_multisort($sortKeys, SORT_DESC, $entries);
} elseif ($this->sorting === self::SORT_GROUPNAME) {
@@ -190,15 +148,14 @@ class MetaData {
/**
* returns the available groups
- * @param string $search a search string
- * @return \OCP\IGroup[]
+ * @return IGroup[]
*/
- public function getGroups($search = '') {
- if ($this->isAdmin) {
+ public function getGroups(string $search = ''): array {
+ if ($this->isAdmin || $this->isDelegatedAdmin) {
return $this->groupManager->search($search);
} else {
$userObject = $this->userSession->getUser();
- if ($userObject !== null) {
+ if ($userObject !== null && $this->groupManager instanceof GroupManager) {
$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($userObject);
} else {
$groups = [];