summaryrefslogtreecommitdiffstats
path: root/lib/private/Share20
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Share20')
-rw-r--r--lib/private/Share20/DefaultShareProvider.php76
-rw-r--r--lib/private/Share20/Manager.php57
2 files changed, 92 insertions, 41 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index feae147066d..93e8cfc9d77 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -362,7 +362,7 @@ class DefaultShareProvider implements IShareProvider {
if ($data === false) {
$qb = $this->dbConn->getQueryBuilder();
- $type = $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder';
+ $type = $share->getNodeType();
//Insert new share
$qb->insert('share')
@@ -373,8 +373,8 @@ class DefaultShareProvider implements IShareProvider {
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
'parent' => $qb->createNamedParameter($share->getId()),
'item_type' => $qb->createNamedParameter($type),
- 'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
- 'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
+ 'item_source' => $qb->createNamedParameter($share->getNodeId()),
+ 'file_source' => $qb->createNamedParameter($share->getNodeId()),
'file_target' => $qb->createNamedParameter($share->getTarget()),
'permissions' => $qb->createNamedParameter(0),
'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
@@ -1070,4 +1070,74 @@ class DefaultShareProvider implements IShareProvider {
}
}
}
+
+ /**
+ * @inheritdoc
+ */
+ public function getAccessList($nodes, $currentAccess) {
+ $ids = [];
+ foreach ($nodes as $node) {
+ $ids[] = $node->getId();
+ }
+
+ $qb = $this->dbConn->getQueryBuilder();
+
+ $or = $qb->expr()->orX(
+ $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
+ $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
+ $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
+ );
+
+ if ($currentAccess) {
+ $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)));
+ }
+
+ $qb->select('share_type', 'share_with')
+ ->from('share')
+ ->where(
+ $or
+ )
+ ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
+ ->andWhere($qb->expr()->orX(
+ $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
+ $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
+ ));
+ $cursor = $qb->execute();
+
+ $users = [];
+ $link = false;
+ while($row = $cursor->fetch()) {
+ $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;
+ } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) {
+ $gid = $row['share_with'];
+ $group = $this->groupManager->get($gid);
+
+ if ($gid === null) {
+ continue;
+ }
+
+ $userList = $group->getUsers();
+ foreach ($userList as $user) {
+ $users[$user->getUID()] = isset($users[$user->getUID()]) ? $users[$user->getUID()] + 1 : 1;
+ }
+ } 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;
+ }
+ }
+ }
+ $cursor->closeCursor();
+
+ $users = array_filter($users, function($count) {
+ return $count > 0;
+ });
+
+ return ['users' => array_keys($users), 'public' => $link, 'remote' => false];
+ }
}
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index d93883e95d4..096d05fbec3 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -1200,69 +1200,50 @@ class Manager implements IManager {
*
* @param \OCP\Files\Node $path
* @param bool $recursive Should we check all parent folders as well
+ * @param bool $currentAccess Should the user have currently access to the file
* @return array
*/
- public function getAccessList(\OCP\Files\Node $path, $recursive = true) {
+ public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) {
$owner = $path->getOwner()->getUID();
+ $al = ['users' => [], 'public' => false, 'remote' => false];
+ if (!$this->userManager->userExists($owner)) {
+ return $al;
+ }
+
//Get node for the owner
$userFolder = $this->rootFolder->getUserFolder($owner);
-
if (!$userFolder->isSubNode($path)) {
$path = $userFolder->getById($path->getId())[0];
}
$providers = $this->factory->getAllProviders();
- /** @var IShare[] $shares */
- $shares = [];
+ /** @var Node[] $nodes */
+ $nodes = [];
+
+ $al['users'][] = $owner;
// Collect all the shares
while ($path->getPath() !== $userFolder->getPath()) {
- foreach ($providers as $provider) {
- $shares = array_merge($shares, $provider->getSharesByPath($path));
- }
+ $nodes[] = $path;
if (!$recursive) {
break;
}
$path = $path->getParent();
}
- $users = [$owner => 'null'];
- $public = false;
- $remote = false;
- foreach ($shares as $share) {
- if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
- $uid = $share->getSharedWith();
-
- // Skip if user does not exist
- if (!$this->userManager->userExists($uid)) {
- continue;
- }
-
- $users[$uid] = null;
- } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
- $group = $this->groupManager->get($share->getSharedWith());
+ foreach ($providers as $provider) {
+ $tmp = $provider->getAccessList($nodes, $currentAccess);
- // If group does not exist skip
- if ($group === null) {
- continue;
- }
-
- $groupUsers = $group->getUsers();
- foreach ($groupUsers as $groupUser) {
- $users[$groupUser->getUID()] = null;
- }
- } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
- $public = true;
- } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
- $remote = true;
- }
+ $al['users'] = array_merge($al['users'], $tmp['users']);
+ $al['public'] = $al['public'] || $tmp['public'];
+ $al['remote'] = $al['remote'] || $tmp['remote'];
}
- $users = array_keys($users);
+ $al['users'] = array_unique($al['users']);
- return ['users' => $users, 'public' => $public, 'remote' => $remote];
+ return $al;
}
/**