/** * 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; } }
/** * Returns the denied ids which match the given action and resource type * * @param string|array $action * @param string|\BeatSwitch\Lock\Resources\Resource $resourceType * @return array */ public function denied($action, $resourceType) { $this->assertLockInstanceIsSet(); return $this->lock->denied($action, $resourceType); }
/** * Clear a given permission on a subject * * @param string|array $action * @param string|\BeatSwitch\Lock\Resources\Resource $resource * @param int $resourceId */ public function clear($action, $resource = null, $resourceId = null) { $this->assertLockInstanceIsSet(); $this->lock->clear($action, $resource, $resourceId); }