trabajo-afectivo/app/models/concerns/has_agent_allowed_params.rb

35 lines
961 B
Ruby
Raw Permalink Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
2019-06-04 03:40:48 +00:00
module HasAgentAllowedParams
extend ActiveSupport::Concern
class_methods do
def agent_allowed_params
agent_allowed_attributes + agent_allowed_nested_relations
end
private
def agent_allowed_attributes
attrs = const_defined?(:AGENT_ALLOWED_ATTRIBUTES) ? const_get(:AGENT_ALLOWED_ATTRIBUTES) : []
[:id] + attrs
end
def agent_allowed_nested_relations
return [] if !const_defined?(:AGENT_ALLOWED_NESTED_RELATIONS)
const_get(:AGENT_ALLOWED_NESTED_RELATIONS).map do |relation_identifier|
key = :"#{relation_identifier}_attributes"
2019-06-04 03:40:48 +00:00
value = reflect_on_association(relation_identifier).klass.agent_allowed_params
if reflect_on_association(relation_identifier).is_a? ActiveRecord::Reflection::HasManyReflection
value << :_destroy
end
{ key => value }
end
end
end
end