Ejemplo n.º 1
0
 public function testUserPermissionComesBeforeRolePermission()
 {
     $user = TestUser::create(['name' => 'user']);
     $role = Role::create(['name' => 'role']);
     $perm = Permission::create(['name' => 'permission']);
     $user->addRole($role);
     $role->allowPermission($perm);
     $user->denyPermission($perm);
     $perm = $user->getPermission($perm);
     $this->assertNotNull($perm);
     $this->assertFalse($perm->allow);
 }
Ejemplo n.º 2
0
 /**
  * @expectedException RuntimeException
  */
 public function testAccessAllowOnResourcePermission()
 {
     $res = TestResource::create(['name' => 'resource']);
     $perm = Permission::create(['name' => 'permission']);
     $res->addPermissionTo('show', $perm);
     $perm = $res->mergedPermissions()->first();
     $var = $perm->allow;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public static function removeGlobalPermissionTo($action, Permission $permission = null)
 {
     $instance = new static();
     $query = $instance->permissions()->newPivotStatement()->where('action', $action)->where('resource_type', get_called_class())->whereNull('resource_id');
     if ($permission) {
         $query->where('permission_id', $permission->getKey());
     }
     $query->delete();
 }
Ejemplo n.º 4
0
 protected function createFakes()
 {
     return [TestUser::create(['name' => 'user']), Role::create(['name' => 'role']), Permission::create(['name' => 'permission']), TestResource::create(['name' => 'resource'])];
 }
Ejemplo n.º 5
0
 /**
  * Get a specific permission from the subject.
  * 
  * @param  Permission $permission
  * 
  * @return Permission
  */
 public function getPermission(Permission $permission)
 {
     return $this->mergedPermissions()->find($permission->getKey());
 }
Ejemplo n.º 6
0
 /**
  * @expectedException RuntimeException
  */
 public function testRolePermissionActionAttribute()
 {
     $role = Role::create(['name' => 'role']);
     $perm = Permission::create(['name' => 'permission']);
     $role->allowPermission($perm);
     $perm = $role->mergedPermissions()->first();
     $var = $perm->action;
 }