mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
63
Security/Authorization/EventVoter.php
Normal file
63
Security/Authorization/EventVoter.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
namespace Chill\EventBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Security\ProvideRoleInterface;
|
||||
use Chill\EventBundle\Entity\Event;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
|
||||
/**
|
||||
* Description of EventVoter
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
*/
|
||||
class EventVoter extends AbstractChillVoter implements ProvideRoleInterface
|
||||
{
|
||||
|
||||
const SEE = 'CHILL_EVENT_SEE';
|
||||
const SEE_DETAILS = 'CHILL_EVENT_SEE_DETAILS';
|
||||
const CREATE = 'CHILL_EVENT_CREATE';
|
||||
const UPDATE = 'CHILL_EVENT_UPDATE';
|
||||
|
||||
protected $authorizationHelper;
|
||||
|
||||
public function __construct(AuthorizationHelper $helper)
|
||||
{
|
||||
$this->authorizationHelper = $helper;
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
{
|
||||
return array(self::SEE, self::SEE_DETAILS,
|
||||
self::CREATE, self::UPDATE);
|
||||
}
|
||||
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array(Event::class);
|
||||
}
|
||||
|
||||
protected function isGranted($attribute, $event, $user = null)
|
||||
{
|
||||
if (!$user instanceof User) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->helper->userHasAccess($user, $event, $attribute);
|
||||
}
|
||||
|
||||
public function getRoles()
|
||||
{
|
||||
return $this->getSupportedAttributes();
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user