summaryrefslogtreecommitdiffstats
path: root/lib/private/Share20/ShareHelper.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-03-27 16:06:31 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2017-04-13 12:58:50 +0200
commit91e650791de6dbb320e5163f626c754d42e0bc35 (patch)
treeb6860a90d3b22bfd715cd7ba444673ae72bebfc0 /lib/private/Share20/ShareHelper.php
parent0c2dc3bc8cdca46afc2bc08da4a985610093f2af (diff)
downloadnextcloud-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/ShareHelper.php')
-rw-r--r--lib/private/Share20/ShareHelper.php118
1 files changed, 94 insertions, 24 deletions
diff --git a/lib/private/Share20/ShareHelper.php b/lib/private/Share20/ShareHelper.php
index a7d46457cd8..93b32cef3c3 100644
--- a/lib/private/Share20/ShareHelper.php
+++ b/lib/private/Share20/ShareHelper.php
@@ -22,43 +22,113 @@
*/
namespace OC\Share20;
-use OCP\Files\IRootFolder;
use OCP\Files\Node;
-use OCP\Files\NotFoundException;
+use OCP\Share\IManager;
+use OCP\Share\IShareHelper;
-class ShareHelper {
- /** @var IRootFolder */
- private $rootFolder;
+class ShareHelper implements IShareHelper {
- public function __construct(IRootFolder $rootFolder) {
- $this->rootFolder = $rootFolder;
+ /** @var IManager */
+ private $shareManager;
+
+ public function __construct(IManager $shareManager) {
+ $this->shareManager = $shareManager;
}
/**
- * If a user has access to a file
- *
* @param Node $node
- * @param array $users Array of userIds
- * @return array Mapping $uid to an array of nodes
+ * @return array [ users => [Mapping $uid => $path], remotes => [Mapping $cloudId => $path]]
*/
- public function getPathsForAccessList(Node $node, $users) {
- $result = [];
-
- foreach ($users as $user) {
- try {
- $userFolder = $this->rootFolder->getUserFolder($user);
- } catch (NotFoundException $e) {
- continue;
+ public function getPathsForAccessList(Node $node) {
+ $result = [
+ 'users' => [],
+ 'remotes' => [],
+ ];
+
+ $accessList = $this->shareManager->getAccessList($node, true, true);
+ if (!empty($accessList['users'])) {
+ $result['users'] = $this->getPathsForUsers($node, $accessList['users']);
+ }
+ if (!empty($accessList['remote'])) {
+ $result['remotes'] = $this->getPathsForRemotes($node, $accessList['remote']);
+ }
+
+ return $result;
+ }
+
+ protected function getPathsForUsers(Node $node, array $users) {
+ $byId = $results = [];
+ foreach ($users as $uid => $info) {
+ if (!isset($byId[$info['node_id']])) {
+ $byId[$info['node_id']] = [];
}
+ $byId[$info['node_id']][$uid] = $info['node_path'];
+ }
- $nodes = $userFolder->getById($node->getId());
- if ($nodes === []) {
- continue;
+ if (isset($byId[$node->getId()])) {
+ foreach ($byId[$node->getId()] as $uid => $path) {
+ $results[$uid] = $path;
}
+ unset($byId[$node->getId()]);
+ }
- $result[$user] = $nodes;
+ if (empty($byId)) {
+ return $results;
}
- return $result;
+ $item = $node;
+ $appendix = '/' . $node->getName();
+ while (!empty($byId)) {
+ $item = $item->getParent();
+
+ if (!empty($byId[$item->getId()])) {
+ foreach ($byId[$item->getId()] as $uid => $path) {
+ $results[$uid] = $path . $appendix;
+ }
+ unset($byId[$item->getId()]);
+ }
+
+ $appendix = '/' . $item->getName() . $appendix;
+ }
+
+ return $results;
+ }
+
+ protected function getPathsForRemotes(Node $node, array $remotes) {
+ $byId = $results = [];
+ foreach ($remotes as $cloudId => $info) {
+ if (!isset($byId[$info['node_id']])) {
+ $byId[$info['node_id']] = [];
+ }
+ $byId[$info['node_id']][$cloudId] = $info['node_path'];
+ }
+
+ if (isset($byId[$node->getId()])) {
+ foreach ($byId[$node->getId()] as $cloudId => $_) {
+ $results[$cloudId] = '/' . $node->getName();
+ }
+ unset($byId[$node->getId()]);
+ }
+
+ if (empty($byId)) {
+ return $results;
+ }
+
+ $item = $node;
+ $path = '/' . $node->getName();
+ while (!empty($byId)) {
+ $item = $item->getParent();
+
+ if (!empty($byId[$item->getId()])) {
+ foreach ($byId[$item->getId()] as $uid => $_) {
+ $results[$uid] = $path;
+ }
+ unset($byId[$item->getId()]);
+ }
+
+ $path = '/' . $item->getName() . $path;
+ }
+
+ return $results;
}
}