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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
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.rbindex 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 Spreebefore_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+ superenddef create@@ -105,8 +102,12 @@ module Spreeprivate- 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)+ endenddef resourcediff --git a/core/app/models/spree/ability.rb b/core/app/models/spree/ability.rbindex 5d018b3b87..ee621b0d5c 100644--- a/core/app/models/spree/ability.rb+++ b/core/app/models/spree/ability.rb@@ -87,7 +87,9 @@ module Spreecan :read, ::Spree::Variantcan :read, ::Spree::Zonecan :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+ endcan [:create, :update, :destroy], ::Spree::WishedItem do |wished_item|wished_item.wishlist.user == userend