Пример #1
0
 /**
  * Apply permissions, restrictions and roles to the given user
  *
  * @param   User    $user
  */
 public function applyRoles(User $user)
 {
     $username = $user->getUsername();
     try {
         $roles = Config::app('roles');
     } catch (NotReadableError $e) {
         Logger::error('Can\'t get permissions and restrictions for user \'%s\'. An exception was thrown:', $username, $e);
         return;
     }
     $userGroups = $user->getGroups();
     $permissions = array();
     $restrictions = array();
     $roleObjs = array();
     foreach ($roles as $roleName => $role) {
         if ($this->match($username, $userGroups, $role)) {
             $permissionsFromRole = StringHelper::trimSplit($role->permissions);
             $permissions = array_merge($permissions, array_diff($permissionsFromRole, $permissions));
             $restrictionsFromRole = $role->toArray();
             unset($restrictionsFromRole['users']);
             unset($restrictionsFromRole['groups']);
             unset($restrictionsFromRole['permissions']);
             foreach ($restrictionsFromRole as $name => $restriction) {
                 if (!isset($restrictions[$name])) {
                     $restrictions[$name] = array();
                 }
                 $restrictions[$name][] = $restriction;
             }
             $roleObj = new Role();
             $roleObjs[] = $roleObj->setName($roleName)->setPermissions($permissionsFromRole)->setRestrictions($restrictionsFromRole);
         }
     }
     $user->setPermissions($permissions);
     $user->setRestrictions($restrictions);
     $user->setRoles($roleObjs);
 }
Пример #2
0
 public function testWhetherSearchProvidesHintWhenSearchStringIsEmpty()
 {
     $user = new User('test');
     $user->setPermissions(array('*' => '*'));
     $dashboard = new SearchDashboard();
     $dashboard->setUser($user);
     $dashboard = $dashboard->search();
     $result = $dashboard->getPane('search')->hasDashlet('Ready to search');
     $this->assertTrue($result, 'Dashboard::search() could not get hint for search');
 }
Пример #3
0
 public function testPermissions()
 {
     $user = new User('test');
     $user->setPermissions(array('test', 'test/some/specific', 'test/more/*', 'test/wildcard-with-wildcard/*', 'test/even-more/specific-with-wildcard/*'));
     $this->assertTrue($user->can('test'));
     $this->assertTrue($user->can('test/some/specific'));
     $this->assertTrue($user->can('test/more/everything'));
     $this->assertTrue($user->can('test/wildcard-with-wildcard/*'));
     $this->assertTrue($user->can('test/wildcard-with-wildcard/sub/sub'));
     $this->assertTrue($user->can('test/even-more/*'));
     $this->assertFalse($user->can('not/test'));
     $this->assertFalse($user->can('test/some/not/so/specific'));
     $this->assertFalse($user->can('test/wildcard2/*'));
 }
Пример #4
0
 /**
  * @depends testWhetherCreatePaneCreatesAPane
  */
 public function testLoadPaneItemsProvidedByEnabledModules()
 {
     $user = new User('test');
     $user->setPermissions(array('*' => '*'));
     $dashboard = new Dashboard();
     $dashboard->setUser($user);
     $dashboard->load();
     $this->assertCount(1, $dashboard->getPanes(), 'Dashboard::load() could not load panes from enabled modules');
 }