]> source.dussan.org Git - nextcloud-server.git/commitdiff
Only return the exact match, when it's allowed
authorJoas Schilling <nickvergessen@owncloud.com>
Wed, 2 Dec 2015 15:01:01 +0000 (16:01 +0100)
committerJoas Schilling <nickvergessen@owncloud.com>
Wed, 2 Dec 2015 15:01:01 +0000 (16:01 +0100)
apps/files_sharing/api/sharees.php
apps/files_sharing/tests/api/shareestest.php

index 21f68d9b253be1caad7002879b4e7354ffc10194..24b51d7afe494bd2c7917bbede3f96edc9b76789 100644 (file)
@@ -120,6 +120,7 @@ class Sharees {
        protected function getUsers($search) {
                $this->result['users'] = $this->result['exact']['users'] = $users = [];
 
+               $userGroups = [];
                if ($this->shareWithGroupOnly) {
                        // Search in all the groups this user is part of
                        $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
@@ -171,13 +172,23 @@ class Sharees {
                        // user id and if so, we add that to the exact match list
                        $user = $this->userManager->get($search);
                        if ($user instanceof IUser) {
-                               array_push($this->result['exact']['users'], [
-                                       'label' => $user->getDisplayName(),
-                                       'value' => [
-                                               'shareType' => Share::SHARE_TYPE_USER,
-                                               'shareWith' => $user->getUID(),
-                                       ],
-                               ]);
+                               $addUser = true;
+
+                               if ($this->shareWithGroupOnly) {
+                                       // Only add, if we have a common group
+                                       $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user));
+                                       $addUser = !empty($commonGroups);
+                               }
+
+                               if ($addUser) {
+                                       array_push($this->result['exact']['users'], [
+                                               'label' => $user->getDisplayName(),
+                                               'value' => [
+                                                       'shareType' => Share::SHARE_TYPE_USER,
+                                                       'shareWith' => $user->getUID(),
+                                               ],
+                                       ]);
+                               }
                        }
                }
 
index 7db6580813f7a1e1cf2355672c0f2f8fca69cdbe..a3e3a6dee6df5d0f4791635338557eeb31c555fd 100644 (file)
@@ -136,12 +136,20 @@ class ShareesTest extends TestCase {
                        ],
                        [
                                'test', true, true, [], [],
+                               [], [], true, $this->getUserMock('test', 'Test')
+                       ],
+                       [
+                               'test', true, false, [], [],
+                               [], [], true, $this->getUserMock('test', 'Test')
+                       ],
+                       [
+                               'test', true, true, ['test-group'], [['test-group', 'test', 2, 0, []]],
                                [
                                        ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
                                ], [], true, $this->getUserMock('test', 'Test')
                        ],
                        [
-                               'test', true, false, [], [],
+                               'test', true, false, ['test-group'], [['test-group', 'test', 2, 0, []]],
                                [
                                        ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
                                ], [], true, $this->getUserMock('test', 'Test')
@@ -390,10 +398,20 @@ class ShareesTest extends TestCase {
                                ->with($searchTerm, $this->invokePrivate($this->sharees, 'limit'), $this->invokePrivate($this->sharees, 'offset'))
                                ->willReturn($userResponse);
                } else {
-                       $this->groupManager->expects($this->once())
-                               ->method('getUserGroupIds')
-                               ->with($user)
-                               ->willReturn($groupResponse);
+                       if ($singleUser !== false) {
+                               $this->groupManager->expects($this->exactly(2))
+                                       ->method('getUserGroupIds')
+                                       ->withConsecutive(
+                                               $user,
+                                               $singleUser
+                                       )
+                                       ->willReturn($groupResponse);
+                       } else {
+                               $this->groupManager->expects($this->once())
+                                       ->method('getUserGroupIds')
+                                       ->with($user)
+                                       ->willReturn($groupResponse);
+                       }
 
                        $this->groupManager->expects($this->exactly(sizeof($groupResponse)))
                                ->method('displayNamesInGroup')