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.

Alternate method of using cancan on show action.

Matthew Kennedy84ff9009d421
diff --git a/api/app/controllers/spree/api/v2/storefront/wishlists_controller.rb b/api/app/controllers/spree/api/v2/storefront/wishlists_controller.rb
index f1b04db322..ee1939271f 100644
--- a/api/app/controllers/spree/api/v2/storefront/wishlists_controller.rb
+++ b/api/app/controllers/spree/api/v2/storefront/wishlists_controller.rb
@@ -7,11 +7,8 @@ module Spree
before_action :ensure_valid_quantity, only: [:add_item, :set_item_quantity]
def show
- @resource ||= current_store.wishlists.find_by!(token: params[:id])
-
- spree_authorize! :read, @resource
-
- render_serialized_payload { serialize_resource(@resource) }
+ spree_authorize! :show, resource
+ super
end
def create
@@ -105,8 +102,12 @@ module Spree
private
- def scope
- super.where(user: spree_current_user)
+ def scope(skip_cancancan: true)
+ if action_name == 'show'
+ super
+ else
+ super.where(user: spree_current_user)
+ end
end
def resource
diff --git a/core/app/models/spree/ability.rb b/core/app/models/spree/ability.rb
index 5d018b3b87..ee621b0d5c 100644
--- a/core/app/models/spree/ability.rb
+++ b/core/app/models/spree/ability.rb
@@ -87,7 +87,9 @@ module Spree
can :read, ::Spree::Variant
can :read, ::Spree::Zone
can :manage, ::Spree::Wishlist, user_id: user.id
- can :read, ::Spree::Wishlist, is_private: false
+ can :show, ::Spree::Wishlist do |wishlist|
+ wishlist.user == user || wishlist.is_private == false
+ end
can [:create, :update, :destroy], ::Spree::WishedItem do |wished_item|
wished_item.wishlist.user == user
end