From 83b88c9a264a46f393df95e6c57793f0300495da Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 17 Aug 2015 12:13:49 +0200 Subject: [PATCH] Do not return the current user himself --- apps/files_sharing/api/sharees.php | 5 +++ apps/files_sharing/tests/api/sharees.php | 44 +++++++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/api/sharees.php b/apps/files_sharing/api/sharees.php index 3e802b3028a..f12677265bf 100644 --- a/apps/files_sharing/api/sharees.php +++ b/apps/files_sharing/api/sharees.php @@ -116,6 +116,11 @@ class Sharees { foreach ($users as $uid => $displayName) { + if ($uid === $this->userSession->getUser()->getUID()) { + // Skip the current user + continue; + } + $sharees[] = [ 'label' => $displayName, 'value' => [ diff --git a/apps/files_sharing/tests/api/sharees.php b/apps/files_sharing/tests/api/sharees.php index 24a659eb063..9b7a21b0635 100644 --- a/apps/files_sharing/tests/api/sharees.php +++ b/apps/files_sharing/tests/api/sharees.php @@ -127,6 +127,20 @@ class ShareesTest extends TestCase { ['label' => 'Test Two', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], ] ], + [ + 'test', + false, + [], + [ + $this->getUserMock('test1', 'Test One'), + $this->getUserMock('test2', 'Test Two'), + $this->getUserMock('admin', 'Should be removed'), + ], + [ + ['label' => 'Test One', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], + ['label' => 'Test Two', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], + ] + ], [ 'test', true, @@ -175,6 +189,26 @@ class ShareesTest extends TestCase { ['label' => 'Test Two', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], ] ], + [ + 'test', + true, + ['abc', 'xyz'], + [ + ['abc', 'test', -1, 0, [ + 'test1' => 'Test One', + ]], + ['xyz', 'test', -1, 0, [ + 'test2' => 'Test Two', + ]], + ['admin', 'Should be removed', -1, 0, [ + 'test2' => 'Test Two', + ]], + ], + [ + ['label' => 'Test One', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], + ['label' => 'Test Two', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], + ] + ], ]; } @@ -188,17 +222,17 @@ class ShareesTest extends TestCase { * @param array $expected */ public function testGetUsers($searchTerm, $shareWithGroupOnly, $groupResponse, $userResponse, $expected) { + $user = $this->getUserMock('admin', 'Administrator'); + $this->session->expects($this->any()) + ->method('getUser') + ->willReturn($user); + if (!$shareWithGroupOnly) { $this->userManager->expects($this->once()) ->method('searchDisplayName') ->with($searchTerm) ->willReturn($userResponse); } else { - $user = $this->getUserMock('admin', 'Administrator'); - $this->session->expects($this->any()) - ->method('getUser') - ->willReturn($user); - $this->groupManager->expects($this->once()) ->method('getUserGroupIds') ->with($user)