Merge pull request #20900 from owncloud/share-group-only-with-exact-match
Only return the exact match, when it's allowed
This commit is contained in:
commit
6b4f48e0f3
|
@ -120,6 +120,7 @@ class Sharees {
|
||||||
protected function getUsers($search) {
|
protected function getUsers($search) {
|
||||||
$this->result['users'] = $this->result['exact']['users'] = $users = [];
|
$this->result['users'] = $this->result['exact']['users'] = $users = [];
|
||||||
|
|
||||||
|
$userGroups = [];
|
||||||
if ($this->shareWithGroupOnly) {
|
if ($this->shareWithGroupOnly) {
|
||||||
// Search in all the groups this user is part of
|
// Search in all the groups this user is part of
|
||||||
$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
|
$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 id and if so, we add that to the exact match list
|
||||||
$user = $this->userManager->get($search);
|
$user = $this->userManager->get($search);
|
||||||
if ($user instanceof IUser) {
|
if ($user instanceof IUser) {
|
||||||
array_push($this->result['exact']['users'], [
|
$addUser = true;
|
||||||
'label' => $user->getDisplayName(),
|
|
||||||
'value' => [
|
if ($this->shareWithGroupOnly) {
|
||||||
'shareType' => Share::SHARE_TYPE_USER,
|
// Only add, if we have a common group
|
||||||
'shareWith' => $user->getUID(),
|
$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(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,12 +136,20 @@ class ShareesTest extends TestCase {
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'test', true, true, [], [],
|
'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']],
|
['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
|
||||||
], [], true, $this->getUserMock('test', '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']],
|
['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
|
||||||
], [], true, $this->getUserMock('test', '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'))
|
->with($searchTerm, $this->invokePrivate($this->sharees, 'limit'), $this->invokePrivate($this->sharees, 'offset'))
|
||||||
->willReturn($userResponse);
|
->willReturn($userResponse);
|
||||||
} else {
|
} else {
|
||||||
$this->groupManager->expects($this->once())
|
if ($singleUser !== false) {
|
||||||
->method('getUserGroupIds')
|
$this->groupManager->expects($this->exactly(2))
|
||||||
->with($user)
|
->method('getUserGroupIds')
|
||||||
->willReturn($groupResponse);
|
->withConsecutive(
|
||||||
|
$user,
|
||||||
|
$singleUser
|
||||||
|
)
|
||||||
|
->willReturn($groupResponse);
|
||||||
|
} else {
|
||||||
|
$this->groupManager->expects($this->once())
|
||||||
|
->method('getUserGroupIds')
|
||||||
|
->with($user)
|
||||||
|
->willReturn($groupResponse);
|
||||||
|
}
|
||||||
|
|
||||||
$this->groupManager->expects($this->exactly(sizeof($groupResponse)))
|
$this->groupManager->expects($this->exactly(sizeof($groupResponse)))
|
||||||
->method('displayNamesInGroup')
|
->method('displayNamesInGroup')
|
||||||
|
|
Loading…
Reference in New Issue