src/Security/Voter/OficinaVoter.php line 8
- <?php
- namespace App\Security\Voter;
- use Symfony\Component\Security\Core\Authorization\Voter\Voter;
- use App\Entity\Oficina;
- class OficinaVoter extends Voter
- {
- public function supports($attribute, $subject): bool
- {
- /* if ($subject) {
- var_dump(get_class($subject));echo "-";
- var_dump(($subject instanceof User));echo "#";
- } */
- return $subject instanceof Oficina && in_array($attribute, array(
- 'ROLE_APP_ADMIN_OFICINA_EDIT',
- 'ROLE_APP_ADMIN_OFICINA_LIST',
- ));
- }
- protected function voteOnAttribute($attribute, $object, $token): bool
- {
- // echo $attribute;
- // return true;
- $user = $token->getUser();
- if ($user->hasRole('ROLE_SUPER_ADMIN') or $user->hasRole('ROLE_ADMIN')) { //Acceso de super admin o administrador
- return true;
- }
- // los managers solo puede editar su oficina
- if ((in_array($attribute, ['ROLE_APP_ADMIN_OFICINA_EDIT']) and $user->hasRole('ROLE_MANAGER') and $object->getId() == $user->getOficinaGestion()->getId()) or in_array($attribute, ['ROLE_APP_ADMIN_OFICINA_LIST'])) {
- return true;
- }
- return false;
- }
- }