Esempio n. 1
0
 public function testRoleContextBucket()
 {
     $acl = $this->getAcl();
     $rb = new RoleBucket($acl);
     $rb->add('guest');
     $rb->add('super_administrator');
     $acl->switchRoleContext($rb);
     $context = $acl->getContext();
     $this->assertEquals($context->getRoles()->toArray(), ['guest', 'super_administrator']);
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function getRoles()
 {
     if (!isset($this->roles)) {
         $this->roles = parent::getRoles();
         $roles = $this->getRoleQuery()->pluck('role_id');
         foreach ($roles as $role) {
             if ($role = app(RoleProvider::class)->getRoleById($role)) {
                 $this->roles->add($role['system_id']);
             }
         }
     }
     return clone $this->roles;
 }
Esempio n. 3
0
 /**
  * Switch to a explicit role (used in testing)
  *
  * @param  array|string|RoleBucket $roles
  * @return AclContextContract
  */
 public function switchRoleContext($roles)
 {
     if (is_string($roles)) {
         $roles = [$roles];
     }
     if (is_array($roles)) {
         $roleBucket = new RoleBucket($this);
         foreach ($roles as $role) {
             $roleBucket->add($role);
         }
     } else {
         $roleBucket = $roles;
     }
     $context = new RoleSetContext($roleBucket);
     $this->registerContext($context);
     $this->currentContext = $context->getId();
     return $context;
 }
Esempio n. 4
0
 /**
  * @inheritdoc
  */
 protected function id()
 {
     return sha1(implode($this->roles->toArray()));
 }
Esempio n. 5
0
 private function discoverSelf(RoleBucket $roleBucket)
 {
     if ($this->isSelf()) {
         $roleBucket->add('self');
     }
 }