From 45e42c25de5e498197a9aace7161b4f377a8dacc Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 14 Mar 2014 13:51:17 +0100 Subject: Group Database backend must not gather user details itself but ask user backends. This is a port to master from PR #7745 remove OC_GROUP_BACKEND_GET_DISPLAYNAME option for group backends Conflicts: lib/private/group/backend.php LDAP: getDisplayNamesInGroup is not an option for group backends anymore Conflicts: apps/user_ldap/group_ldap.php apps/user_ldap/group_proxy.php clean up group backends Conflicts: lib/private/group/database.php remove now unnecessary test implement getDisplayNames in group manager adjust user manager tests test for group manager's displayNamesInGroup trim must not be used in empty in PHP < 5.5 keep the constant to not provoke PHP warnings Conflicts: lib/private/group/backend.php --- lib/private/group.php | 12 +----------- lib/private/group/backend.php | 22 +--------------------- lib/private/group/database.php | 25 ------------------------- lib/private/group/group.php | 6 +----- lib/private/group/manager.php | 34 ++++++++++++++++++++++++++++++++++ lib/private/user/manager.php | 4 ++-- 6 files changed, 39 insertions(+), 64 deletions(-) (limited to 'lib') diff --git a/lib/private/group.php b/lib/private/group.php index d9f430f833b..ea6384bae3e 100644 --- a/lib/private/group.php +++ b/lib/private/group.php @@ -274,17 +274,7 @@ class OC_Group { * @returns array with display names (value) and user ids(key) */ public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { - $group = self::getManager()->get($gid); - if ($group) { - $users = $group->searchDisplayName($search, $limit, $offset); - $displayNames = array(); - foreach ($users as $user) { - $displayNames[$user->getUID()] = $user->getDisplayName(); - } - return $displayNames; - } else { - return array(); - } + return self::getManager()->displayNamesInGroup($gid, $search, $limit, $offset); } /** diff --git a/lib/private/group/backend.php b/lib/private/group/backend.php index b0ed0d90d76..cc61fce1615 100644 --- a/lib/private/group/backend.php +++ b/lib/private/group/backend.php @@ -33,7 +33,7 @@ define('OC_GROUP_BACKEND_CREATE_GROUP', 0x00000001); define('OC_GROUP_BACKEND_DELETE_GROUP', 0x00000010); define('OC_GROUP_BACKEND_ADD_TO_GROUP', 0x00000100); define('OC_GROUP_BACKEND_REMOVE_FROM_GOUP', 0x00001000); -define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); +define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); //OBSOLETE define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000); /** @@ -45,7 +45,6 @@ abstract class OC_Group_Backend implements OC_Group_Interface { OC_GROUP_BACKEND_DELETE_GROUP => 'deleteGroup', OC_GROUP_BACKEND_ADD_TO_GROUP => 'addToGroup', OC_GROUP_BACKEND_REMOVE_FROM_GOUP => 'removeFromGroup', - OC_GROUP_BACKEND_GET_DISPLAYNAME => 'displayNamesInGroup', OC_GROUP_BACKEND_COUNT_USERS => 'countUsersInGroup', ); @@ -137,23 +136,4 @@ abstract class OC_Group_Backend implements OC_Group_Interface { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { return array(); } - - /** - * @brief get a list of all display names in a group - * @param string $gid - * @param string $search - * @param int $limit - * @param int $offset - * @return array with display names (value) and user ids (key) - */ - public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { - $displayNames = array(); - $users = $this->usersInGroup($gid, $search, $limit, $offset); - foreach ($users as $user) { - $displayNames[$user] = $user; - } - - return $displayNames; - } - } diff --git a/lib/private/group/database.php b/lib/private/group/database.php index 3815dcff2e5..df0d84d0d2a 100644 --- a/lib/private/group/database.php +++ b/lib/private/group/database.php @@ -225,29 +225,4 @@ class OC_Group_Database extends OC_Group_Backend { return $result->fetchOne(); } - /** - * @brief get a list of all display names in a group - * @param string $gid - * @param string $search - * @param int $limit - * @param int $offset - * @return array with display names (value) and user ids (key) - */ - public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { - $displayNames = array(); - - $stmt = OC_DB::prepare('SELECT `*PREFIX*users`.`uid`, `*PREFIX*users`.`displayname`' - .' FROM `*PREFIX*users`' - .' INNER JOIN `*PREFIX*group_user` ON `*PREFIX*group_user`.`uid` = `*PREFIX*users`.`uid`' - .' WHERE `gid` = ? AND `*PREFIX*group_user`.`uid` LIKE ?', - $limit, - $offset); - $result = $stmt->execute(array($gid, $search.'%')); - $users = array(); - while ($row = $result->fetchRow()) { - $displayName = trim($row['displayname'], ' '); - $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName; - } - return $displayNames; - } } diff --git a/lib/private/group/group.php b/lib/private/group/group.php index 3efbb6e7023..7593bb68d1a 100644 --- a/lib/private/group/group.php +++ b/lib/private/group/group.php @@ -212,11 +212,7 @@ class Group { public function searchDisplayName($search, $limit = null, $offset = null) { $users = array(); foreach ($this->backends as $backend) { - if ($backend->implementsActions(OC_GROUP_BACKEND_GET_DISPLAYNAME)) { - $userIds = array_keys($backend->displayNamesInGroup($this->gid, $search, $limit, $offset)); - } else { - $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); - } + $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); $users = $this->getVerifiedUsers($userIds); if (!is_null($limit) and $limit <= 0) { return array_values($users); diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index f591bd32aba..d31225e3c2e 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -158,4 +158,38 @@ class Manager extends PublicEmitter { } return array_values($groups); } + + /** + * @brief get a list of all display names in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (value) and user ids (key) + */ + 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 + $groupUsers = $group->searchUsers('', $limit, $offset); + $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; + } + + $matchingUsers = array(); + foreach($groupUsers as $user) { + if(!$testUsers || isset($filteredUsers[$user->getUID()])) { + $matchingUsers[$user->getUID()] = $user->getDisplayName(); + } + } + return $matchingUsers; + } } diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index 14698452e88..6f6fd80a8ef 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -174,12 +174,12 @@ class Manager extends PublicEmitter { $backendUsers = $backend->getUsers($pattern, $limit, $offset); if (is_array($backendUsers)) { foreach ($backendUsers as $uid) { - $users[] = $this->getUserObject($uid, $backend); + $users[$uid] = $this->getUserObject($uid, $backend); } } } - usort($users, function ($a, $b) { + uasort($users, function ($a, $b) { /** * @var \OC\User\User $a * @var \OC\User\User $b -- cgit v1.2.3