vendor\uvdesk\core-framework\Security\TicketVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Security;
  3. use Symfony\Component\DependencyInjection\ContainerInterface;
  4. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
  7. class TicketVoter extends Voter
  8. {
  9.     const MEMBER_VIEW 'AGENT_VIEW';
  10.     const CUSTOMER_VIEW 'CUSTOMER_VIEW';
  11.     private $container;
  12.     private $decisionManager;
  13.     public function __construct(ContainerInterface $containerAccessDecisionManagerInterface $decisionManager)
  14.     {
  15.         $this->container $container;
  16.         $this->decisionManager $decisionManager;
  17.     }
  18.     protected function supports($attribute$subject)
  19.     {
  20.         if (!in_array($attribute, [self::MEMBER_VIEWself::CUSTOMER_VIEW])) {
  21.             return false;
  22.         }
  23.         return $subject instanceof \Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
  24.     }
  25.     protected function voteOnAttribute($attribute$ticketTokenInterface $token)
  26.     {
  27.         $user $token->getUser();
  28.         if (!$user instanceof \Webkul\UVDesk\SupportBundle\Entity\User) {
  29.             return false;
  30.         }
  31.         
  32.         switch ($attribute) {
  33.             case self::MEMBER_VIEW:
  34.                 if ($this->decisionManager->decide($token, ['ROLE_ADMIN'])) {
  35.                     return true;
  36.                 } else if ($this->decisionManager->decide($token, ['ROLE_AGENT'])) {
  37.                     $userInstance $user->getAgentInstance();
  38.                     dump($userInstance->getTicketAccessLevel());
  39.                     die;
  40.                     // switch ($userInstance->getTicketAccessLevel()) {
  41.                     //     case TICKET::AGENT_GLOBAL_ACCESS:
  42.                     //         return true;
  43.                     //     case TICKET::AGENT_GROUP_ACCESS:
  44.                     //         // $userGroupAccess = (bool)$user->getGroups()->contains($ticket->getGroup());
  45.                     //         // $userTeamAccess = (bool)$user->getUserSubGroup()->contains($ticket->getSubGroup());
  46.                     //         // $access = $userGroupAccess ? $userGroupAccess : $userTeamAccess;
  47.                     //         break;
  48.                     //     case TICKET::AGENT_TEAM_ACCESS:
  49.                     //         // $access = (bool)($user->getUserSubGroup()->contains($ticket->getSubGroup()));
  50.                     //         break;
  51.                     //     case TICKET::AGENT_INDIVIDUAL_ACCESS:
  52.                     //         return (bool) ($user->getId() === $ticket->getAgent()->getId());
  53.                     //         break;
  54.                     //     default:
  55.                     //         break;
  56.                     // }
  57.                 }
  58.                 break;
  59.             case self::CUSTOMER_VIEW:
  60.                 if ($ticket->getIsTrashed()) {
  61.                     return false;
  62.                 }
  63.                 
  64.                 if ($ticket->getCustomer() == $user) {
  65.                     return true;
  66.                 } else {
  67.                     // $flag = 0;
  68.                     // $collaborators = $ticket->getCollaborators();
  69.                     // if(count($collaborators)) {
  70.                     //     foreach ($collaborators as $collaborator) {
  71.                     //         if($collaborator == $user)
  72.                     //             $flag = 1;
  73.                     //     }
  74.                     //     if($flag)
  75.                     //         return true;    
  76.                     //     else
  77.                     //         return false;    
  78.                     // }
  79.                 }
  80.                 
  81.                 break;
  82.             default:
  83.                 break;
  84.         }
  85.         return false;
  86.     }
  87.     // protected function isGranted($attribute, $ticket, $user = null)
  88.     // {
  89.     //     if (!is_object($user)) {
  90.     //         return false;
  91.     //     }
  92.         
  93.     //     if($attribute == 'FRONT_VIEW') {
  94.     //         if($ticket->getIsTrashed())
  95.     //             return false;
  96.     //         if($ticket->getCustomer() == $user)
  97.     //             return true;
  98.     //         else {
  99.     //             $flag = 0;
  100.     //             $collaborators = $ticket->getCollaborators();
  101.     //             if(count($collaborators)) {
  102.     //                 foreach ($collaborators as $collaborator) {
  103.     //                     if($collaborator == $user)
  104.     //                         $flag = 1;
  105.     //                 }
  106.     //                 if($flag)
  107.     //                     return true;    
  108.     //                 else
  109.     //                     return false;    
  110.     //             }
  111.     //         } 
  112.     //     } else {
  113.             // if($user->getRole() == 'ROLE_AGENT') {
  114.             //     switch($user->getDetail()['agent']->getTicketView()){
  115.             //         case UserData::GLOBAL_ACCESS:
  116.             //             $access = true;
  117.             //         break;
  118.             //         case UserData::GROUP_ACCESS:
  119.             //             $userGroupAccess = (bool)$user->getGroups()->contains($ticket->getGroup());
  120.             //             $userTeamAccess = (bool)$user->getUserSubGroup()->contains($ticket->getSubGroup());
  121.             //             $access = $userGroupAccess ? $userGroupAccess : $userTeamAccess;
  122.             //         break;
  123.             //         case UserData::TEAM_ACCESS:
  124.             //             $access = (bool)($user->getUserSubGroup()->contains($ticket->getSubGroup()));
  125.             //         break;
  126.             //         case UserData::INDIVIDUAL_ACCESS:
  127.             //         default:
  128.             //             $access = (bool)($ticket->getAgent() == $user);
  129.             //         break;
  130.             //     }
  131.             //     if(!$access)
  132.             //         $access = (bool)($ticket->getAgent() == $user);
  133.             //     return $access;    
  134.             //     // if($ticket->getAgent() == $user)
  135.             //     //     return true;
  136.             //     // else {
  137.             //     //     $flag = 0;
  138.             //     //     $agentGroups = $user->getGroups();
  139.             //     //     if($ticket->getGroup()) {
  140.             //     //         foreach ($agentGroups as $group) {
  141.             //     //             if($group->getId() == $ticket->getGroup()->getId())
  142.             //     //                 $flag = 1;
  143.             //     //         }
  144.             //     //         if($flag)
  145.             //     //             return true;    
  146.             //     //         else
  147.             //     //             return false;    
  148.             //     //     } else {
  149.                         
  150.             //     //     }
  151.             //     // } 
  152.             // } else {
  153.             //     return true;
  154.             // }
  155.     //     }
  156.     // }
  157. }