summaryrefslogtreecommitdiffstats
path: root/lib/private/legacy
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2015-10-20 12:32:59 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-10-21 11:32:38 +0200
commitc515628ebe23d78170c699a63d9a2ca1100e5412 (patch)
tree1540fe9db8c5637e46d4db221759d87d668cf5ba /lib/private/legacy
parent0e9ab139432b562f442e01a983b7dcfbd6499115 (diff)
downloadnextcloud-server-c515628ebe23d78170c699a63d9a2ca1100e5412.tar.gz
nextcloud-server-c515628ebe23d78170c699a63d9a2ca1100e5412.zip
Legacy OC_SubAdmin is now just a wrapper
Diffstat (limited to 'lib/private/legacy')
-rw-r--r--lib/private/legacy/subadmin.php136
1 files changed, 57 insertions, 79 deletions
diff --git a/lib/private/legacy/subadmin.php b/lib/private/legacy/subadmin.php
index ec4f9f3b899..d10b6e90bb5 100644
--- a/lib/private/legacy/subadmin.php
+++ b/lib/private/legacy/subadmin.php
@@ -24,8 +24,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
-OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_SubAdmin', 'post_deleteUser');
-OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC_SubAdmin', 'post_deleteGroup');
+
/**
* This class provides all methods needed for managing groups.
*
@@ -42,10 +41,11 @@ class OC_SubAdmin{
* @return boolean
*/
public static function createSubAdmin($uid, $gid) {
- $stmt = OC_DB::prepare('INSERT INTO `*PREFIX*group_admin` (`gid`,`uid`) VALUES(?,?)');
- $stmt->execute(array($gid, $uid));
- OC_Hook::emit( "OC_SubAdmin", "post_createSubAdmin", array( "gid" => $gid ));
- return true;
+ $groupManager = \OC::$server->getGroupManager();
+ $userManager = \OC::$server->getUserManager();
+ $subAdmin = $groupManager->getSubAdmin();
+
+ return $subAdmin->createSubAdmin($userManager->get($uid), $groupManager->get($gid));
}
/**
@@ -55,10 +55,11 @@ class OC_SubAdmin{
* @return boolean
*/
public static function deleteSubAdmin($uid, $gid) {
- $stmt = OC_DB::prepare('DELETE FROM `*PREFIX*group_admin` WHERE `gid` = ? AND `uid` = ?');
- $stmt->execute(array($gid, $uid));
- OC_Hook::emit( "OC_SubAdmin", "post_deleteSubAdmin", array( "gid" => $gid ));
- return true;
+ $groupManager = \OC::$server->getGroupManager();
+ $userManager = \OC::$server->getUserManager();
+ $subAdmin = $groupManager->getSubAdmin();
+
+ return $subAdmin->deleteSubAdmin($userManager->get($uid), $groupManager->get($gid));
}
/**
@@ -67,11 +68,16 @@ class OC_SubAdmin{
* @return array
*/
public static function getSubAdminsGroups($uid) {
- $stmt = OC_DB::prepare('SELECT `gid` FROM `*PREFIX*group_admin` WHERE `uid` = ?');
- $result = $stmt->execute(array($uid));
- $gids = array();
- while($row = $result->fetchRow()) {
- $gids[] = $row['gid'];
+ $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();
}
return $gids;
}
@@ -82,11 +88,15 @@ class OC_SubAdmin{
* @return array
*/
public static function getGroupsSubAdmins($gid) {
- $stmt = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_admin` WHERE `gid` = ?');
- $result = $stmt->execute(array($gid));
- $uids = array();
- while($row = $result->fetchRow()) {
- $uids[] = $row['uid'];
+ $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();
}
return $uids;
}
@@ -96,13 +106,20 @@ class OC_SubAdmin{
* @return array
*/
public static function getAllSubAdmins() {
- $stmt = OC_DB::prepare('SELECT * FROM `*PREFIX*group_admin`');
- $result = $stmt->execute();
- $subadmins = array();
- while($row = $result->fetchRow()) {
- $subadmins[] = $row;
+ $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(),
+ ];
}
- return $subadmins;
+ return $result;
}
/**
@@ -112,13 +129,11 @@ class OC_SubAdmin{
* @return bool
*/
public static function isSubAdminofGroup($uid, $gid) {
- $stmt = OC_DB::prepare('SELECT COUNT(*) AS `count` FROM `*PREFIX*group_admin` WHERE `uid` = ? AND `gid` = ?');
- $result = $stmt->execute(array($uid, $gid));
- $result = $result->fetchRow();
- if($result['count'] >= 1) {
- return true;
- }
- return false;
+ $groupManager = \OC::$server->getGroupManager();
+ $userManager = \OC::$server->getUserManager();
+ $subAdmin = $groupManager->getSubAdmin();
+
+ return $subAdmin->isSubAdminOfGroup($userManager->get($uid), $groupManager->get($gid));
}
/**
@@ -127,18 +142,11 @@ class OC_SubAdmin{
* @return bool
*/
public static function isSubAdmin($uid) {
- // Check if the user is already an admin
- if(OC_Group::inGroup($uid, 'admin' )) {
- return true;
- }
+ $groupManager = \OC::$server->getGroupManager();
+ $userManager = \OC::$server->getUserManager();
+ $subAdmin = $groupManager->getSubAdmin();
- $stmt = OC_DB::prepare('SELECT COUNT(*) AS `count` FROM `*PREFIX*group_admin` WHERE `uid` = ?');
- $result = $stmt->execute(array($uid));
- $result = $result->fetchRow();
- if($result['count'] > 0) {
- return true;
- }
- return false;
+ return $subAdmin->isSubAdmin($userManager->get($uid));
}
/**
@@ -148,19 +156,11 @@ class OC_SubAdmin{
* @return bool
*/
public static function isUserAccessible($subadmin, $user) {
- if(!self::isSubAdmin($subadmin)) {
- return false;
- }
- if(OC_User::isAdminUser($user)) {
- return false;
- }
- $accessiblegroups = self::getSubAdminsGroups($subadmin);
- foreach($accessiblegroups as $accessiblegroup) {
- if(OC_Group::inGroup($user, $accessiblegroup)) {
- return true;
- }
- }
- return false;
+ $groupManager = \OC::$server->getGroupManager();
+ $userManager = \OC::$server->getUserManager();
+ $subAdmin = $groupManager->getSubAdmin();
+
+ return $subAdmin->isUserAccessible($userManager->get($subadmin), $userManager->get($user));
}
/*
@@ -169,26 +169,4 @@ class OC_SubAdmin{
public static function isGroupAccessible($subadmin, $group) {
return self::isSubAdminofGroup($subadmin, $group);
}
-
- /**
- * delete all SubAdmins by uid
- * @param array $parameters
- * @return boolean
- */
- public static function post_deleteUser($parameters) {
- $stmt = OC_DB::prepare('DELETE FROM `*PREFIX*group_admin` WHERE `uid` = ?');
- $stmt->execute(array($parameters['uid']));
- return true;
- }
-
- /**
- * delete all SubAdmins by gid
- * @param array $parameters
- * @return boolean
- */
- public static function post_deleteGroup($parameters) {
- $stmt = OC_DB::prepare('DELETE FROM `*PREFIX*group_admin` WHERE `gid` = ?');
- $stmt->execute(array($parameters['gid']));
- return true;
- }
}