owncloud/core — pull request #9225 by voxsim (2014-06-26 10:51:08+00:00)
Title: fix in displayNamesInGroup

When in displayNamesInGroup is specified a limit N, we did complex search only in the first N users.

For example:
- user_backend with users (A, B, C, D, E) with the same GROUP
- we call displayNamesInGroup($gid=GROUP, $search='E', $limit=4, $offset=0), where:
$group->searchUsers('', $limit, $offset); retrieves (A, B, C, D) as result1
$filteredUsers = $this->userManager->search($search); retrieves (E) as result2
In conclusion, $matchingUsers is empty because we loop in result1 and we search if one element in result1 is present in result2, but in this example we don't have any of it.

We found it because this function is called from core/ajax/share.php when a USER A try to share something with USER B and displayNamesInGroup is called with limit 15, but in our backend we have like 32 users.

Finally, we don't understand why the function is so complicated, because, for me, it should be done in this way:

public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$group = $this->get($gid);
if(is_null($group)) {
return array();
}
// only user backends have the capability to do a complex search for users
$search = trim($search);
if(!empty($search)) {
//TODO: for OC 7 earliest: user backend should get a method to check selected users against a pattern
$filteredUsers = $this->userManager->search($search);
$testUsers = true;
} else {
$filteredUsers = array();
$testUsers = false;
}

return $filteredUsers;
}

thanks,
Simon