mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\ActivityBundle\Security\Authorization;
|
|
|
|
use Chill\MainBundle\Entity\Center;
|
|
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
|
|
|
use function in_array;
|
|
|
|
class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
|
|
{
|
|
public const LISTS = 'CHILL_ACTIVITY_LIST';
|
|
|
|
public const STATS = 'CHILL_ACTIVITY_STATS';
|
|
|
|
/**
|
|
* @var AuthorizationHelper
|
|
*/
|
|
protected $helper;
|
|
|
|
public function __construct(AuthorizationHelper $helper)
|
|
{
|
|
$this->helper = $helper;
|
|
}
|
|
|
|
public function getRoles()
|
|
{
|
|
return $this->getAttributes();
|
|
}
|
|
|
|
public function getRolesWithHierarchy()
|
|
{
|
|
return ['Activity' => $this->getRoles()];
|
|
}
|
|
|
|
public function getRolesWithoutScope()
|
|
{
|
|
return $this->getAttributes();
|
|
}
|
|
|
|
protected function getSupportedClasses()
|
|
{
|
|
return [Center::class];
|
|
}
|
|
|
|
protected function isGranted($attribute, $object, $user = null)
|
|
{
|
|
if (!$user instanceof \Symfony\Component\Security\Core\User\UserInterface) {
|
|
return false;
|
|
}
|
|
|
|
return $this->helper->userHasAccess($user, $object, $attribute);
|
|
}
|
|
|
|
protected function supports($attribute, $subject)
|
|
{
|
|
if (
|
|
$subject instanceof Center
|
|
&& in_array($attribute, $this->getAttributes())
|
|
) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private function getAttributes()
|
|
{
|
|
return [self::STATS, self::LISTS];
|
|
}
|
|
}
|