Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Allow to pass all model parameters in Platform API and drop reliance on Spree::PermittedAttributes

Damian Legawiec42ac5efe54ae
diff --git a/api/app/controllers/spree/api/v2/platform/resource_controller.rb b/api/app/controllers/spree/api/v2/platform/resource_controller.rb
index cff1095c4f..17798fcc96 100644
--- a/api/app/controllers/spree/api/v2/platform/resource_controller.rb
+++ b/api/app/controllers/spree/api/v2/platform/resource_controller.rb
@@ -98,7 +98,7 @@ module Spree
end
def spree_permitted_attributes
- Spree::PermittedAttributes.try("#{model_param_name}_attributes") || {}
+ model_class.json_api_permitted_attributes
end
def permitted_resource_params
diff --git a/core/app/models/spree/base.rb b/core/app/models/spree/base.rb
index cf05b0e7af..f574311dde 100644
--- a/core/app/models/spree/base.rb
+++ b/core/app/models/spree/base.rb
@@ -49,6 +49,10 @@ class Spree::Base < ApplicationRecord
column_names.reject { |c| c.match(/_id$|id|preferences|(.*)password|(.*)token|(.*)api_key/) }
end
+ def self.json_api_permitted_attributes
+ column_names.reject { |c| c == 'id' }
+ end
+
def self.json_api_type
to_s.demodulize.underscore
end
diff --git a/core/spec/models/spree/base_spec.rb b/core/spec/models/spree/base_spec.rb
index a5bfad10c4..0578f7d9e3 100644
--- a/core/spec/models/spree/base_spec.rb
+++ b/core/spec/models/spree/base_spec.rb
@@ -58,4 +58,8 @@ describe Spree::Base do
it { expect(Spree::Address.json_api_columns).to contain_exactly('address1', 'address2', 'alternative_phone', 'city', 'company', 'created_at', 'deleted_at', 'firstname', 'label', 'lastname', 'phone', 'state_name', 'updated_at', 'zipcode') }
it { expect(Spree::Address.json_api_columns).not_to include('country_id') }
end
+
+ describe '.json_api_permitted_attributes' do
+ it { expect(Spree::Address.json_api_permitted_attributes).to contain_exactly('firstname', 'lastname', 'address1', 'address2', 'city', 'zipcode', 'phone', 'state_name', 'alternative_phone', 'company', 'state_id', 'country_id', 'created_at', 'updated_at', 'user_id', 'deleted_at', 'label') }
+ end
end