public function testGetGroups() { $groups = []; $id = $this->getUniqueID(); for ($i = 0; $i < 10; $i++) { $groups[] = $this->groupManager->createGroup($id . '_' . $i); } $_GET = []; $result = $this->api->getGroups([]); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $this->assertCount(count($this->groupManager->search('')), $result->getData()['groups']); $this->assertContains('admin', $result->getData()['groups']); foreach ($groups as $group) { $this->assertContains($group->getGID(), $result->getData()['groups']); } $_GET = ['search' => $id, 'limit' => 5, 'offset' => 2]; $result = $this->api->getGroups([]); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $this->assertCount(5, $result->getData()['groups']); foreach (array_splice($groups, 2, 5) as $group) { $this->assertContains($group->getGID(), $result->getData()['groups']); } foreach ($groups as $group) { $group->delete(); } }
/** * Returns a list of principals based on a prefix. * * This prefix will often contain something like 'principals'. You are only * expected to return principals that are in this base path. * * You are expected to return at least a 'uri' for every user, you can * return any additional properties if you wish so. Common properties are: * {DAV:}displayname * * @param string $prefixPath * @return string[] */ public function getPrincipalsByPrefix($prefixPath) { $principals = []; if ($prefixPath === self::PRINCIPAL_PREFIX) { foreach ($this->groupManager->search('') as $user) { $principals[] = $this->groupToPrincipal($user); } } return $principals; }
/** * returns a list of groups */ public function getGroups($parameters) { $search = !empty($_GET['search']) ? $_GET['search'] : ''; $limit = !empty($_GET['limit']) ? $_GET['limit'] : null; $offset = !empty($_GET['offset']) ? $_GET['offset'] : null; $groups = $this->groupManager->search($search, $limit, $offset); $groups = array_map(function ($group) { return $group->getGID(); }, $groups); return new OC_OCS_Result(['groups' => $groups]); }
/** * @param string $search */ protected function getGroups($search) { $this->result['groups'] = $this->result['exact']['groups'] = []; $groups = $this->groupManager->search($search, $this->limit, $this->offset); $groups = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); if (sizeof($groups) < $this->limit) { $this->reachedEndFor[] = 'groups'; } $userGroups = []; if (!empty($groups) && $this->shareWithGroupOnly) { // Intersect all the groups that match with the groups this user is a member of $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); $groups = array_intersect($groups, $userGroups); } foreach ($groups as $gid) { if (strtolower($gid) === $search) { $this->result['exact']['groups'][] = ['label' => $search, 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => $search]]; } else { $this->result['groups'][] = ['label' => $gid, 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => $gid]]; } } if ($this->offset === 0 && empty($this->result['exact']['groups'])) { // On page one we try if the search result has a direct hit on the // user id and if so, we add that to the exact match list $group = $this->groupManager->get($search); if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { array_push($this->result['exact']['groups'], ['label' => $group->getGID(), 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => $group->getGID()]]); } } }
/** * returns a list of groups * * @param array $parameters * @return OC_OCS_Result */ public function getGroups($parameters) { $search = $this->request->getParam('search', ''); $limit = $this->request->getParam('limit'); $offset = $this->request->getParam('offset'); if ($limit !== null) { $limit = (int) $limit; } if ($offset !== null) { $offset = (int) $offset; } $groups = $this->groupManager->search($search, $limit, $offset); $groups = array_map(function ($group) { /** @var IGroup $group */ return $group->getGID(); }, $groups); return new OC_OCS_Result(['groups' => $groups]); }
/** * returns the available groups * @param string $search a search string * @return \OCP\IGroup[] */ protected function getGroups($search = '') { if ($this->isAdmin) { return $this->groupManager->search($search); } else { $userObject = $this->userSession->getUser(); if ($userObject !== null) { $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($userObject); } else { $groups = []; } return $groups; } }
/** * returns the available groups * @param string $search a search string * @return \OC\Group\Group[] */ private function getGroups($search = '') { if ($this->isAdmin) { return $this->groupManager->search($search); } else { // FIXME: Remove static method call $groupIds = \OC_SubAdmin::getSubAdminsGroups($this->user); /* \OC_SubAdmin::getSubAdminsGroups() returns an array of GIDs, but this * method is expected to return an array with the GIDs as keys and group objects as * values, so we need to convert this information. */ $groups = array(); foreach ($groupIds as $gid) { $group = $this->groupManager->get($gid); if (!is_null($group)) { $groups[$gid] = $group; } } return $groups; } }