group.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class CoreWorkflow::Attributes::Group < CoreWorkflow::Attributes::Base
  3. def values
  4. groups.each do |group|
  5. assets(group)
  6. end
  7. if groups.blank?
  8. ['']
  9. else
  10. groups.pluck(:id)
  11. end
  12. end
  13. def customer_ticket_create_group_ids
  14. Setting.get('customer_ticket_create_group_ids')
  15. end
  16. def groups
  17. @groups ||= if agent_view?
  18. groups_agent
  19. elsif customer_view?
  20. groups_customer
  21. else
  22. groups_default
  23. end
  24. end
  25. def agent_view?
  26. @attributes.payload_class == Ticket && @attributes.user.permissions?('ticket.agent')
  27. end
  28. def customer_view?
  29. @attributes.payload_class == Ticket && @attributes.user.permissions?('ticket.customer') && @attributes.payload['screen'] == 'create_middle' && customer_ticket_create_group_ids.present?
  30. end
  31. def groups_agent
  32. if @attributes.payload['screen'] == 'create_middle'
  33. @attributes.user.groups_access(%w[create])
  34. else
  35. @attributes.user.groups_access(%w[create change])
  36. end
  37. end
  38. def groups_customer
  39. Group.where(id: customer_ticket_create_group_ids, active: true)
  40. end
  41. def groups_default
  42. Group.where(active: true)
  43. end
  44. def assets(group)
  45. return if @attributes.assets == false
  46. return if @attributes.assets[Group.to_app_model] && @attributes.assets[Group.to_app_model][group.id]
  47. @attributes.assets = group.assets(@attributes.assets)
  48. end
  49. end