Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 22 additions & 34 deletions lib/private/Collaboration/Collaborators/UserPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function __construct(IConfig $config, IUserManager $userManager, IGroupMa
public function search($search, $limit, $offset, ISearchResult $searchResult) {
$result = ['wide' => [], 'exact' => []];
$users = [];
$autoCompleteUsers = [];
$hasMoreResults = false;

$userGroups = [];
Expand All @@ -91,28 +90,6 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
foreach ($usersTmp as $user) {
if ($user->isEnabled()) { // Don't keep deactivated users
$users[$user->getUID()] = $user;

$addToWideResults = false;
if ($this->shareeEnumeration && !$this->shareeEnumerationInGroupOnly) {
$addToWideResults = true;
}

if ($this->shareeEnumerationInGroupOnly) {
$commonGroups = array_intersect($currentUserGroups, $this->groupManager->getUserGroupIds($user));
if (!empty($commonGroups)) {
$addToWideResults = true;
}
}

if ($addToWideResults) {
$autoCompleteUsers[] = [
'label' => $user->getDisplayName(),
'value' => [
'shareType' => IShare::TYPE_USER,
'shareWith' => (string)$user->getUID(),
],
];
}
}
}
}
Expand Down Expand Up @@ -145,13 +122,27 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
],
];
} else {
$result['wide'][] = [
'label' => $userDisplayName,
'value' => [
'shareType' => Share::SHARE_TYPE_USER,
'shareWith' => $uid,
],
];
$addToWideResults = false;
if ($this->shareeEnumeration && !$this->shareeEnumerationInGroupOnly) {
$addToWideResults = true;
}

if ($this->shareeEnumerationInGroupOnly) {
$commonGroups = array_intersect($currentUserGroups, $this->groupManager->getUserGroupIds($user));
if (!empty($commonGroups)) {
$addToWideResults = true;
}
}

if ($addToWideResults) {
$result['wide'][] = [
'label' => $userDisplayName,
'value' => [
'shareType' => IShare::TYPE_USER,
'shareWith' => $uid,
],
];
}
}
}

Expand Down Expand Up @@ -183,10 +174,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
}
}

// overwrite wide matches if they are limited
if (!$this->shareeEnumeration || $this->shareeEnumerationInGroupOnly) {
$result['wide'] = $autoCompleteUsers;
}


$type = new SearchResultType('users');
$searchResult->addResultSet($type, $result['wide'], $result['exact']);
Expand Down
41 changes: 31 additions & 10 deletions tests/lib/Collaboration/Collaborators/UserPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,16 @@ public function dataSearchEnumeration() {
['uid' => 'test1', 'groups' => ['groupA']],
['uid' => 'test2', 'groups' => ['groupB']],
],
['test1'],
['exact' => [], 'wide' => ['test1']],
],
[
'test1',
['groupA'],
[
['uid' => 'test1', 'groups' => ['groupA']],
['uid' => 'test2', 'groups' => ['groupB']],
],
['exact' => ['test1'], 'wide' => []],
],
[
'test',
Expand All @@ -531,7 +540,7 @@ public function dataSearchEnumeration() {
['uid' => 'test1', 'groups' => ['groupA']],
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['test1', 'test2'],
['exact' => [], 'wide' => ['test1', 'test2']],
],
[
'test',
Expand All @@ -540,7 +549,7 @@ public function dataSearchEnumeration() {
['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['test1', 'test2'],
['exact' => [], 'wide' => ['test1', 'test2']],
],
[
'test',
Expand All @@ -549,7 +558,7 @@ public function dataSearchEnumeration() {
['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['test1', 'test2'],
['exact' => [], 'wide' => ['test1', 'test2']],
],
[
'test',
Expand All @@ -558,7 +567,7 @@ public function dataSearchEnumeration() {
['uid' => 'test1', 'groups' => ['groupA']],
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
[],
['exact' => [], 'wide' => []],
],
[
'test',
Expand All @@ -567,7 +576,16 @@ public function dataSearchEnumeration() {
['uid' => 'test1', 'groups' => []],
['uid' => 'test2', 'groups' => []],
],
[],
['exact' => [], 'wide' => []],
],
[
'test',
['groupC', 'groupB'],
[
['uid' => 'test1', 'groups' => []],
['uid' => 'test2', 'groups' => []],
],
['exact' => [], 'wide' => []],
],
];
}
Expand All @@ -582,9 +600,12 @@ public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers,
return $this->getUserMock($user['uid'], $user['uid']);
}, $matchingUsers);

$mappedResult = array_map(function ($user) {
$mappedResultExact = array_map(function ($user) {
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user]];
}, $result['exact']);
$mappedResultWide = array_map(function ($user) {
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user]];
}, $result);
}, $result['wide']);

$this->userManager->expects($this->once())
->method('searchDisplayName')
Expand Down Expand Up @@ -615,7 +636,7 @@ function ($e) use ($user) {
$this->plugin->search($search, $this->limit, $this->offset, $this->searchResult);
$result = $this->searchResult->asArray();

$this->assertEquals([], $result['exact']['users']);
$this->assertEquals($mappedResult, $result['users']);
$this->assertEquals($mappedResultExact, $result['exact']['users']);
$this->assertEquals($mappedResultWide, $result['users']);
}
}