invite.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class FormUpdater::Updater::User::Invite < FormUpdater::Updater
  3. include FormUpdater::Concerns::ChecksCoreWorkflow
  4. core_workflow_screen 'invite_agent'
  5. def authorized?
  6. current_user.permissions?('admin.wizard')
  7. end
  8. def object_type
  9. ::User
  10. end
  11. def resolve
  12. if meta[:initial]
  13. prepare_initial_data
  14. end
  15. super
  16. end
  17. private
  18. def prepare_initial_data
  19. result['role_ids'] = initial_role_ids
  20. result['group_ids'] = initial_group_ids
  21. end
  22. def initial_role_ids
  23. {
  24. options: initial_role_options
  25. }
  26. end
  27. def initial_role_options
  28. Role
  29. .where(active: true)
  30. .reorder(id: :asc)
  31. .map do |elem|
  32. {
  33. value: elem.id,
  34. label: elem.name,
  35. description: elem.note,
  36. }
  37. end
  38. end
  39. def initial_group_ids
  40. {
  41. options: initial_group_options
  42. }
  43. end
  44. def initial_group_options
  45. FormUpdater::Relation::Group.new(
  46. context:,
  47. current_user:,
  48. filter_ids: Group.pluck(:id),
  49. ).options
  50. end
  51. end