You are here

function support_ticket_support_ticket_access in Support Ticketing System 8

Implements hook_support_ticket_access().

File

modules/support_ticket/support_ticket.module, line 614
Enables use of support tickets with optional time tracking.

Code

function support_ticket_support_ticket_access(SupportTicketInterface $support_ticket, $op, $account) {
  $type = $support_ticket
    ->bundle();
  switch ($op) {
    case 'create':
      return AccessResult::allowedIfHasPermission($account, 'create ' . $type . ' ticket');
    case 'update':
      if ($account
        ->hasPermission('edit any ' . $type . ' ticket', $account)) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      else {
        return AccessResult::allowedIf($account
          ->hasPermission('edit own ' . $type . ' ticket', $account) && $account
          ->id() == $support_ticket
          ->getOwnerId())
          ->cachePerPermissions()
          ->cachePerUser()
          ->cacheUntilEntityChanges($support_ticket);
      }
    case 'delete':
      if ($account
        ->hasPermission('delete any ' . $type . ' ticket', $account)) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      else {
        return AccessResult::allowedIf($account
          ->hasPermission('delete own ' . $type . ' ticket', $account) && $account
          ->id() == $support_ticket
          ->getOwnerId())
          ->cachePerPermissions()
          ->cachePerUser()
          ->cacheUntilEntityChanges($support_ticket);
      }
    default:

      // No opinion.
      return AccessResult::neutral();
  }
}