Skip to content

Commit

Permalink
Do not return the current user himself
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed Aug 17, 2015
1 parent 3cf9655 commit abc85fd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
5 changes: 5 additions & 0 deletions apps/files_sharing/api/sharees.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ protected function getUsers($search, $shareWithGroupOnly) {


foreach ($users as $uid => $displayName) {
if ($uid === $this->userSession->getUser()->getUID()) {
// Skip the current user
continue;
}

$sharees[] = [
'label' => $displayName,
'value' => [
Expand Down
44 changes: 39 additions & 5 deletions apps/files_sharing/tests/api/sharees.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ public function dataGetUsers() {
['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,
Expand Down Expand Up @@ -175,6 +189,26 @@ public function dataGetUsers() {
['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']],
]
],
];
}

Expand All @@ -188,17 +222,17 @@ public function dataGetUsers() {
* @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)
Expand Down

0 comments on commit abc85fd

Please sign in to comment.