time_accounting_policy.rb 668 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Ticket::TimeAccountingPolicy < ApplicationPolicy
  3. def create?
  4. if !Setting.get 'time_accounting'
  5. return not_authorized __('Time Accounting is not enabled')
  6. end
  7. if !matches_selector?
  8. return not_authorized __('Ticket does not match Time Accounting Selector')
  9. end
  10. ticket_update_access?
  11. end
  12. private
  13. def ticket_update_access?
  14. TicketPolicy.new(user, record.ticket).update?
  15. end
  16. def matches_selector?
  17. CoreWorkflow.matches_selector?(id: record.id, user: user, selector: Setting.get('time_accounting_selector')[:condition] || {})
  18. end
  19. end