/**
  * Assert if the condition is correct
  *
  * @param \BeatSwitch\Lock\Lock $lock
  * @param \BeatSwitch\Lock\Permissions\Permission $permission
  * @param string $action
  * @param \BeatSwitch\Lock\Resources\Resource|null $resource
  * @return bool
  */
 public function assert(Lock $lock, Permission $permission, $action, Resource $resource = null)
 {
     $user = $lock->getSubject();
     $id = (int) $resource->getResourceId();
     $userId = (int) $user->id;
     if ($user instanceof User) {
         return $user->hasRole('admin') || $userId === $id;
     }
 }
示例#2
0
 /**
  * The resource's identifier
  *
  * @return int|null
  */
 public function getResourceId()
 {
     return $this->resource ? $this->resource->getResourceId() : null;
 }