diff options
author | Joas Schilling <coding@schilljs.com> | 2017-03-27 16:06:31 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-04-13 12:58:50 +0200 |
commit | 91e650791de6dbb320e5163f626c754d42e0bc35 (patch) | |
tree | b6860a90d3b22bfd715cd7ba444673ae72bebfc0 /lib/private/Share20/DefaultShareProvider.php | |
parent | 0c2dc3bc8cdca46afc2bc08da4a985610093f2af (diff) | |
download | nextcloud-server-91e650791de6dbb320e5163f626c754d42e0bc35.tar.gz nextcloud-server-91e650791de6dbb320e5163f626c754d42e0bc35.zip |
Return the paths for the users without setting them all up
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Share20/DefaultShareProvider.php')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index b8f46a1f4d6..49a756f2a10 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -1092,7 +1092,7 @@ class DefaultShareProvider implements IShareProvider { $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); } - $qb->select('share_type', 'share_with') + $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') ->from('share') ->where( $or @@ -1110,7 +1110,8 @@ class DefaultShareProvider implements IShareProvider { $type = (int)$row['share_type']; if ($type === \OCP\Share::SHARE_TYPE_USER) { $uid = $row['share_with']; - $users[$uid] = isset($users[$uid]) ? $users[$uid] + 1 : 1; + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; + $users[$uid][$row['id']] = $row; } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { $gid = $row['share_with']; $group = $this->groupManager->get($gid); @@ -1121,23 +1122,60 @@ class DefaultShareProvider implements IShareProvider { $userList = $group->getUsers(); foreach ($userList as $user) { - $users[$user->getUID()] = isset($users[$user->getUID()]) ? $users[$user->getUID()] + 1 : 1; + $uid = $user->getUID(); + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; + $users[$uid][$row['id']] = $row; } } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { $link = true; } else if ($type === self::SHARE_TYPE_USERGROUP) { if ($currentAccess === true) { $uid = $row['share_with']; - $users[$uid] = isset($users[$uid]) ? $users[$uid] - 1 : -1; + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; + $users[$uid][$row['id']] = $row; } } } $cursor->closeCursor(); - $users = array_filter($users, function($count) { - return $count > 0; - }); + $users = array_map([$this, 'filterSharesOfUser'], $users); - return ['users' => array_keys($users), 'public' => $link]; + return ['users' => $users, 'public' => $link]; + } + + /** + * For each user the path with the fewest slashes is returned + * @param array $shares + * @return array + */ + protected function filterSharesOfUser(array $shares) { + // Group shares when the user has a share exception + foreach ($shares as $id => $share) { + $type = (int) $share['share_type']; + $permissions = (int) $share['permissions']; + + if ($type === self::SHARE_TYPE_USERGROUP) { + unset($shares[$share['parent']]); + + if ($permissions === 0) { + unset($shares[$id]); + } + } + } + + $best = []; + $bestDepth = 0; + foreach ($shares as $id => $share) { + $depth = substr_count($share['file_target'], '/'); + if (empty($best) || $depth < $bestDepth) { + $bestDepth = $depth; + $best = [ + 'node_id' => $share['file_source'], + 'node_path' => $share['file_target'], + ]; + } + } + + return $best; } } |