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

34 lines
959 B
Ruby
Raw Normal View History

2019-06-04 03:40:48 +00:00
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
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