return ($result === 'yes');
}
+ /**
+ * @inheritdoc
+ */
public function getAccessList($nodes, $currentAccess) {
$ids = [];
foreach ($nodes as $node) {
));
$cursor = $qb->execute();
+ if ($currentAccess === false) {
+ $remote = $cursor->fetch() !== false;
+ $cursor->closeCursor();
+
+ return ['remote' => $remote];
+ }
+
$remote = [];
while ($row = $cursor->fetch()) {
$remote[$row['share_with']] = [
->method('sendRemoteShare')
->willReturn(true);
+ $result = $this->provider->getAccessList([$file1], true);
+ $this->assertEquals(['remote' => []], $result);
+
+ $result = $this->provider->getAccessList([$file1], false);
+ $this->assertEquals(['remote' => false], $result);
+
$share1 = $this->shareManager->newShare();
$share1->setSharedWith('user@server.com')
->setSharedBy($u1->getUID())
$this->provider->create($share2);
$result = $this->provider->getAccessList([$file1], true);
-
$this->assertEquals(['remote' => [
'user@server.com' => [
'token' => 'token1',
'node_id' => $file1->getId(),
],
]], $result);
+
+ $result = $this->provider->getAccessList([$file1], false);
+ $this->assertEquals(['remote' => true], $result);
+
$u1->delete();
}
}
return $shares;
}
+ /**
+ * @inheritdoc
+ */
public function getAccessList($nodes, $currentAccess) {
$ids = [];
foreach ($nodes as $node) {
$folder = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
+ $accessList = $provider->getAccessList([$folder], true);
+ $this->assertArrayHasKey('mail', $accessList);
+ $this->assertFalse($accessList['mail']);
+ $accessList = $provider->getAccessList([$folder], false);
+ $this->assertArrayHasKey('mail', $accessList);
+ $this->assertFalse($accessList['mail']);
+
$share1 = $this->shareManager->newShare();
$share1->setSharedWith('user@server.com')
->setSharedBy($u1->getUID())
$this->cache[$parent] = $resultForParents;
}
$userIds = array_merge($userIds, $resultForParents['users']);
- $public = $resultForParents['public'] || !empty($resultForParents['remote']);
+ $public = $resultForParents['public'] || $resultForParents['remote'];
// Find out who, if anyone, is sharing the file
if ($file !== null) {
$resultForFile = $this->shareManager->getAccessList($file, false);
$userIds = array_merge($userIds, $resultForFile['users']);
- $public = $resultForFile['public'] || !empty($resultForFile['remote']) || $public;
+ $public = $resultForFile['public'] || $resultForFile['remote'] || $public;
}
// check if it is a group mount
}
$cursor->closeCursor();
- $users = array_map([$this, 'filterSharesOfUser'], $users);
if ($currentAccess === true) {
+ $users = array_map([$this, 'filterSharesOfUser'], $users);
$users = array_filter($users);
+ } else {
+ $users = array_keys($users);
}
return ['users' => $users, 'public' => $link];
*
* Consider:
* -root
- * |-folder1
- * |-folder2
- * |-fileA
+ * |-folder1 (23)
+ * |-folder2 (32)
+ * |-fileA (42)
*
- * fileA is shared with user1
+ * fileA is shared with user1 and user1@server1
* folder2 is shared with group2 (user4 is a member of group2)
- * folder1 is shared with user2
+ * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2
*
- * Then the access list will to '/folder1/folder2/fileA' is:
+ * Then the access list to '/folder1/folder2/fileA' with $currentAccess is:
* [
- * users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]],
- * remote => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]],
+ * users => [
+ * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'],
+ * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'],
+ * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'],
+ * ],
+ * remote => [
+ * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'],
+ * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'],
+ * ],
+ * public => bool
+ * mail => bool
+ * ]
+ *
+ * The access list to '/folder1/folder2/fileA' **without** $currentAccess is:
+ * [
+ * users => ['user1', 'user2', 'user4'],
+ * remote => bool,
* public => bool
* mail => bool
* ]
public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) {
$owner = $path->getOwner()->getUID();
- $al = ['users' => [], 'remote' => [], 'public' => false];
+ if ($currentAccess) {
+ $al = ['users' => [], 'remote' => [], 'public' => false];
+ } else {
+ $al = ['users' => [], 'remote' => false, 'public' => false];
+ }
if (!$this->userManager->userExists($owner)) {
return $al;
}
*
* Consider:
* -root
- * |-folder1
- * |-folder2
- * |-fileA
+ * |-folder1 (23)
+ * |-folder2 (32)
+ * |-fileA (42)
*
- * fileA is shared with user1
+ * fileA is shared with user1 and user1@server1
* folder2 is shared with group2 (user4 is a member of group2)
- * folder1 is shared with user2
+ * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2
*
- * Then the access list will to '/folder1/folder2/fileA' is:
+ * Then the access list to '/folder1/folder2/fileA' with $currentAccess is:
* [
- * users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]],
- * remote => ['user1' => ['node_id' => 42, 'token' => 'ShareToken'], 'user2' => [...]],
+ * users => [
+ * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'],
+ * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'],
+ * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'],
+ * ],
+ * remote => [
+ * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'],
+ * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'],
+ * ],
+ * public => bool
+ * mail => bool
+ * ]
+ *
+ * The access list to '/folder1/folder2/fileA' **without** $currentAccess is:
+ * [
+ * users => ['user1', 'user2', 'user4'],
+ * remote => bool,
* public => bool
* mail => bool
* ]
/**
* Get the access list to the array of provided nodes.
- * Return will look like:
- *
- * [
- * users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]],
- * remote => ['user1' => ['node_id' => 42, 'token' => 'ShareToken'], 'user2' => [...]],
- * mail => bool
- * public => bool
- * ]
+ *
+ * @see IManager::getAccessList() for sample docs
*
* @param Node[] $nodes The list of nodes to get access for
* @param bool $currentAccess If current access is required (like for removed shares that might get revived later)
$folder2 = $folder1->newFolder('baz');
$file1 = $folder2->newFile('bar');
+ $result = $provider->getAccessList([$folder1, $folder2, $file1], false);
+ $this->assertCount(0, $result['users']);
+ $this->assertFalse($result['public']);
+
$shareManager = \OC::$server->getShareManager();
$share1 = $shareManager->newShare();
$share1->setNode($folder1)
$result = $provider->getAccessList([$folder1, $folder2, $file1], false);
$this->assertCount(4, $result['users']);
- $this->assertArrayHasKey('testShare2', $result['users']);
- $this->assertArrayHasKey('testShare3', $result['users']);
- $this->assertArrayHasKey('testShare4', $result['users']);
- $this->assertArrayHasKey('testShare5', $result['users']);
+ $this->assertContains('testShare2', $result['users']);
+ $this->assertContains('testShare3', $result['users']);
+ $this->assertContains('testShare4', $result['users']);
+ $this->assertContains('testShare5', $result['users']);
$this->assertTrue($result['public']);
$provider->delete($share1);
$folder2 = $folder1->newFolder('baz');
$file1 = $folder2->newFile('bar');
+ $result = $provider->getAccessList([$folder1, $folder2, $file1], false);
+ $this->assertCount(0, $result['users']);
+ $this->assertFalse($result['public']);
+
$shareManager = \OC::$server->getShareManager();
$share1 = $shareManager->newShare();
$share1->setNode($folder1)