public function testGetWithCache() { $groupManager = $this->getGroupManagerMock(); $groupMetaData = new \OC\Group\MetaData('foo', true, $groupManager); $group = $this->getGroupMock(); $groups = array_fill(0, 3, $group); $groupManager->expects($this->once())->method('search')->with('')->will($this->returnValue($groups)); //two calls, if caching fails call counts for group and groupmanager //are exceeded $groupMetaData->get(); $groupMetaData->get(); }
/** * @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))); }
$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 $quotaPreset = $config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
* 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)));