use App\Base\Models\User;
class Authorization
{
public $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function userHasPermissionTo($action, $resource, $resourceId = null, $groupRelated = false, $groupType = null, $groupId = null)
{
if ($groupRelated) {
return (
(
$resourceId ? $this->user->isOwner($resource, $resourceId) : false
) || (
$this->user->isMember($groupType, $groupId) &&
$this->user->isAllowedTo($action, $resource, true, $groupType, $groupId)
)
) && (
$this->user->isNotForbiddenTo($action, $resource, $groupType, $groupId)
);
}
if ($groupType) {
return (
$this->user->isOwner($resource, $resourceId) || (
$this->user->isMember($groupType, $groupId) &&
$this->user->isAllowedTo($action, $resource, false, $groupType, $groupId)
)
) && (
$this->user->isNotForbiddenTo($action, $resource, $groupType, $groupId)
);
}
return $this->user->isAllowedTo($action, $resource) &&
$this->user->isNotForbiddenTo($action, $resource);
}
//
}