/** * @NoAdminRequired * * @param string $pattern * @param bool $filterGroups * @return DataResponse */ public function index($pattern = '', $filterGroups = false) { $groupPattern = $filterGroups ? $pattern : ''; $groupsInfo = new \OC\Group\MetaData($this->userSession->getUser()->getUID(), $this->isAdmin, $this->groupManager); $groupsInfo->setSorting($groupsInfo::SORT_USERCOUNT); list($adminGroups, $groups) = $groupsInfo->get($groupPattern, $pattern); return new DataResponse(array('data' => array('adminGroups' => $adminGroups, 'groups' => $groups))); }
public function testGetWithSorting() { $groupManager = $this->getGroupManagerMock(); $groupMetaData = new \OC\Group\MetaData('foo', true, $groupManager); $groupMetaData->setSorting($groupMetaData::SORT_USERCOUNT); $group = $this->getGroupMock(); $groups = array_fill(0, 3, $group); $groupManager->expects($this->once())->method('search')->with('')->will($this->returnValue($groups)); list($adminGroups, $ordinaryGroups) = $groupMetaData->get(); $this->assertSame(1, count($adminGroups)); $this->assertSame(2, count($ordinaryGroups)); $this->assertSame('g3', $ordinaryGroups[0]['name']); $this->assertSame(5, $ordinaryGroups[0]['usercount']); }
OC_App::setActiveNavigationEntry('core_users'); $userManager = \OC_User::getManager(); $groupManager = \OC_Group::getManager(); // Set the sort option: SORT_USERCOUNT or SORT_GROUPNAME $sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT; if (\OC_App::isEnabled('user_ldap')) { $isLDAPUsed = $groupManager->isBackendUsed('\\OCA\\user_ldap\\GROUP_LDAP') || $groupManager->isBackendUsed('\\OCA\\user_ldap\\Group_Proxy'); if ($isLDAPUsed) { // LDAP user count can be slow, so we sort by group name here $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME; } } $config = \OC::$server->getConfig(); $isAdmin = OC_User::isAdminUser(OC_User::getUser()); $groupsInfo = new \OC\Group\MetaData(OC_User::getUser(), $isAdmin, $groupManager); $groupsInfo->setSorting($sortGroupsBy); list($adminGroup, $groups) = $groupsInfo->get(); $recoveryAdminEnabled = OC_App::isEnabled('encryption') && $config->getAppValue('encryption', 'recoveryAdminEnabled', null); if ($isAdmin) { $subadmins = OC_SubAdmin::getAllSubAdmins(); } else { /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */ $gids = array(); foreach ($groups as $group) { if (isset($group['id'])) { $gids[] = $group['id']; } } $subadmins = false; } // load preset quotas
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ OC_JSON::callCheck(); OC_JSON::checkSubAdminUser(); if (isset($_GET['pattern']) && !empty($_GET['pattern'])) { $pattern = $_GET['pattern']; } else { $pattern = ''; } if (isset($_GET['filterGroups']) && !empty($_GET['filterGroups'])) { $filterGroups = intval($_GET['filterGroups']) === 1; } else { $filterGroups = false; } $groupPattern = $filterGroups ? $pattern : ''; $groups = array(); $adminGroups = array(); $groupManager = \OC_Group::getManager(); $isAdmin = OC_User::isAdminUser(OC_User::getUser()); //we pass isAdmin as true, because OC_SubAdmin has no search feature, //groups will be filtered out later $groupsInfo = new \OC\Group\MetaData(OC_User::getUser(), true, $groupManager); $groupsInfo->setSorting($groupsInfo::SORT_USERCOUNT); list($adminGroups, $groups) = $groupsInfo->get($groupPattern, $pattern); OC_JSON::success(array('data' => array('adminGroups' => $adminGroups, 'groups' => $groups)));
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ OC_Util::checkSubAdminUser(); OC_App::setActiveNavigationEntry('core_users'); $userManager = \OC_User::getManager(); $groupManager = \OC_Group::getManager(); $config = \OC::$server->getConfig(); $isAdmin = OC_User::isAdminUser(OC_User::getUser()); $groupsInfo = new \OC\Group\MetaData(OC_User::getUser(), $isAdmin, $groupManager); $groupsInfo->setSorting($groupsInfo::SORT_GROUPNAME); list($adminGroup, $groups) = $groupsInfo->get(); $recoveryAdminEnabled = OC_App::isEnabled('encryption') && $config->getAppValue('encryption', 'recoveryAdminEnabled', null); if ($isAdmin) { $subadmins = OC_SubAdmin::getAllSubAdmins(); } else { /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */ $gids = array(); foreach ($groups as $group) { if (isset($group['id'])) { $gids[] = $group['id']; } } $subadmins = false; } // load preset quotas