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.

Improve checking user performance in Platform API (#11396)

Damian Legawiec9a898b52cf84
diff --git a/api/app/controllers/spree/api/v2/platform/orders_controller.rb b/api/app/controllers/spree/api/v2/platform/orders_controller.rb
index 1bf216e3c3..5604f79e9a 100644
--- a/api/app/controllers/spree/api/v2/platform/orders_controller.rb
+++ b/api/app/controllers/spree/api/v2/platform/orders_controller.rb
@@ -108,20 +108,6 @@ module Spree
:item_count, :tax_total, :completed_at)
end
- def authorize_spree_user
- return if spree_current_user.nil?
-
- if action_name == 'create'
- spree_authorize! :create, model_class
- elsif %w[show index].include?(action_name)
- spree_authorize! :read, model_class
- elsif %w[next cancel complete empty advance add_store_credit remove_store_credit].include?(action_name)
- spree_authorize! :update, resource
- else
- spree_authorize! action_name, resource
- end
- end
-
def render_order(result)
if result.success?
render_serialized_payload { serialize_resource(resource) }
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 e4a3c071be..fc815818a5 100644
--- a/api/app/controllers/spree/api/v2/platform/resource_controller.rb
+++ b/api/app/controllers/spree/api/v2/platform/resource_controller.rb
@@ -83,12 +83,17 @@ module Spree
def authorize_spree_user
return if spree_current_user.nil?
- if action_name == 'create'
+ case action_name
+ when 'create'
spree_authorize! :create, model_class
- elsif %w[show index].include?(action_name)
+ when 'destroy'
+ spree_authorize! :destroy, resource
+ when 'index'
spree_authorize! :read, model_class
+ when 'show'
+ spree_authorize! :read, resource
else
- spree_authorize! action_name, resource
+ spree_authorize! :update, resource
end
end