mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
Extract permitted attributes to separate service
This commit is contained in:
@@ -305,23 +305,7 @@ module Admin
|
||||
end
|
||||
|
||||
def enterprise_params
|
||||
return params[:enterprise] if params[:enterprise].empty?
|
||||
|
||||
params.require(:enterprise).permit(
|
||||
:id, :name, :is_primary_producer, :visible, :permalink,
|
||||
:contact_name, :email_address, :phone, :sells, :owner_id,
|
||||
:website, :facebook, :instagram, :linkedin, :twitter,
|
||||
:abn, :acn, :charges_sales_tax, :display_invoice_logo,
|
||||
:invoice_text, :description, :long_description, :logo, :promo_image,
|
||||
:preferred_product_selection_from_inventory_only, :preferred_shopfront_message,
|
||||
:preferred_shopfront_closed_message, :preferred_shopfront_taxon_order,
|
||||
:preferred_shopfront_order_cycle_order, :require_login,
|
||||
:allow_guest_orders, :allow_order_changes, :enable_subscriptions,
|
||||
group_ids: [], user_ids: [],
|
||||
shipping_method_ids: [], payment_method_ids: [],
|
||||
address_attributes: PermittedAttributes::Address.attributes,
|
||||
producer_properties_attributes: [:id, :property_name, :value, :_destroy]
|
||||
)
|
||||
PermittedAttributes::Enterprise.new(params).call
|
||||
end
|
||||
|
||||
# Used in ResourceController#create
|
||||
|
||||
37
app/services/permitted_attributes/enterprise.rb
Normal file
37
app/services/permitted_attributes/enterprise.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PermittedAttributes
|
||||
class Enterprise
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
return @params[:enterprise] if @params[:enterprise].empty?
|
||||
|
||||
@params.require(:enterprise).permit(
|
||||
basic_permitted_attributes + [
|
||||
group_ids: [], user_ids: [],
|
||||
shipping_method_ids: [], payment_method_ids: [],
|
||||
address_attributes: PermittedAttributes::Address.attributes,
|
||||
producer_properties_attributes: [:id, :property_name, :value, :_destroy]
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def basic_permitted_attributes
|
||||
[
|
||||
:id, :name, :visible, :permalink, :owner_id, :contact_name, :email_address, :phone,
|
||||
:is_primary_producer, :sells, :website, :facebook, :instagram, :linkedin, :twitter,
|
||||
:description, :long_description, :logo, :promo_image,
|
||||
:allow_guest_orders, :allow_order_changes, :require_login, :enable_subscriptions,
|
||||
:abn, :acn, :charges_sales_tax, :display_invoice_logo, :invoice_text,
|
||||
:preferred_product_selection_from_inventory_only, :preferred_shopfront_message,
|
||||
:preferred_shopfront_closed_message, :preferred_shopfront_taxon_order,
|
||||
:preferred_shopfront_order_cycle_order
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user