usersInGroup index by int for BC, searchInGroup index by uid (string).
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
* gives back the user names as they are used ownClod internally
*
* @param array $ldapUsers as returned by fetchList()
- * @return array an array with the user names to use in Nextcloud
+ * @return array<int,string> an array with the user names to use in Nextcloud
*
* gives back the user names as they are used ownClod internally
* @throws \Exception
* gives back the group names as they are used ownClod internally
*
* @param array $ldapGroups as returned by fetchList()
- * @return array an array with the group names to use in Nextcloud
+ * @return array<int,string> an array with the group names to use in Nextcloud
*
* gives back the group names as they are used ownClod internally
* @throws \Exception
/**
* @param array[] $ldapObjects as returned by fetchList()
+ * @return array<int,string>
* @throws \Exception
*/
private function ldap2NextcloudNames(array $ldapObjects, bool $isUsers): array {
}
/**
- * @return array A list of users that have the given group as gid number
+ * @return array<int,string> A list of users that have the given group as gid number
* @throws ServerNotAvailableException
*/
public function getUsersInGidNumber(
/**
* @throws ServerNotAvailableException
+ * @return array<int,string>
*/
public function getUsersInPrimaryGroup(
string $groupDN,
* @param string $search
* @param int $limit
* @param int $offset
- * @return array with user ids
+ * @return array<int,string> user ids
* @throws Exception
* @throws ServerNotAvailableException
*/
if (empty($ldap_users)) {
break;
}
- $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
+ $uid = $this->access->dn2username($ldap_users[0]['dn'][0]);
+ if (!$uid) {
+ break;
+ }
+ $groupUsers[] = $uid;
break;
default:
//we got DNs, check if we need to filter by search or we can give back all of them
/**
* get a list of all users in a group
*
- * @return string[] with user ids
+ * @return array<int,string> user ids
*/
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$this->setup();
* @param string $search
* @param int $limit
* @param int $offset
- * @return array an array of user ids
+ * @return array<int,string> an array of user ids
*/
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
return [];
* @param string $search
* @param int $limit
* @param int $offset
- * @return array<string> an array of user ids
+ * @return array<int,string> an array of user ids
*/
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0): array {
- return array_map(fn ($user) => $user->getUid(), $this->searchInGroup($gid, $search, $limit, $offset));
+ return array_values(array_map(fn ($user) => $user->getUid(), $this->searchInGroup($gid, $search, $limit, $offset)));
}
public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array {
$users = [];
foreach ($this->backends as $backend) {
if ($backend instanceof ISearchableGroupBackend) {
- $users = array_merge($users, $backend->searchInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0));
+ $users = array_merge($users, array_values($backend->searchInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0)));
} else {
$userIds = $backend->usersInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0);
$userManager = \OCP\Server::get(IUserManager::class);
* @since 26.0.0
*/
interface ISearchableGroupBackend {
-
/**
* @brief Get a list of users matching the given search parameters.
*
* want to search. This can be empty to get all the users.
* @param int $limit The limit of results
* @param int $offset The offset of the results
- * @return IUser[]
+ * @return array<string,IUser> Users indexed by uid
* @since 26.0.0
*/
public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array;
* @param string $search
* @param int $limit
* @param int $offset
- * @return array an array of user ids
+ * @return array<int,string> an array of user ids
* @since 4.5.0
* @deprecated 26.0.0 Use searchInGroup instead, for performance reasons
*/
$backend->expects($this->once())
->method('searchInGroup')
->with('testgroup', '', -1, 0)
- ->willReturn([$this->getTestUser('user2'), $this->getTestUser('user33')]);
+ ->willReturn(['user2' => $this->getTestUser('user2'), 'user33' => $this->getTestUser('user33')]);
$this->userManager->expects($this->never())->method('get');
$backend->expects($this->once())
->method('searchInGroup')
->with('testgroup', '', 1, 1)
- ->willReturn([$this->getTestUser('user33')]);
+ ->willReturn(['user33' => $this->getTestUser('user33')]);
$this->userManager->expects($this->never())->method('get');
$result = [];
foreach ($this->groups[$gid] as $user) {
if (stripos($user, $search) !== false) {
- $result[] = new DummyUser($user, '');
+ $result[$user] = new DummyUser($user, '');
}
}
return $result;