Clear up return types

usersInGroup index by int for BC, searchInGroup index by uid (string).

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/32866/head
Côme Chilliet 2023-01-02 17:10:31 +07:00
parent 6385a5af36
commit b6c17c6ce7
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
10 changed files with 21 additions and 16 deletions

@ -631,7 +631,7 @@ class Access extends LDAPUtility {
* gives back the user names as they are used ownClod internally * gives back the user names as they are used ownClod internally
* *
* @param array $ldapUsers as returned by fetchList() * @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 * gives back the user names as they are used ownClod internally
* @throws \Exception * @throws \Exception
@ -644,7 +644,7 @@ class Access extends LDAPUtility {
* gives back the group names as they are used ownClod internally * gives back the group names as they are used ownClod internally
* *
* @param array $ldapGroups as returned by fetchList() * @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 * gives back the group names as they are used ownClod internally
* @throws \Exception * @throws \Exception
@ -655,6 +655,7 @@ class Access extends LDAPUtility {
/** /**
* @param array[] $ldapObjects as returned by fetchList() * @param array[] $ldapObjects as returned by fetchList()
* @return array<int,string>
* @throws \Exception * @throws \Exception
*/ */
private function ldap2NextcloudNames(array $ldapObjects, bool $isUsers): array { private function ldap2NextcloudNames(array $ldapObjects, bool $isUsers): array {

@ -466,7 +466,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
} }
/** /**
* @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 * @throws ServerNotAvailableException
*/ */
public function getUsersInGidNumber( public function getUsersInGidNumber(
@ -591,6 +591,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
/** /**
* @throws ServerNotAvailableException * @throws ServerNotAvailableException
* @return array<int,string>
*/ */
public function getUsersInPrimaryGroup( public function getUsersInPrimaryGroup(
string $groupDN, string $groupDN,
@ -840,7 +841,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
* @param string $search * @param string $search
* @param int $limit * @param int $limit
* @param int $offset * @param int $offset
* @return array with user ids * @return array<int,string> user ids
* @throws Exception * @throws Exception
* @throws ServerNotAvailableException * @throws ServerNotAvailableException
*/ */
@ -909,7 +910,11 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
if (empty($ldap_users)) { if (empty($ldap_users)) {
break; 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; break;
default: default:
//we got DNs, check if we need to filter by search or we can give back all of them //we got DNs, check if we need to filter by search or we can give back all of them

@ -171,7 +171,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* get a list of all users in a group * 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) { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$this->setup(); $this->setup();

@ -126,7 +126,7 @@ abstract class Backend implements \OCP\GroupInterface {
* @param string $search * @param string $search
* @param int $limit * @param int $limit
* @param int $offset * @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) { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
return []; return [];

@ -333,10 +333,10 @@ class Database extends ABackend implements
* @param string $search * @param string $search
* @param int $limit * @param int $limit
* @param int $offset * @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 { 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 { public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array {

@ -251,7 +251,7 @@ class Group implements IGroup {
$users = []; $users = [];
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend instanceof ISearchableGroupBackend) { 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 { } else {
$userIds = $backend->usersInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0); $userIds = $backend->usersInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0);
$userManager = \OCP\Server::get(IUserManager::class); $userManager = \OCP\Server::get(IUserManager::class);

@ -29,7 +29,6 @@ use OCP\IUser;
* @since 26.0.0 * @since 26.0.0
*/ */
interface ISearchableGroupBackend { interface ISearchableGroupBackend {
/** /**
* @brief Get a list of users matching the given search parameters. * @brief Get a list of users matching the given search parameters.
* *
@ -45,7 +44,7 @@ interface ISearchableGroupBackend {
* want to search. This can be empty to get all the users. * want to search. This can be empty to get all the users.
* @param int $limit The limit of results * @param int $limit The limit of results
* @param int $offset The offset of the results * @param int $offset The offset of the results
* @return IUser[] * @return array<string,IUser> Users indexed by uid
* @since 26.0.0 * @since 26.0.0
*/ */
public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array; public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array;

@ -112,7 +112,7 @@ interface GroupInterface {
* @param string $search * @param string $search
* @param int $limit * @param int $limit
* @param int $offset * @param int $offset
* @return array an array of user ids * @return array<int,string> an array of user ids
* @since 4.5.0 * @since 4.5.0
* @deprecated 26.0.0 Use searchInGroup instead, for performance reasons * @deprecated 26.0.0 Use searchInGroup instead, for performance reasons
*/ */

@ -737,7 +737,7 @@ class ManagerTest extends TestCase {
$backend->expects($this->once()) $backend->expects($this->once())
->method('searchInGroup') ->method('searchInGroup')
->with('testgroup', '', -1, 0) ->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'); $this->userManager->expects($this->never())->method('get');
@ -793,7 +793,7 @@ class ManagerTest extends TestCase {
$backend->expects($this->once()) $backend->expects($this->once())
->method('searchInGroup') ->method('searchInGroup')
->with('testgroup', '', 1, 1) ->with('testgroup', '', 1, 1)
->willReturn([$this->getTestUser('user33')]); ->willReturn(['user33' => $this->getTestUser('user33')]);
$this->userManager->expects($this->never())->method('get'); $this->userManager->expects($this->never())->method('get');

@ -208,7 +208,7 @@ class Dummy extends ABackend implements ICreateGroupBackend, IDeleteGroupBackend
$result = []; $result = [];
foreach ($this->groups[$gid] as $user) { foreach ($this->groups[$gid] as $user) {
if (stripos($user, $search) !== false) { if (stripos($user, $search) !== false) {
$result[] = new DummyUser($user, ''); $result[$user] = new DummyUser($user, '');
} }
} }
return $result; return $result;