diff --git a/app/controllers/admin/subscriptions_controller.rb b/app/controllers/admin/subscriptions_controller.rb index 6b65ddda86..4561ef3a79 100644 --- a/app/controllers/admin/subscriptions_controller.rb +++ b/app/controllers/admin/subscriptions_controller.rb @@ -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 diff --git a/app/services/permitted_attributes/subscription.rb b/app/services/permitted_attributes/subscription.rb new file mode 100644 index 0000000000..2ab3956fca --- /dev/null +++ b/app/services/permitted_attributes/subscription.rb @@ -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