backend.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class CoreWorkflow::Result::Backend
  3. def initialize(result_object:, field:, perform_config:, skip_rerun: false)
  4. @result_object = result_object
  5. @field = field
  6. @perform_config = perform_config
  7. @skip_rerun = skip_rerun
  8. end
  9. def field
  10. @field.sub(%r{.*\.}, '')
  11. end
  12. def multiple?
  13. @result_object.payload['params'][field].is_a?(Array) || @result_object.attributes.object_elements_hash.dig(field, :multiple)
  14. end
  15. def set_rerun
  16. return if @skip_rerun
  17. @result_object.rerun = true
  18. end
  19. def result(backend, field, value = nil)
  20. @result_object.run_backend_value(backend, field, value)
  21. end
  22. def saved_value
  23. # make sure we have a saved object
  24. return [] if @result_object.attributes.saved_only.blank?
  25. # we only want to have the saved value in the restrictions
  26. # if no changes happend to the form. If the users does changes
  27. # to the form then also the saved value should get removed
  28. return [] if @result_object.attributes.selected.changed?
  29. # attribute can be blank e.g. in custom development
  30. # or if attribute is only available in the frontend but not
  31. # in the backend
  32. return [] if attribute.blank?
  33. Array(@result_object.attributes.saved_attribute_value(attribute)).map(&:to_s)
  34. end
  35. def attribute
  36. @attribute ||= @result_object.attributes.object_elements_hash[field]
  37. end
  38. end