public function testRescanGroupPath() { $originalGroup = Group::add('Old Group for Rescan', 'This is a test group'); $newGroup = $originalGroup->update('New Group for Rescan', 'This is a test group'); $newPath = $newGroup->getGroupPath(); $this->assertEquals('/New Group for Rescan', $newPath); }
public function import(\SimpleXMLElement $sx) { if (isset($sx->groups)) { $groups = array(); foreach ($sx->groups->group as $g) { $groups[] = $g; } usort($groups, function ($a, $b) { $pathA = (string) $a['path']; $pathB = (string) $b['path']; $numA = count(explode('/', $pathA)); $numB = count(explode('/', $pathB)); if ($numA == $numB) { return 0; } else { return $numA < $numB ? -1 : 1; } }); foreach ($groups as $group) { $existingGroup = \Concrete\Core\User\Group\Group::getByPath((string) $group['path']); if (!is_object($existingGroup)) { $parent = null; if ((string) $group['path'] != '') { $lastSlash = strrpos((string) $group['path'], '/'); $parentPath = substr((string) $group['path'], 0, $lastSlash); if ($parentPath) { $parent = \Concrete\Core\User\Group\Group::getByPath($parentPath); } } $pkg = static::getPackageObject($g['package']); \Concrete\Core\User\Group\Group::add((string) $group['name'], (string) $group['description'], $parent, $pkg); } } } }
public function groupExists($name, $batch) { $g = Group::getByName($name); if (is_object($g)) { return true; } return false; }
public function setDefaultPermissions(FileManager $tree) { $rootNode = $tree->getRootTreeNodeObject(); $adminGroupEntity = GroupEntity::getOrCreate(Group::getByID(ADMIN_GROUP_ID)); $pk = CategoryTreeNodeKey::getByHandle('view_category_tree_node'); $pk->setPermissionObject($rootNode); $pa = Access::create($pk); $pa->addListItem($adminGroupEntity); $pt = $pk->getPermissionAssignmentObject(); $pt->assignPermissionAccess($pa); }
public function load() { $db = Loader::db(); $gID = $db->GetOne('select gID from PermissionAccessEntityGroups where peID = ?', array($this->peID)); if ($gID) { $g = Group::getByID($gID); if (is_object($g)) { $this->group = $g; $this->label = $g->getGroupDisplayName(); } else { $this->label = t('(Deleted Group)'); } } }
public function getAccessEntity() { $group = $this->group; if (!is_object($group)) { $group = Group::getByName($this->group); if (!is_object($group)) { $group = Group::getByPath($this->group); } } if (is_object($group)) { $entity = GroupAccessEntity::getOrCreate($group); return $entity; } }
public function import(\SimpleXMLElement $sx) { if (isset($sx->permissionkeys)) { foreach ($sx->permissionkeys->permissionkey as $pk) { if (is_object(Key::getByHandle((string) $pk['handle']))) { continue; } $pkc = Category::getByHandle((string) $pk['category']); $c1 = $pkc->getPermissionKeyClass(); $pkx = call_user_func(array($c1, 'import'), $pk); $assignments = array(); if (isset($pk->access)) { foreach ($pk->access->children() as $ch) { if ($ch->getName() == 'group') { /* * Legacy */ $g = Group::getByName($ch['name']); if (!is_object($g)) { $g = Group::add($g['name'], $g['description']); } $pae = GroupEntity::getOrCreate($g); $assignments[] = $pae; } if ($ch->getName() == 'entity') { $type = Type::getByHandle((string) $ch['type']); $class = $type->getAccessEntityTypeClass(); if (method_exists($class, 'configureFromImport')) { $pae = $class::configureFromImport($ch); $assignments[] = $pae; } } } } if (count($assignments)) { $pa = Access::create($pkx); foreach ($assignments as $pae) { $pa->addListItem($pae); } $pt = $pkx->getPermissionAssignmentObject(); $pt->assignPermissionAccess($pa); } } } }
public static function add() { // copy permissions from the other node. $rootNode = ExpressEntryCategory::add(); $treeID = parent::create($rootNode); $tree = self::getByID($treeID); $adminGroupEntity = GroupEntity::getOrCreate(ConcreteGroup::getByID(ADMIN_GROUP_ID)); $permissions = ['view_express_entries', 'add_express_entries', 'edit_express_entries', 'delete_express_entries']; foreach ($permissions as $handle) { $pk = ExpressTreeNodeKey::getByHandle($handle); $pk->setPermissionObject($rootNode); $pa = Access::create($pk); $pa->addListItem($adminGroupEntity); $pt = $pk->getPermissionAssignmentObject(); $pt->assignPermissionAccess($pa); } return $tree; }
public function testGroups() { $u = \User::getByUserID(2); $g = Group::add('Test Group', 'Test Group'); $u->enterGroup($g); $this->list->filterByGroup($g); $this->assertEquals(1, $this->list->getTotalResults()); $pagination = $this->list->getPagination(); $this->assertEquals(1, $pagination->getTotalResults()); $results = $pagination->getCurrentPageResults(); $this->assertInstanceOf('\\Concrete\\Core\\User\\UserInfo', $results[0]); $this->assertEquals('testuser2', $results[0]->getUserName()); $nl = new UserList(); $nl->filterByGroup($g, false); $nl->sortByUserID(); $this->assertEquals(2, $nl->getTotalResults()); $results = $nl->getResults(); $this->assertEquals('testuser', $results[0]->getUserName()); $this->assertEquals('andrew', $results[1]->getUserName()); }
public function testAutomatedGroupsBase() { require_once dirname(__FILE__) . '/fixtures/TestGroup.php'; $g = Group::add('Test Group', ''); // gonna pull all users with vowels in their names in this group. $g->setAutomationOptions(true, false, false); $groupControllers = \Group::getAutomatedOnRegisterGroupControllers(); $this->assertEquals(1, count($groupControllers)); $users = array(array('aembler', '*****@*****.**'), array('ffjdhbn', '*****@*****.**'), array('ffbOkj', '*****@*****.**'), array('kkytnz', '*****@*****.**'), array('zzvnv', '*****@*****.**'), array('qqwenz', '*****@*****.**'), array('mmnvb', '*****@*****.**')); foreach ($users as $user) { $this->createUser($user[0], $user[1]); } $ul = new UserList(); $ul->filterByGroupID($g->getGroupID()); $ul->sortByUserName(); $users1 = $ul->getResults(); $ul = new UserList(); $ul->filterByNoGroup(); $ul->sortByUserName(); $users2 = $ul->getResults(); $this->assertEquals(3, count($users1)); $this->assertEquals(4, count($users2)); }
public function testAddingBadgeToUser() { \Cache::disableAll(); \Config::set('concrete.email.enabled', false); \Config::set('concrete.log.emails', false); Action::add('won_badge', t('Won a Badge'), 5, false); $g = Group::add('Test Group', 'Gettin a Badge'); $g->setBadgeOptions(0, 'test', 10); $g = Group::getByID(1); $user = \Concrete\Core\User\UserInfo::add(array('uName' => 'testuser', 'uEmail' => '*****@*****.**')); $uo = $user->getUserObject(); $uo->enterGroup($g); \Config::clear('concrete.email.enabled'); \Config::clear('concrete.log.emails'); $list = new EntryList(); $list->filterbyUserName('testuser'); $results = $list->get(); $this->assertEquals(1, count($results)); $result = $results[0]; $this->assertInstanceOf('\\Concrete\\Core\\User\\Point\\Entry', $result); /* @var $result \Concrete\Core\User\Point\Entry */ $this->assertInstanceOf('\\Concrete\\Core\\User\\Point\\Action\\WonBadgeAction', $result->getUserPointEntryActionObject()); $this->assertInstanceOf('\\Concrete\\Core\\User\\Point\\Action\\WonBadgeActionDescription', $result->getUserPointEntryDescriptionObject()); }
public static function getAutomatedOnJobRunGroupControllers() { return Group::getAutomationControllers('gCheckAutomationOnJobRun'); }
/** * @param $queryRow * * @return \Concrete\Core\User\Group\Group */ public function getResult($queryRow) { $g = Group::getByID($queryRow['gID']); return $g; }
public function _getUserGroups($disableLogin = false) { $app = Application::getFacadeApplication(); $req = Request::getInstance(); $session = $app['session']; if ($session->has('uGroups') && !$disableLogin && !$req->hasCustomRequestUser()) { $ug = $session->get('uGroups'); } else { $db = $app['database']->connection(); if ($this->uID) { $ug[REGISTERED_GROUP_ID] = REGISTERED_GROUP_ID; $uID = $this->uID; $q = "select gID from UserGroups where uID = ?"; $r = $db->query($q, array($uID)); while ($row = $r->fetch()) { $g = Group::getByID($row['gID']); if ($g->isUserExpired($this)) { $this->exitGroup($g); } else { $ug[$row['gID']] = $row['gID']; } } } // now we populate also with guest information, since presumably logged-in users // see the same stuff as guest $ug[GUEST_GROUP_ID] = GUEST_GROUP_ID; } return $ug; }
public function installMaintenanceModePermission() { $pk = Key::getByHandle('view_in_maintenance_mode'); if (!$pk instanceof Key) { $pk = Key::add('admin', 'view_in_maintenance_mode', 'View Site in Maintenance Mode', 'Controls whether a user can access the website when its under maintenance.', false, false); $pa = $pk->getPermissionAccessObject(); if (!is_object($pa)) { $pa = Access::create($pk); } $adminGroup = Group::getByID(ADMIN_GROUP_ID); if ($adminGroup) { $adminGroupEntity = GroupEntity::getOrCreate($adminGroup); $pa->addListItem($adminGroupEntity); $pt = $pk->getPermissionAssignmentObject(); $pt->assignPermissionAccess($pa); } } }
public function setTreeNodeGroup(UserGroup $g) { $db = Loader::db(); $db->Replace('TreeGroupNodes', array('treeNodeID' => $this->getTreeNodeID(), 'gID' => $g->getGroupID()), array('treeNodeID'), true); $this->gID = $g->getGroupID(); }
/** * Filters by Group ID. */ public function filterByGroupID($gID) { $group = Group::getByID($gID); $this->filterByGroup($group); }
public function removeGroup(Group $g) { $db = Loader::db(); $db->Execute('delete from GroupSetGroups where gsID = ? and gID = ?', array($this->getGroupSetID(), $g->getGroupID())); }
protected function getAssignments(AccessEntity $entity) { $class = $this->getClass($entity); $g = Group::getByName($entity->getGroupName()); return $class::getOrCreate($g); }
public function setPropertiesFromArray($arr) { return parent::setPropertiesFromArray($arr); }
/** * Return true if user is in Group. * * @param Group $g * @return bool */ public function inGroup($g) { $app = Application::getFacadeApplication(); $db = $app['database']->connection(); $v = array($this->uID, $g->getGroupID()); $cnt = $db->GetOne("select gID from UserGroups where uID = ? and gID = ?", $v); return $cnt > 0; }