parent
dba5cafde8
commit
57eded82c0
@ -0,0 +1,83 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Security\Authorization\Voter; |
||||
|
||||
use Chamilo\CoreBundle\Entity\AbstractResource; |
||||
use Chamilo\CoreBundle\Entity\ResourceNode; |
||||
use Symfony\Component\HttpFoundation\RequestStack; |
||||
use Symfony\Component\Security\Acl\Permission\MaskBuilder; |
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter; |
||||
use Symfony\Component\Security\Core\Security; |
||||
|
||||
class ResourceVoter extends Voter |
||||
{ |
||||
public const VIEW = 'VIEW'; |
||||
public const CREATE = 'CREATE'; |
||||
public const EDIT = 'EDIT'; |
||||
public const DELETE = 'DELETE'; |
||||
public const EXPORT = 'EXPORT'; |
||||
|
||||
private $requestStack; |
||||
private $security; |
||||
|
||||
public function __construct(Security $security, RequestStack $requestStack) |
||||
{ |
||||
$this->security = $security; |
||||
$this->requestStack = $requestStack; |
||||
} |
||||
|
||||
public static function getReaderMask(): int |
||||
{ |
||||
$builder = new MaskBuilder(); |
||||
$builder |
||||
->add(self::VIEW) |
||||
; |
||||
|
||||
return $builder->get(); |
||||
} |
||||
|
||||
public static function getEditorMask(): int |
||||
{ |
||||
$builder = new MaskBuilder(); |
||||
$builder |
||||
->add(self::VIEW) |
||||
->add(self::EDIT) |
||||
; |
||||
|
||||
return $builder->get(); |
||||
} |
||||
|
||||
protected function supports(string $attribute, $subject): bool |
||||
{ |
||||
$options = [ |
||||
self::VIEW, |
||||
self::CREATE, |
||||
self::EDIT, |
||||
self::DELETE, |
||||
self::EXPORT, |
||||
]; |
||||
error_log('resource supports'); |
||||
// if the attribute isn't one we support, return false |
||||
if (!in_array($attribute, $options)) { |
||||
return false; |
||||
} |
||||
|
||||
// only vote on ResourceNode objects inside this voter |
||||
if (!$subject instanceof AbstractResource) { |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool |
||||
{ |
||||
error_log('resource voteOnAttribute'); |
||||
$user = $token->getUser(); |
||||
|
||||
return true; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue