roles.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Kayako::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(kayako_role) if kayako_role && respond_to?(kayako_role, true)
  11. logger.debug "Unknown mapping for role '#{resource['role']['type']}' (method: #{kayako_role})"
  12. customer
  13. end
  14. def kayako_role
  15. @kayako_role ||= resource['role']&.fetch('type')&.downcase
  16. end
  17. def customer
  18. [role_customer]
  19. end
  20. def collaborators
  21. agent
  22. end
  23. def agent
  24. [role_agent]
  25. end
  26. def owner
  27. admin
  28. end
  29. def admin
  30. [role_admin, role_agent]
  31. end
  32. def role_admin
  33. @role_admin ||= lookup('Admin')
  34. end
  35. def role_agent
  36. @role_agent ||= lookup('Agent')
  37. end
  38. def role_customer
  39. @role_customer ||= lookup('Customer')
  40. end
  41. def lookup(role_name)
  42. ::Role.lookup(name: role_name)
  43. end
  44. end