summaryrefslogtreecommitdiffstats
path: root/lib/private/Share
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/private/Share
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/private/Share')
-rw-r--r--lib/private/Share/Share.php98
1 files changed, 84 insertions, 14 deletions
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)) {