summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-03-03 01:24:27 -0600
committerMorris Jobke <hey@morrisjobke.de>2017-03-09 17:35:09 -0600
commita5ba1f78033b3ebe69c771fb33c1217a60494728 (patch)
treeb4bdf0ec562db9e91071eeef39f82586ce48eef4 /lib
parent6fd0e7e93995facfe75b26699ea462bb94fd03b9 (diff)
downloadnextcloud-server-a5ba1f78033b3ebe69c771fb33c1217a60494728.tar.gz
nextcloud-server-a5ba1f78033b3ebe69c771fb33c1217a60494728.zip
Remove legacy class OC_Group and OC_User
* basically a straight replacement of the wrapped code at the calling code parts Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php2
-rw-r--r--lib/private/Encryption/Util.php12
-rw-r--r--lib/private/Share/Share.php98
-rw-r--r--lib/private/User/User.php10
-rw-r--r--lib/private/legacy/group.php302
-rw-r--r--lib/private/legacy/user.php4
6 files changed, 107 insertions, 321 deletions
diff --git a/lib/base.php b/lib/base.php
index e9e9af8c553..68178b06c5b 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -698,7 +698,7 @@ class OC {
}
OC_User::useBackend(new \OC\User\Database());
- OC_Group::useBackend(new \OC\Group\Database());
+ \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database());
// Subscribe to the hook
\OCP\Util::connectHook(
diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php
index 3afa1bb9596..76e1200a1cb 100644
--- a/lib/private/Encryption/Util.php
+++ b/lib/private/Encryption/Util.php
@@ -273,8 +273,18 @@ class Util {
$result = \OCP\User::getUsers();
} else {
$result = array_merge($result, $users);
+
+ $groupManager = \OC::$server->getGroupManager();
foreach ($groups as $group) {
- $result = array_merge($result, \OC_Group::usersInGroup($group));
+ $groupObject = $groupManager->get($group);
+ if ($groupObject) {
+ $foundUsers = $groupObject->searchUsers('', -1, 0);
+ $userIds = [];
+ foreach ($foundUsers as $user) {
+ $userIds[] = $user->getUID();
+ }
+ $result = array_merge($result, $userIds);
+ }
}
}
diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php
index 6abaa7dd413..da4b7dda91c 100644
--- a/lib/private/Share/Share.php
+++ b/lib/private/Share/Share.php
@@ -237,8 +237,19 @@ class Share extends Constants {
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage(), \OCP\Util::ERROR);
} else {
+ $groupManager = \OC::$server->getGroupManager();
while ($row = $result->fetchRow()) {
- $usersInGroup = \OC_Group::usersInGroup($row['share_with']);
+
+ $usersInGroup = [];
+ $group = $groupManager->get($row['share_with']);
+ if ($group) {
+ $users = $group->searchUsers('', -1, 0);
+ $userIds = array();
+ foreach ($users as $user) {
+ $userIds[] = $user->getUID();
+ }
+ $usersInGroup = $userIds;
+ }
$shares = array_merge($shares, $usersInGroup);
if ($returnUserPaths) {
foreach ($usersInGroup as $user) {
@@ -468,7 +479,11 @@ class Share extends Constants {
//if didn't found a result than let's look for a group share.
if(empty($shares) && $user !== null) {
- $groups = \OC_Group::getUserGroups($user);
+ $userObject = \OC::$server->getUserManager()->get($user);
+ $groups = [];
+ if ($userObject) {
+ $groups = \OC::$server->getGroupManager()->getUserGroupIds($userObject);
+ }
if (!empty($groups)) {
$where = $fileDependentWhere . ' WHERE `' . $column . '` = ? AND `item_type` = ? AND `share_with` in (?)';
@@ -628,7 +643,18 @@ class Share extends Constants {
if ((int)$item['share_type'] === self::SHARE_TYPE_USER) {
$users[] = $item['share_with'];
} else if ((int)$item['share_type'] === self::SHARE_TYPE_GROUP) {
- $users = array_merge($users, \OC_Group::usersInGroup($item['share_with']));
+
+ $group = \OC::$server->getGroupManager()->get($item['share_with']);
+ $userIds = [];
+ if ($group) {
+ $users = $group->searchUsers('', -1, 0);
+ foreach ($users as $user) {
+ $userIds[] = $user->getUID();
+ }
+ return $userIds;
+ }
+
+ $users = array_merge($users, $userIds);
}
}
}
@@ -740,7 +766,19 @@ class Share extends Constants {
throw new \Exception($message_t);
}
if ($shareWithinGroupOnly) {
- $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith));
+ $userManager = \OC::$server->getUserManager();
+ $groupManager = \OC::$server->getGroupManager();
+ $userOwner = $userManager->get($uidOwner);
+ $userShareWith = $userManager->get($shareWith);
+ $groupsOwner = [];
+ $groupsShareWith = [];
+ if ($userOwner) {
+ $groupsOwner = $groupManager->getUserGroupIds($userOwner);
+ }
+ if ($userShareWith) {
+ $groupsShareWith = $groupManager->getUserGroupIds($userShareWith);
+ }
+ $inGroup = array_intersect($groupsOwner, $groupsShareWith);
if (empty($inGroup)) {
$message = 'Sharing %s failed, because the user '
.'%s is not a member of any groups that %s is a member of';
@@ -775,18 +813,22 @@ class Share extends Constants {
}
}
} else if ($shareType === self::SHARE_TYPE_GROUP) {
- if (!\OC_Group::groupExists($shareWith)) {
+ if (!\OC::$server->getGroupManager()->groupExists($shareWith)) {
$message = 'Sharing %s failed, because the group %s does not exist';
$message_t = $l->t('Sharing %s failed, because the group %s does not exist', array($itemSourceName, $shareWith));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG);
throw new \Exception($message_t);
}
if ($shareWithinGroupOnly && !\OC_Group::inGroup($uidOwner, $shareWith)) {
- $message = 'Sharing %s failed, because '
- .'%s is not a member of the group %s';
- $message_t = $l->t('Sharing %s failed, because %s is not a member of the group %s', array($itemSourceName, $uidOwner, $shareWith));
- \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $uidOwner, $shareWith), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
+ $group = \OC::$server->getGroupManager()->get($shareWith);
+ $user = \OC::$server->getUserManager()->get($uidOwner);
+ if (!$group || !$user || !$group->inGroup($user)) {
+ $message = 'Sharing %s failed, because '
+ . '%s is not a member of the group %s';
+ $message_t = $l->t('Sharing %s failed, because %s is not a member of the group %s', array($itemSourceName, $uidOwner, $shareWith));
+ \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $uidOwner, $shareWith), \OCP\Util::DEBUG);
+ throw new \Exception($message_t);
+ }
}
// Check if the item source is already shared with the group, either from the same owner or a different user
// The check for each user in the group is done inside the put() function
@@ -804,7 +846,18 @@ class Share extends Constants {
$group = $shareWith;
$shareWith = array();
$shareWith['group'] = $group;
- $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner));
+
+
+ $groupObject = \OC::$server->getGroupManager()->get($group);
+ $userIds = [];
+ if ($groupObject) {
+ $users = $groupObject->searchUsers('', -1, 0);
+ foreach ($users as $user) {
+ $userIds[] = $user->getUID();
+ }
+ }
+
+ $shareWith['users'] = array_diff($userIds, array($uidOwner));
} else if ($shareType === self::SHARE_TYPE_LINK) {
$updateExistingShare = false;
if (\OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_links', 'yes') == 'yes') {
@@ -1057,7 +1110,9 @@ class Share extends Constants {
$itemUnshared = true;
break;
} elseif ((int)$share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) {
- if (\OC_Group::inGroup($uid, $share['share_with'])) {
+ $group = \OC::$server->getGroupManager()->get($share['share_with']);
+ $user = \OC::$server->getUserManager()->get($uid);
+ if ($group && $user && $group->inGroup($user)) {
$groupShare = $share;
}
} elseif ((int)$share['share_type'] === self::$shareTypeGroupUserUnique &&
@@ -1746,7 +1801,12 @@ class Share extends Constants {
$queryArgs[] = self::SHARE_TYPE_USER;
$queryArgs[] = self::$shareTypeGroupUserUnique;
$queryArgs[] = $shareWith;
- $groups = \OC_Group::getUserGroups($shareWith);
+
+ $user = \OC::$server->getUserManager()->get($shareWith);
+ $groups = [];
+ if ($user) {
+ $groups = \OC::$server->getGroupManager()->getUserGroupIds($user);
+ }
if (!empty($groups)) {
$placeholders = join(',', array_fill(0, count($groups), '?'));
$where .= ' OR (`share_type` = ? AND `share_with` IN ('.$placeholders.')) ';
@@ -2171,7 +2231,17 @@ class Share extends Constants {
if (isset($shareWith['users'])) {
$users = $shareWith['users'];
} else {
- $users = \OC_Group::usersInGroup($shareWith['group']);
+ $group = \OC::$server->getGroupManager()->get($shareWith['group']);
+ if ($group) {
+ $users = $group->searchUsers('', -1, 0);
+ $userIds = [];
+ foreach ($users as $user) {
+ $userIds[] = $user->getUID();
+ }
+ $users = $userIds;
+ } else {
+ $users = [];
+ }
}
// remove current user from list
if (in_array(\OCP\User::getUser(), $users)) {
diff --git a/lib/private/User/User.php b/lib/private/User/User.php
index 961f70f8a8e..bca9c46bfd0 100644
--- a/lib/private/User/User.php
+++ b/lib/private/User/User.php
@@ -204,9 +204,15 @@ class User implements IUser {
// FIXME: Feels like an hack - suggestions?
+ $groupManager = \OC::$server->getGroupManager();
// We have to delete the user from all groups
- foreach (\OC::$server->getGroupManager()->getUserGroupIds($this) as $groupId) {
- \OC_Group::removeFromGroup($this->uid, $groupId);
+ foreach ($groupManager->getUserGroupIds($this) as $groupId) {
+ $group = $groupManager->get($groupId);
+ if ($group) {
+ \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]);
+ $group->removeUser($this);
+ \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]);
+ }
}
// Delete the user's keys in preferences
\OC::$server->getConfig()->deleteAllUserValues($this->uid);
diff --git a/lib/private/legacy/group.php b/lib/private/legacy/group.php
deleted file mode 100644
index 6b58cb4c834..00000000000
--- a/lib/private/legacy/group.php
+++ /dev/null
@@ -1,302 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Georg Ehrke <georg@owncloud.com>
- * @author goodkiller <markopraakli@gmail.com>
- * @author Jakob Sack <mail@jakobsack.de>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author macjohnny <estebanmarin@gmx.ch>
- * @author Michael Gapczynski <GapczynskiM@gmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Qingping Hou <dave2008713@gmail.com>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @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/>
- *
- */
-
-/**
- * This class provides all methods needed for managing groups.
- *
- * Note that &run is deprecated and won't work anymore.
- * Hooks provided:
- * pre_createGroup(&run, gid)
- * post_createGroup(gid)
- * pre_deleteGroup(&run, gid)
- * post_deleteGroup(gid)
- * pre_addToGroup(&run, uid, gid)
- * post_addToGroup(uid, gid)
- * pre_removeFromGroup(&run, uid, gid)
- * post_removeFromGroup(uid, gid)
- */
-class OC_Group {
-
- /**
- * @return \OC\Group\Manager
- * @deprecated Use \OC::$server->getGroupManager();
- */
- public static function getManager() {
- return \OC::$server->getGroupManager();
- }
-
- /**
- * @return \OC\User\Manager
- * @deprecated Use \OC::$server->getUserManager()
- */
- private static function getUserManager() {
- return \OC::$server->getUserManager();
- }
-
- /**
- * set the group backend
- * @param \OC\Group\Backend $backend The backend to use for user management
- * @return bool
- */
- public static function useBackend($backend) {
- self::getManager()->addBackend($backend);
- return true;
- }
-
- /**
- * remove all used backends
- */
- public static function clearBackends() {
- self::getManager()->clearBackends();
- }
-
- /**
- * Try to create a new group
- * @param string $gid The name of the group to create
- * @return bool
- *
- * Tries to create a new group. If the group name already exists, false will
- * be returned. Basic checking of Group name
- * @deprecated Use \OC::$server->getGroupManager()->createGroup() instead
- */
- public static function createGroup($gid) {
- if (self::getManager()->createGroup($gid)) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * delete a group
- * @param string $gid gid of the group to delete
- * @return bool
- *
- * Deletes a group and removes it from the group_user-table
- * @deprecated Use \OC::$server->getGroupManager()->delete() instead
- */
- public static function deleteGroup($gid) {
- $group = self::getManager()->get($gid);
- if ($group) {
- if ($group->delete()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * is user in group?
- * @param string $uid uid of the user
- * @param string $gid gid of the group
- * @return bool
- *
- * Checks whether the user is member of a group or not.
- * @deprecated Use \OC::$server->getGroupManager->inGroup($user);
- */
- public static function inGroup($uid, $gid) {
- $group = self::getManager()->get($gid);
- $user = self::getUserManager()->get($uid);
- if ($group and $user) {
- return $group->inGroup($user);
- }
- return false;
- }
-
- /**
- * Add a user to a group
- * @param string $uid Name of the user to add to group
- * @param string $gid Name of the group in which add the user
- * @return bool
- *
- * Adds a user to a group.
- * @deprecated Use \OC::$server->getGroupManager->addUser();
- */
- public static function addToGroup($uid, $gid) {
- $group = self::getManager()->get($gid);
- $user = self::getUserManager()->get($uid);
- if ($group and $user) {
- $group->addUser($user);
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Removes a user from a group
- * @param string $uid Name of the user to remove from group
- * @param string $gid Name of the group from which remove the user
- * @return bool
- *
- * removes the user from a group.
- */
- public static function removeFromGroup($uid, $gid) {
- $group = self::getManager()->get($gid);
- $user = self::getUserManager()->get($uid);
- if ($group and $user) {
- OC_Hook::emit("OC_Group", "pre_removeFromGroup", array("run" => true, "uid" => $uid, "gid" => $gid));
- $group->removeUser($user);
- OC_Hook::emit("OC_User", "post_removeFromGroup", array("uid" => $uid, "gid" => $gid));
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Get all groups a user belongs to
- * @param string $uid Name of the user
- * @return array an array of group names
- *
- * This function fetches all groups a user belongs to. It does not check
- * if the user exists at all.
- * @deprecated Use \OC::$server->getGroupManager->getUserGroupIds($user)
- */
- public static function getUserGroups($uid) {
- $user = self::getUserManager()->get($uid);
- if ($user) {
- return self::getManager()->getUserGroupIds($user);
- } else {
- return array();
- }
- }
-
- /**
- * get a list of all groups
- * @param string $search
- * @param int|null $limit
- * @param int|null $offset
- * @return array an array of group names
- *
- * Returns a list with all groups
- */
- public static function getGroups($search = '', $limit = null, $offset = null) {
- $groups = self::getManager()->search($search, $limit, $offset);
- $groupIds = array();
- foreach ($groups as $group) {
- $groupIds[] = $group->getGID();
- }
- return $groupIds;
- }
-
- /**
- * check if a group exists
- *
- * @param string $gid
- * @return bool
- * @deprecated Use \OC::$server->getGroupManager->groupExists($gid)
- */
- public static function groupExists($gid) {
- return self::getManager()->groupExists($gid);
- }
-
- /**
- * get a list of all users in a group
- * @param string $gid
- * @param string $search
- * @param int $limit
- * @param int $offset
- * @return array an array of user ids
- */
- public static function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
- $group = self::getManager()->get($gid);
- if ($group) {
- $users = $group->searchUsers($search, $limit, $offset);
- $userIds = array();
- foreach ($users as $user) {
- $userIds[] = $user->getUID();
- }
- return $userIds;
- } else {
- return array();
- }
- }
-
- /**
- * get a list of all users in several groups
- * @param string[] $gids
- * @param string $search
- * @param int $limit
- * @param int $offset
- * @return array an array of user ids
- */
- public static function usersInGroups($gids, $search = '', $limit = -1, $offset = 0) {
- $users = array();
- foreach ($gids as $gid) {
- // TODO Need to apply limits to groups as total
- $users = array_merge(array_diff(self::usersInGroup($gid, $search, $limit, $offset), $users), $users);
- }
- return $users;
- }
-
- /**
- * get a list of all display names in a group
- * @param string $gid
- * @param string $search
- * @param int $limit
- * @param int $offset
- * @return array an array of display names (value) and user ids(key)
- * @deprecated Use \OC::$server->getGroupManager->displayNamesInGroup($gid, $search, $limit, $offset)
- */
- public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
- return self::getManager()->displayNamesInGroup($gid, $search, $limit, $offset);
- }
-
- /**
- * get a list of all display names in several groups
- * @param array $gids
- * @param string $search
- * @param int $limit
- * @param int $offset
- * @return array an array of display names (Key) user ids (value)
- */
- public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) {
- $displayNames = array();
- foreach ($gids as $gid) {
- // TODO Need to apply limits to groups as total
- $diff = array_diff(
- self::displayNamesInGroup($gid, $search, $limit, $offset),
- $displayNames
- );
- if ($diff) {
- // A fix for LDAP users. array_merge loses keys...
- $displayNames = $diff + $displayNames;
- }
- }
- return $displayNames;
- }
-}
diff --git a/lib/private/legacy/user.php b/lib/private/legacy/user.php
index 661242a659a..621ea3535b1 100644
--- a/lib/private/legacy/user.php
+++ b/lib/private/legacy/user.php
@@ -333,7 +333,9 @@ class OC_User {
* @return bool
*/
public static function isAdminUser($uid) {
- if (OC_Group::inGroup($uid, 'admin') && self::$incognitoMode === false) {
+ $group = \OC::$server->getGroupManager()->get('admin');
+ $user = \OC::$server->getUserManager()->get($uid);
+ if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
return true;
}
return false;