2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://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|
|
2020-08-21 08:18:31 +00:00
|
|
|
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
|