Fix errors in PermittedAttributes::OrderCycle

This commit is contained in:
Matt-Yorkley
2021-03-24 18:22:56 +00:00
committed by Andy Brett
parent 4929b6f1e2
commit 3c864a68d1

View File

@@ -35,23 +35,8 @@ module PermittedAttributes
:tag_list,
tags: [:text],
enterprise_fee_ids: [],
variants: permitted_variant_ids
variants: {}
]
end
# In rails 5 we will be able to permit random hash keys simply with :variants => {}
# See https://github.com/rails/rails/commit/e86524c0c5a26ceec92895c830d1355ae47a7034
#
# Until then, we need to create an array of variant IDs in order to permit them
def permitted_variant_ids
variant_ids(@params[:order_cycle][:incoming_exchanges]) +
variant_ids(@params[:order_cycle][:outgoing_exchanges])
end
def variant_ids(exchange_params)
return [] unless exchange_params
exchange_params.map { |exchange| exchange[:variants].map { |key, _value| key } }.flatten
end
end
end