Ejemplo n.º 1
0
 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);
             }
         }
     }
 }
Ejemplo n.º 3
0
 public static function configureFromImport(\SimpleXMLElement $element)
 {
     $g = Group::getByName((string) $element['name']);
     if (!is_object($g)) {
         $g = Group::add((string) $element['name'], (string) $element['description']);
     }
     return static::getOrCreate($g);
 }
 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);
             }
         }
     }
 }
Ejemplo n.º 5
0
 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());
 }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
 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());
 }