roles.rb 992 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Zendesk::User::Roles < Sequencer::Unit::Common::Provider::Named
  3. uses :resource, :initiator
  4. private
  5. def roles
  6. return admin if initiator
  7. map_roles
  8. end
  9. def map_roles
  10. return send(zendesk_role) if respond_to?(zendesk_role, true)
  11. logger.error "Unknown mapping for role '#{resource.role.name}' (method: #{zendesk_role})"
  12. end_user
  13. end
  14. def zendesk_role
  15. @zendesk_role ||= resource.role.name.tr('-', '_').to_sym
  16. end
  17. def end_user
  18. [role_customer]
  19. end
  20. def agent
  21. return [role_agent] if resource.restricted_agent
  22. admin
  23. end
  24. def admin
  25. [role_admin, role_agent]
  26. end
  27. def role_admin
  28. @role_admin ||= lookup('Admin')
  29. end
  30. def role_agent
  31. @role_agent ||= lookup('Agent')
  32. end
  33. def role_customer
  34. @role_customer ||= lookup('Customer')
  35. end
  36. def lookup(role_name)
  37. ::Role.lookup(name: role_name)
  38. end
  39. end