time_accountings_controller_policy.rb 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Controllers::TimeAccountingsControllerPolicy < Controllers::ApplicationControllerPolicy
  3. default_permit!('admin.time_accounting')
  4. def index?
  5. admin_access? || agent_access?
  6. end
  7. def show?
  8. admin_access? || agent_access?
  9. end
  10. def create?
  11. return true if admin_access?
  12. time_accounting = Ticket::TimeAccounting.new(ticket: ticket)
  13. time_accounting_policy = Ticket::TimeAccountingPolicy.new(user, time_accounting)
  14. if !time_accounting_policy.create?
  15. return not_authorized(time_accounting_policy.custom_exception)
  16. end
  17. true
  18. end
  19. private
  20. def admin_access?
  21. user.permissions?('admin.time_accounting')
  22. end
  23. def ticket
  24. @ticket ||= Ticket.find(record.params[:ticket_id])
  25. end
  26. def agent_access?
  27. return false if record.params[:ticket_id].blank?
  28. TicketPolicy.new(user, ticket).agent_update_access?
  29. end
  30. end