mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Extract permitted attributes to separate service
This commit is contained in:
@@ -157,18 +157,7 @@ module Admin
|
||||
end
|
||||
|
||||
def subscription_params
|
||||
return params[:subscription] if params[:subscription].empty?
|
||||
|
||||
params.require(:subscription).permit(
|
||||
:id, :shop_id, :schedule_id, :customer_id,
|
||||
:payment_method_id, :shipping_method_id,
|
||||
:begins_at, :ends_at,
|
||||
:canceled_at, :paused_at,
|
||||
:shipping_fee_estimate, :payment_fee_estimate,
|
||||
:subscription_line_items_attributes => [:id, :quantity, :variant_id, :price_estimate, :_destroy],
|
||||
:bill_address_attributes => permitted_address_attributes,
|
||||
:ship_address_attributes => permitted_address_attributes
|
||||
)
|
||||
PermittedAttributes::Subscription.new(params).call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
37
app/services/permitted_attributes/subscription.rb
Normal file
37
app/services/permitted_attributes/subscription.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PermittedAttributes
|
||||
class Subscription
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
return @params[:subscription] if @params[:subscription].empty?
|
||||
|
||||
@params.require(:subscription).permit(basic_permitted_attributes + other_permitted_attributes)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def basic_permitted_attributes
|
||||
[
|
||||
:id, :shop_id, :schedule_id, :customer_id,
|
||||
:payment_method_id, :shipping_method_id,
|
||||
:begins_at, :ends_at,
|
||||
:canceled_at, :paused_at,
|
||||
:shipping_fee_estimate, :payment_fee_estimate,
|
||||
]
|
||||
end
|
||||
|
||||
def other_permitted_attributes
|
||||
[
|
||||
subscription_line_items_attributes: [
|
||||
:id, :quantity, :variant_id, :price_estimate, :_destroy
|
||||
],
|
||||
bill_address_attributes: PermittedAttributes::Address.attributes,
|
||||
ship_address_attributes: PermittedAttributes::Address.attributes
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user