2015-08-13 19:31:38 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @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/>
|
|
|
|
*
|
|
|
|
*/
|
2015-10-20 10:32:59 +00:00
|
|
|
|
2015-08-13 19:31:38 +00:00
|
|
|
/**
|
|
|
|
* This class provides all methods needed for managing groups.
|
|
|
|
*
|
|
|
|
* Hooks provided:
|
|
|
|
* post_createSubAdmin($gid)
|
|
|
|
* post_deleteSubAdmin($gid)
|
|
|
|
*/
|
|
|
|
class OC_SubAdmin{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add a SubAdmin
|
|
|
|
* @param string $uid uid of the SubAdmin
|
|
|
|
* @param string $gid gid of the group
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function createSubAdmin($uid, $gid) {
|
2015-10-20 10:32:59 +00:00
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
|
|
|
$userManager = \OC::$server->getUserManager();
|
|
|
|
$subAdmin = $groupManager->getSubAdmin();
|
|
|
|
|
|
|
|
return $subAdmin->createSubAdmin($userManager->get($uid), $groupManager->get($gid));
|
2015-08-13 19:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete a SubAdmin
|
|
|
|
* @param string $uid uid of the SubAdmin
|
|
|
|
* @param string $gid gid of the group
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function deleteSubAdmin($uid, $gid) {
|
2015-10-20 10:32:59 +00:00
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
|
|
|
$userManager = \OC::$server->getUserManager();
|
|
|
|
$subAdmin = $groupManager->getSubAdmin();
|
|
|
|
|
|
|
|
return $subAdmin->deleteSubAdmin($userManager->get($uid), $groupManager->get($gid));
|
2015-08-13 19:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get groups of a SubAdmin
|
|
|
|
* @param string $uid uid of the SubAdmin
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getSubAdminsGroups($uid) {
|
2015-10-20 10:32:59 +00:00
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
|
|
|
$userManager = \OC::$server->getUserManager();
|
|
|
|
$subAdmin = $groupManager->getSubAdmin();
|
|
|
|
|
|
|
|
$groups = $subAdmin->getSubAdminsGroups($userManager->get($uid));
|
|
|
|
|
|
|
|
// New class returns IGroup[] so convert back
|
|
|
|
$gids = [];
|
|
|
|
foreach ($groups as $group) {
|
|
|
|
$gids[] = $group->getGID();
|
2015-08-13 19:31:38 +00:00
|
|
|
}
|
|
|
|
return $gids;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get SubAdmins of a group
|
|
|
|
* @param string $gid gid of the group
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getGroupsSubAdmins($gid) {
|
2015-10-20 10:32:59 +00:00
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
|
|
|
$subAdmin = $groupManager->getSubAdmin();
|
|
|
|
|
|
|
|
$users = $subAdmin->getGroupsSubAdmins($groupManager->get($gid));
|
|
|
|
|
|
|
|
// New class returns IUser[] so convert back
|
|
|
|
$uids = [];
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$uids[] = $user->getUID();
|
2015-08-13 19:31:38 +00:00
|
|
|
}
|
|
|
|
return $uids;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get all SubAdmins
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getAllSubAdmins() {
|
2015-10-20 10:32:59 +00:00
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
|
|
|
$subAdmin = $groupManager->getSubAdmin();
|
|
|
|
|
|
|
|
$subAdmins = $subAdmin->getAllSubAdmins();
|
|
|
|
|
|
|
|
// New class returns IUser[] so convert back
|
|
|
|
$result = [];
|
|
|
|
foreach ($subAdmins as $subAdmin) {
|
|
|
|
$result[] = [
|
|
|
|
'gid' => $subAdmin['group']->getGID(),
|
|
|
|
'uid' => $subAdmin['user']->getUID(),
|
|
|
|
];
|
2015-08-13 19:31:38 +00:00
|
|
|
}
|
2015-10-20 10:32:59 +00:00
|
|
|
return $result;
|
2015-08-13 19:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checks if a user is a SubAdmin of a group
|
|
|
|
* @param string $uid uid of the subadmin
|
|
|
|
* @param string $gid gid of the group
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isSubAdminofGroup($uid, $gid) {
|
2015-10-20 10:32:59 +00:00
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
|
|
|
$userManager = \OC::$server->getUserManager();
|
|
|
|
$subAdmin = $groupManager->getSubAdmin();
|
|
|
|
|
|
|
|
return $subAdmin->isSubAdminOfGroup($userManager->get($uid), $groupManager->get($gid));
|
2015-08-13 19:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checks if a user is a SubAdmin
|
|
|
|
* @param string $uid uid of the subadmin
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isSubAdmin($uid) {
|
2015-10-20 10:32:59 +00:00
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
|
|
|
$userManager = \OC::$server->getUserManager();
|
|
|
|
$subAdmin = $groupManager->getSubAdmin();
|
2015-08-13 19:31:38 +00:00
|
|
|
|
2015-10-20 10:32:59 +00:00
|
|
|
return $subAdmin->isSubAdmin($userManager->get($uid));
|
2015-08-13 19:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checks if a user is a accessible by a subadmin
|
|
|
|
* @param string $subadmin uid of the subadmin
|
|
|
|
* @param string $user uid of the user
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isUserAccessible($subadmin, $user) {
|
2015-10-20 10:32:59 +00:00
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
|
|
|
$userManager = \OC::$server->getUserManager();
|
|
|
|
$subAdmin = $groupManager->getSubAdmin();
|
|
|
|
|
|
|
|
return $subAdmin->isUserAccessible($userManager->get($subadmin), $userManager->get($user));
|
2015-08-13 19:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* alias for self::isSubAdminofGroup()
|
|
|
|
*/
|
|
|
|
public static function isGroupAccessible($subadmin, $group) {
|
|
|
|
return self::isSubAdminofGroup($subadmin, $group);
|
|
|
|
}
|
|
|
|
}
|