has_agent_allowed_params.rb 961 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module HasAgentAllowedParams
  3. extend ActiveSupport::Concern
  4. class_methods do
  5. def agent_allowed_params
  6. agent_allowed_attributes + agent_allowed_nested_relations
  7. end
  8. private
  9. def agent_allowed_attributes
  10. attrs = const_defined?(:AGENT_ALLOWED_ATTRIBUTES) ? const_get(:AGENT_ALLOWED_ATTRIBUTES) : []
  11. [:id] + attrs
  12. end
  13. def agent_allowed_nested_relations
  14. return [] if !const_defined?(:AGENT_ALLOWED_NESTED_RELATIONS)
  15. const_get(:AGENT_ALLOWED_NESTED_RELATIONS).map do |relation_identifier|
  16. key = :"#{relation_identifier}_attributes"
  17. value = reflect_on_association(relation_identifier).klass.agent_allowed_params
  18. if reflect_on_association(relation_identifier).is_a? ActiveRecord::Reflection::HasManyReflection
  19. value << :_destroy
  20. end
  21. { key => value }
  22. end
  23. end
  24. end
  25. end