Fix returned paths for remote shares

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-03-28 17:06:26 +02:00 committed by Roeland Jago Douma
parent 4bcb7d88b5
commit 3c1365c0d1
No known key found for this signature in database
GPG Key ID: F941078878347C0C
5 changed files with 13 additions and 25 deletions

View File

@ -983,7 +983,7 @@ class FederatedShareProvider implements IShareProvider {
}
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('share_with', 'token', 'file_source', 'file_target')
$qb->select('share_with', 'token', 'file_source')
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)))
->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
@ -997,7 +997,6 @@ class FederatedShareProvider implements IShareProvider {
while ($row = $cursor->fetch()) {
$remote[$row['share_with']] = [
'node_id' => $row['file_source'],
'node_path' => $row['file_target'],
'token' => $row['token'],
];
}

View File

@ -37,7 +37,7 @@ class ShareHelper implements IShareHelper {
/**
* @param Node $node
* @return array [ users => [Mapping $uid => $path], remotes => [Mapping $cloudId => $path]]
* @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]]
*/
public function getPathsForAccessList(Node $node) {
$result = [
@ -103,26 +103,10 @@ class ShareHelper implements IShareHelper {
$byId[$info['node_id']][$cloudId] = $info['token'];
}
if (isset($byId[$node->getId()])) {
foreach ($byId[$node->getId()] as $cloudId => $token) {
$results[$cloudId] = [
'node_path' => '/' . $node->getName(),
'token' => $token,
];
}
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()])) {
$path = $this->getMountedPath($item);
foreach ($byId[$item->getId()] as $uid => $token) {
$results[$uid] = [
'node_path' => $path,
@ -131,10 +115,15 @@ class ShareHelper implements IShareHelper {
}
unset($byId[$item->getId()]);
}
$path = '/' . $item->getName() . $path;
$item = $item->getParent();
}
return $results;
}
protected function getMountedPath(Node $node) {
$path = $node->getPath();
$sections = explode('/', $path, 4);
return '/' . $sections[3];
}
}

View File

@ -208,7 +208,7 @@ interface IManager {
* Then the access list will to '/folder1/folder2/fileA' is:
* [
* users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]],
* remote => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]],
* remote => ['user1' => ['node_id' => 42, 'token' => 'ShareToken'], 'user2' => [...]],
* public => bool
* mail => bool
* ]

View File

@ -34,7 +34,7 @@ interface IShareHelper {
/**
* @param Node $node
* @return array [ users => [Mapping $uid => $path], remotes => [Mapping $cloudId => $path]]
* @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]]
* @since 12
*/
public function getPathsForAccessList(Node $node);

View File

@ -197,7 +197,7 @@ interface IShareProvider {
*
* [
* users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]],
* remote => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]],
* remote => ['user1' => ['node_id' => 42, 'token' => 'ShareToken'], 'user2' => [...]],
* mail => bool
* public => bool
* ]