]> source.dussan.org Git - nextcloud-server.git/commitdiff
Adjust docs and make !$currentAccess simpler
authorJoas Schilling <coding@schilljs.com>
Tue, 11 Apr 2017 10:40:36 +0000 (12:40 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 13 Apr 2017 10:58:52 +0000 (12:58 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/federatedfilesharing/lib/FederatedShareProvider.php
apps/federatedfilesharing/tests/FederatedShareProviderTest.php
apps/sharebymail/lib/ShareByMailProvider.php
apps/sharebymail/tests/ShareByMailProviderTest.php
lib/private/Encryption/File.php
lib/private/Share20/DefaultShareProvider.php
lib/private/Share20/Manager.php
lib/public/Share/IManager.php
lib/public/Share/IShareProvider.php
tests/lib/Share20/DefaultShareProviderTest.php

index 617db4a45ac5c73fc307e7119a6cd4fb6c3c7d8c..34e02391e05145d4ae3f708e07a0f332c3e9429b 100644 (file)
@@ -976,6 +976,9 @@ class FederatedShareProvider implements IShareProvider {
                return ($result === 'yes');
        }
 
+       /**
+        * @inheritdoc
+        */
        public function getAccessList($nodes, $currentAccess) {
                $ids = [];
                foreach ($nodes as $node) {
@@ -993,6 +996,13 @@ class FederatedShareProvider implements IShareProvider {
                        ));
                $cursor = $qb->execute();
 
+               if ($currentAccess === false) {
+                       $remote = $cursor->fetch() !== false;
+                       $cursor->closeCursor();
+
+                       return ['remote' => $remote];
+               }
+
                $remote = [];
                while ($row = $cursor->fetch()) {
                        $remote[$row['share_with']] = [
index 788ae47fdede20bc144981d4ccb2cff12452913a..e01e02c83ba09bf61bd7dd9b540e65c13bf26e09 100644 (file)
@@ -805,6 +805,12 @@ class FederatedShareProviderTest extends \Test\TestCase {
                        ->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())
@@ -822,7 +828,6 @@ class FederatedShareProviderTest extends \Test\TestCase {
                $this->provider->create($share2);
 
                $result = $this->provider->getAccessList([$file1], true);
-
                $this->assertEquals(['remote' => [
                        'user@server.com' => [
                                'token' => 'token1',
@@ -833,6 +838,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
                                'node_id' => $file1->getId(),
                        ],
                ]], $result);
+
+               $result = $this->provider->getAccessList([$file1], false);
+               $this->assertEquals(['remote' => true], $result);
+
                $u1->delete();
        }
 }
index 14ed12749b7e99ef5c168fed37b1070bac4f51ca..0f4a8dd87bcea11432ec6249878522843cc2bb70 100644 (file)
@@ -834,6 +834,9 @@ class ShareByMailProvider implements IShareProvider {
                return $shares;
        }
 
+       /**
+        * @inheritdoc
+        */
        public function getAccessList($nodes, $currentAccess) {
                $ids = [];
                foreach ($nodes as $node) {
index 1b215016ee4bab1ace5b264d1dec76965230b579..cd0600d3ae969c4285568c571e7f206a353c3cfe 100644 (file)
@@ -675,6 +675,13 @@ class ShareByMailProviderTest extends TestCase {
 
                $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())
index f6fd3382cb5c957b59ab87c7d7afb19708420994..2bc0e014f0c971678d6ebbc7795adeaabb159009 100644 (file)
@@ -95,14 +95,14 @@ class File implements \OCP\Encryption\IFile {
                        $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
index b28dc56f8520a72ab9a3bf4a80cf812fc741df5c..ed3651df9b29071a482e8021f35997ed6a1bb6cd 100644 (file)
@@ -1136,9 +1136,11 @@ class DefaultShareProvider implements IShareProvider {
                }
                $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];
index 91fcb6af8fb0dff270c6b5c90db3089660e1def9..8b670da544b552eead54aa329708d45da8bd857a 100644 (file)
@@ -1181,18 +1181,33 @@ class Manager implements IManager {
         *
         * 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
         * ]
@@ -1207,7 +1222,11 @@ class Manager implements IManager {
        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;
                }
index 5f02e1d9804468c066d1ab3870bd42a716b3ade3..31f04803066cc2901a5b93959fde6aa8ab836d41 100644 (file)
@@ -197,18 +197,33 @@ interface IManager {
         *
         * 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
         * ]
index bac1a5d87f01927cf7700d41abdf61abc04b1e30..31808206cf6b5266138ebf83c41a3bc46a778b60 100644 (file)
@@ -193,14 +193,8 @@ interface IShareProvider {
 
        /**
         * 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)
index 6c351f1a6d95a7cada835cca291b4ecbd70fd1af..0fa8aa3d0c624301a5b5ae3bb2413c2ead0df51e 100644 (file)
@@ -2462,6 +2462,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
                $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)
@@ -2503,10 +2507,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
                $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);
@@ -2549,6 +2553,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
                $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)