action.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class PerformChanges::Action
  3. include Mixin::RequiredSubPaths
  4. attr_accessor :record, :execution_data, :performable, :origin, :context_data, :user_id
  5. attr_reader :locale, :timezone
  6. def self.action_lookup
  7. @action_lookup ||= descendants.index_by { |action| action.name.demodulize.underscore.to_sym }
  8. end
  9. def self.phase
  10. :before_save
  11. end
  12. def initialize(record, execution_data, perform_changes_data)
  13. @record = record
  14. @execution_data = execution_data
  15. @performable = perform_changes_data[:performable]
  16. @origin = perform_changes_data[:origin]
  17. @context_data = perform_changes_data[:context_data]
  18. @user_id = perform_changes_data[:user_id]
  19. @locale = fetch_locale
  20. @timezone = fetch_timezone
  21. end
  22. def execute(prepared_actions)
  23. raise NotImplementedError
  24. end
  25. private
  26. def id
  27. record.id
  28. end
  29. def notification_factory_template_objects
  30. @notification_factory_template_objects ||= {
  31. record.class.name.downcase.to_sym => record,
  32. }
  33. end
  34. def fetch_locale
  35. locale = @performable.try(:localization)
  36. # Returning nil will use the system default locale in the NotificationFactory classes.
  37. return nil if locale.blank? || locale == 'system'
  38. locale
  39. end
  40. def fetch_timezone
  41. timezone = @performable.try(:timezone)
  42. # Returning nil will use the system default timezone in the NotificationFactory classes.
  43. return nil if timezone.blank? || timezone == 'system'
  44. timezone
  45. end
  46. end