diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2019-11-25 17:16:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-25 17:16:40 +0100 |
commit | b1dffc5c2dd17216c87788bf36b8e15b45be2241 (patch) | |
tree | 164de89542956784da0c7046c5fb00c09aa423ea /lib/private/Group | |
parent | 279c0cb2ed99c3914f19468c267344aa3a2f04e6 (diff) | |
parent | b4408e4245ca4045df7a5f8fdf6ba9100730fa4f (diff) | |
download | nextcloud-server-b1dffc5c2dd17216c87788bf36b8e15b45be2241.tar.gz nextcloud-server-b1dffc5c2dd17216c87788bf36b8e15b45be2241.zip |
Merge pull request #17896 from nextcloud/fix/noid/consider-create-group-result
take group creation result into consideration
Diffstat (limited to 'lib/private/Group')
-rw-r--r-- | lib/private/Group/Manager.php | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index 7567f719b0a..0e51b4ec2cc 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -93,8 +93,8 @@ class Manager extends PublicEmitter implements IGroupManager { $this->dispatcher = $dispatcher; $this->logger = $logger; - $cachedGroups = & $this->cachedGroups; - $cachedUserGroups = & $this->cachedUserGroups; + $cachedGroups = &$this->cachedGroups; + $cachedUserGroups = &$this->cachedUserGroups; $this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) { /** * @var \OC\Group\Group $group @@ -149,6 +149,7 @@ class Manager extends PublicEmitter implements IGroupManager { /** * Get the active backends + * * @return \OCP\GroupInterface[] */ public function getBackends() { @@ -163,7 +164,7 @@ class Manager extends PublicEmitter implements IGroupManager { /** * @param string $gid - * @return \OC\Group\Group + * @return IGroup|null */ public function get($gid) { if (isset($this->cachedGroups[$gid])) { @@ -175,12 +176,12 @@ class Manager extends PublicEmitter implements IGroupManager { /** * @param string $gid * @param string $displayName - * @return \OCP\IGroup + * @return \OCP\IGroup|null */ protected function getGroupObject($gid, $displayName = null) { $backends = []; foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC\Group\Backend::GROUP_DETAILS)) { + if ($backend->implementsActions(Backend::GROUP_DETAILS)) { $groupData = $backend->getGroupDetails($gid); if (is_array($groupData) && !empty($groupData)) { // take the display name from the first backend that has a non-null one @@ -210,21 +211,22 @@ class Manager extends PublicEmitter implements IGroupManager { /** * @param string $gid - * @return \OC\Group\Group + * @return IGroup|null */ public function createGroup($gid) { if ($gid === '' || $gid === null) { - return false; + return null; } else if ($group = $this->get($gid)) { return $group; } else { - $this->emit('\OC\Group', 'preCreate', array($gid)); + $this->emit('\OC\Group', 'preCreate', [$gid]); foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC\Group\Backend::CREATE_GROUP)) { - $backend->createGroup($gid); - $group = $this->getGroupObject($gid); - $this->emit('\OC\Group', 'postCreate', array($group)); - return $group; + if ($backend->implementsActions(Backend::CREATE_GROUP)) { + if ($backend->createGroup($gid)) { + $group = $this->getGroupObject($gid); + $this->emit('\OC\Group', 'postCreate', [$group]); + return $group; + } } } return null; @@ -260,7 +262,7 @@ class Manager extends PublicEmitter implements IGroupManager { * @param IUser|null $user * @return \OC\Group\Group[] */ - public function getUserGroups(IUser $user= null) { + public function getUserGroups(IUser $user = null) { if (!$user instanceof IUser) { return []; } @@ -295,12 +297,13 @@ class Manager extends PublicEmitter implements IGroupManager { /** * Checks if a userId is in the admin group + * * @param string $userId * @return bool if admin */ public function isAdmin($userId) { foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC\Group\Backend::IS_ADMIN) && $backend->isAdmin($userId)) { + if ($backend->implementsActions(Backend::IS_ADMIN) && $backend->isAdmin($userId)) { return true; } } @@ -309,6 +312,7 @@ class Manager extends PublicEmitter implements IGroupManager { /** * Checks if a userId is in a group + * * @param string $userId * @param string $group * @return bool if in group @@ -319,28 +323,31 @@ class Manager extends PublicEmitter implements IGroupManager { /** * get a list of group ids for a user + * * @param IUser $user * @return array with group ids */ public function getUserGroupIds(IUser $user) { - return array_map(function($value) { - return (string) $value; + return array_map(function ($value) { + return (string)$value; }, array_keys($this->getUserGroups($user))); } /** * get an array of groupid and displayName for a user + * * @param IUser $user * @return array ['displayName' => displayname] */ public function getUserGroupNames(IUser $user) { - return array_map(function($group) { + return array_map(function ($group) { return array('displayName' => $group->getDisplayName()); }, $this->getUserGroups($user)); } /** * get a list of all display names in a group + * * @param string $gid * @param string $search * @param int $limit @@ -349,32 +356,32 @@ class Manager extends PublicEmitter implements IGroupManager { */ public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { $group = $this->get($gid); - if(is_null($group)) { + if (is_null($group)) { return []; } $search = trim($search); $groupUsers = []; - if(!empty($search)) { + if (!empty($search)) { // only user backends have the capability to do a complex search for users $searchOffset = 0; $searchLimit = $limit * 100; - if($limit === -1) { + if ($limit === -1) { $searchLimit = 500; } do { $filteredUsers = $this->userManager->searchDisplayName($search, $searchLimit, $searchOffset); - foreach($filteredUsers as $filteredUser) { - if($group->inGroup($filteredUser)) { - $groupUsers[]= $filteredUser; + foreach ($filteredUsers as $filteredUser) { + if ($group->inGroup($filteredUser)) { + $groupUsers[] = $filteredUser; } } $searchOffset += $searchLimit; - } while(count($groupUsers) < $searchLimit+$offset && count($filteredUsers) >= $searchLimit); + } while (count($groupUsers) < $searchLimit + $offset && count($filteredUsers) >= $searchLimit); - if($limit === -1) { + if ($limit === -1) { $groupUsers = array_slice($groupUsers, $offset); } else { $groupUsers = array_slice($groupUsers, $offset, $limit); @@ -384,7 +391,7 @@ class Manager extends PublicEmitter implements IGroupManager { } $matchingUsers = []; - foreach($groupUsers as $groupUser) { + foreach ($groupUsers as $groupUser) { $matchingUsers[$groupUser->getUID()] = $groupUser->getDisplayName(); } return $matchingUsers; |