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