From 7cbde3b2e0f3ec04225ba037dd6b865f1c0248b8 Mon Sep 17 00:00:00 2001 From: Alessandro Rodi Date: Fri, 10 Jul 2020 17:05:47 +0200 Subject: [PATCH 1/4] Replace custom CanCanCan action aliases with default ones --- .../spree/api/addresses_controller.rb | 2 +- .../controllers/spree/api/base_controller.rb | 6 +- .../spree/api/countries_controller.rb | 4 +- .../spree/api/credit_cards_controller.rb | 4 +- .../spree/api/customer_returns_controller.rb | 6 +- .../spree/api/images_controller.rb | 4 +- .../spree/api/inventory_units_controller.rb | 2 +- .../spree/api/option_types_controller.rb | 6 +- .../spree/api/option_values_controller.rb | 4 +- .../spree/api/orders_controller.rb | 2 +- .../spree/api/payments_controller.rb | 2 +- .../api/product_properties_controller.rb | 6 +- .../spree/api/promotions_controller.rb | 2 +- .../spree/api/properties_controller.rb | 6 +- .../spree/api/resource_controller.rb | 4 +- .../api/return_authorizations_controller.rb | 6 +- .../spree/api/shipments_controller.rb | 2 +- .../spree/api/states_controller.rb | 6 +- .../spree/api/stock_items_controller.rb | 4 +- .../spree/api/stock_locations_controller.rb | 6 +- .../spree/api/stock_movements_controller.rb | 6 +- .../spree/api/stores_controller.rb | 6 +- .../spree/api/taxonomies_controller.rb | 4 +- .../spree/api/taxons_controller.rb | 8 +-- .../controllers/spree/api/users_controller.rb | 2 +- .../spree/api/variants_controller.rb | 4 +- .../controllers/spree/api/zones_controller.rb | 4 +- .../spree/api/shipments_controller_spec.rb | 4 +- .../admin/customer_returns_controller.rb | 4 +- .../spree/admin/promotion_codes_controller.rb | 6 +- .../admin/return_authorizations_controller.rb | 2 +- .../spree/admin/root_controller.rb | 2 +- .../spree/admin/stock_items_controller.rb | 10 ++-- .../spree/admin/customer_returns_helper.rb | 2 +- .../spree/admin/promotions/edit.html.erb | 4 +- .../admin/shared/_order_submenu.html.erb | 8 +-- .../admin/shared/_payments_tabs.html.erb | 2 +- .../shared/_settings_checkout_tabs.html.erb | 10 ++-- .../admin/shared/_settings_sub_menu.html.erb | 12 ++-- .../admin/shared/_shipping_tabs.html.erb | 6 +- .../spree/admin/shared/_taxes_tabs.html.erb | 4 +- .../spree/admin/stock_locations/edit.html.erb | 2 +- .../admin/stock_locations/index.html.erb | 2 +- .../admin/stock_movements/index.html.erb | 2 +- .../views/spree/admin/users/_form.html.erb | 4 +- .../views/spree/admin/users/_tabs.html.erb | 2 +- .../views/spree/admin/variants/index.html.erb | 2 +- .../spree/admin/root_controller_spec.rb | 2 +- backend/spec/features/admin/homepage_spec.rb | 2 +- .../features/admin/orders/listing_spec.rb | 2 +- .../admin/orders/order_details_spec.rb | 6 +- .../orders/return_authorizations_spec.rb | 2 +- .../features/admin/products/products_spec.rb | 2 +- backend/spec/features/admin/users_spec.rb | 2 +- core/app/models/spree/ability.rb | 13 ----- .../permission_sets/configuration_display.rb | 28 +++++----- .../spree/permission_sets/default_customer.rb | 32 +++++------ .../spree/permission_sets/order_display.rb | 22 ++++---- .../spree/permission_sets/order_management.rb | 2 +- .../spree/permission_sets/product_display.rb | 18 +++--- .../permission_sets/promotion_display.rb | 10 ++-- .../restricted_stock_display.rb | 4 +- .../restricted_stock_management.rb | 2 +- .../spree/permission_sets/stock_display.rb | 4 +- .../spree/permission_sets/stock_management.rb | 2 +- .../lib/spree/permission_sets/user_display.rb | 6 +- .../spree/permission_sets/user_management.rb | 6 +- .../spree/testing_support/ability_helpers.rb | 18 +++--- .../core/controller_helpers/auth_spec.rb | 2 +- .../permission_sets/default_customer_spec.rb | 4 +- core/spec/models/spree/ability_spec.rb | 2 + .../permission_sets/configuration_display.rb | 56 +++++++++---------- .../permission_sets/order_display_spec.rb | 40 ++++++------- .../permission_sets/order_management_spec.rb | 4 +- .../permission_sets/product_display_spec.rb | 36 ++++++------ .../permission_sets/promotion_display_spec.rb | 22 ++++---- .../restricted_stock_display_spec.rb | 16 +++--- .../restricted_stock_management_spec.rb | 8 +-- .../permission_sets/stock_display_spec.rb | 8 +-- .../permission_sets/stock_management_spec.rb | 4 +- .../permission_sets/user_display_spec.rb | 12 ++-- .../permission_sets/user_management_spec.rb | 6 +- .../controllers/spree/orders_controller.rb | 4 +- .../spree/orders_controller_ability_spec.rb | 6 +- 84 files changed, 306 insertions(+), 317 deletions(-) diff --git a/api/app/controllers/spree/api/addresses_controller.rb b/api/app/controllers/spree/api/addresses_controller.rb index 0a7b9922644..e8f8ac2e63f 100644 --- a/api/app/controllers/spree/api/addresses_controller.rb +++ b/api/app/controllers/spree/api/addresses_controller.rb @@ -6,7 +6,7 @@ class AddressesController < Spree::Api::BaseController before_action :find_order def show - authorize! :read, @order, order_token + authorize! :show, @order, order_token find_address respond_with(@address) end diff --git a/api/app/controllers/spree/api/base_controller.rb b/api/app/controllers/spree/api/base_controller.rb index 47b84b55249..4da8dcf0d64 100644 --- a/api/app/controllers/spree/api/base_controller.rb +++ b/api/app/controllers/spree/api/base_controller.rb @@ -135,13 +135,13 @@ def find_product(id) def product_scope if can?(:admin, Spree::Product) - scope = Spree::Product.with_discarded.accessible_by(current_ability, :read).includes(*product_includes) + scope = Spree::Product.with_discarded.accessible_by(current_ability).includes(*product_includes) unless params[:show_deleted] scope = scope.not_deleted end else - scope = Spree::Product.accessible_by(current_ability, :read).available.includes(*product_includes) + scope = Spree::Product.accessible_by(current_ability).available.includes(*product_includes) end scope @@ -161,7 +161,7 @@ def order_id def authorize_for_order @order = Spree::Order.find_by(number: order_id) - authorize! :read, @order, order_token + authorize! :show, @order, order_token end def lock_order diff --git a/api/app/controllers/spree/api/countries_controller.rb b/api/app/controllers/spree/api/countries_controller.rb index 7106af9f059..dc9a7845fe7 100644 --- a/api/app/controllers/spree/api/countries_controller.rb +++ b/api/app/controllers/spree/api/countries_controller.rb @@ -7,7 +7,7 @@ class CountriesController < Spree::Api::BaseController def index @countries = Spree::Country. - accessible_by(current_ability, :read). + accessible_by(current_ability). ransack(params[:q]). result. order('name ASC') @@ -21,7 +21,7 @@ def index end def show - @country = Spree::Country.accessible_by(current_ability, :read).find(params[:id]) + @country = Spree::Country.accessible_by(current_ability, :show).find(params[:id]) respond_with(@country) end end diff --git a/api/app/controllers/spree/api/credit_cards_controller.rb b/api/app/controllers/spree/api/credit_cards_controller.rb index d4fecd3787f..30f4f247d1c 100644 --- a/api/app/controllers/spree/api/credit_cards_controller.rb +++ b/api/app/controllers/spree/api/credit_cards_controller.rb @@ -9,7 +9,7 @@ class CreditCardsController < Spree::Api::BaseController def index @credit_cards = user .credit_cards - .accessible_by(current_ability, :read) + .accessible_by(current_ability) .with_payment_profile .ransack(params[:q]).result @@ -29,7 +29,7 @@ def update def user if params[:user_id].present? - @user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:user_id]) + @user ||= Spree.user_class.accessible_by(current_ability, :show).find(params[:user_id]) end end diff --git a/api/app/controllers/spree/api/customer_returns_controller.rb b/api/app/controllers/spree/api/customer_returns_controller.rb index 0f38bd689db..6bc4b769896 100644 --- a/api/app/controllers/spree/api/customer_returns_controller.rb +++ b/api/app/controllers/spree/api/customer_returns_controller.rb @@ -23,7 +23,7 @@ def index @customer_returns = @order. customer_returns. - accessible_by(current_ability, :read). + accessible_by(current_ability). ransack(params[:q]). result @@ -38,7 +38,7 @@ def new def show authorize! :show, CustomerReturn - @customer_return = @order.customer_returns.accessible_by(current_ability, :read).find(params[:id]) + @customer_return = @order.customer_returns.accessible_by(current_ability, :show).find(params[:id]) respond_with(@customer_return) end @@ -56,7 +56,7 @@ def update def load_order @order ||= Spree::Order.find_by!(number: order_id) - authorize! :read, @order + authorize! :show, @order end def customer_return_params diff --git a/api/app/controllers/spree/api/images_controller.rb b/api/app/controllers/spree/api/images_controller.rb index c18a9b757d1..3ec65e1f7fa 100644 --- a/api/app/controllers/spree/api/images_controller.rb +++ b/api/app/controllers/spree/api/images_controller.rb @@ -4,12 +4,12 @@ module Spree module Api class ImagesController < Spree::Api::BaseController def index - @images = scope.images.accessible_by(current_ability, :read) + @images = scope.images.accessible_by(current_ability) respond_with(@images) end def show - @image = scope.images.accessible_by(current_ability, :read).find(params[:id]) + @image = scope.images.accessible_by(current_ability, :show).find(params[:id]) respond_with(@image) end diff --git a/api/app/controllers/spree/api/inventory_units_controller.rb b/api/app/controllers/spree/api/inventory_units_controller.rb index 9db00e93b23..7a25ec4fee1 100644 --- a/api/app/controllers/spree/api/inventory_units_controller.rb +++ b/api/app/controllers/spree/api/inventory_units_controller.rb @@ -26,7 +26,7 @@ def update private def inventory_unit - @inventory_unit ||= Spree::InventoryUnit.accessible_by(current_ability, :read).find(params[:id]) + @inventory_unit ||= Spree::InventoryUnit.accessible_by(current_ability, :show).find(params[:id]) end def prepare_event diff --git a/api/app/controllers/spree/api/option_types_controller.rb b/api/app/controllers/spree/api/option_types_controller.rb index 55ebd63d6db..88fa157faf2 100644 --- a/api/app/controllers/spree/api/option_types_controller.rb +++ b/api/app/controllers/spree/api/option_types_controller.rb @@ -5,15 +5,15 @@ module Api class OptionTypesController < Spree::Api::BaseController def index if params[:ids] - @option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability, :read).where(id: params[:ids].split(',')) + @option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability).where(id: params[:ids].split(',')) else - @option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability, :read).load.ransack(params[:q]).result + @option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability).load.ransack(params[:q]).result end respond_with(@option_types) end def show - @option_type = Spree::OptionType.accessible_by(current_ability, :read).find(params[:id]) + @option_type = Spree::OptionType.accessible_by(current_ability, :show).find(params[:id]) respond_with(@option_type) end diff --git a/api/app/controllers/spree/api/option_values_controller.rb b/api/app/controllers/spree/api/option_values_controller.rb index 0f25fa12caf..0feea2337e5 100644 --- a/api/app/controllers/spree/api/option_values_controller.rb +++ b/api/app/controllers/spree/api/option_values_controller.rb @@ -46,9 +46,9 @@ def destroy def scope if params[:option_type_id] - @scope ||= Spree::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability, :read) + @scope ||= Spree::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability) else - @scope ||= Spree::OptionValue.accessible_by(current_ability, :read).load + @scope ||= Spree::OptionValue.accessible_by(current_ability).load end end diff --git a/api/app/controllers/spree/api/orders_controller.rb b/api/app/controllers/spree/api/orders_controller.rb index f07a0a19eda..fab604ec1be 100644 --- a/api/app/controllers/spree/api/orders_controller.rb +++ b/api/app/controllers/spree/api/orders_controller.rb @@ -53,7 +53,7 @@ def empty end def index - authorize! :index, Order + authorize! :admin, Order orders_includes = [ { user: :store_credits }, :line_items, diff --git a/api/app/controllers/spree/api/payments_controller.rb b/api/app/controllers/spree/api/payments_controller.rb index 36785940052..81fc16bca7f 100644 --- a/api/app/controllers/spree/api/payments_controller.rb +++ b/api/app/controllers/spree/api/payments_controller.rb @@ -62,7 +62,7 @@ def void def find_order @order = Spree::Order.find_by(number: order_id) - authorize! :read, @order, order_token + authorize! :show, @order, order_token end def find_payment diff --git a/api/app/controllers/spree/api/product_properties_controller.rb b/api/app/controllers/spree/api/product_properties_controller.rb index d14c7e20d02..97b7f432d64 100644 --- a/api/app/controllers/spree/api/product_properties_controller.rb +++ b/api/app/controllers/spree/api/product_properties_controller.rb @@ -9,7 +9,7 @@ class ProductPropertiesController < Spree::Api::BaseController def index @product_properties = @product. product_properties. - accessible_by(current_ability, :read). + accessible_by(current_ability). ransack(params[:q]). result @@ -54,14 +54,14 @@ def destroy def find_product @product = super(params[:product_id]) - authorize! :read, @product + authorize! :show, @product end def product_property if @product @product_property ||= @product.product_properties.find_by(id: params[:id]) @product_property ||= @product.product_properties.includes(:property).where(spree_properties: { name: params[:id] }).first! - authorize! :read, @product_property + authorize! :show, @product_property end end diff --git a/api/app/controllers/spree/api/promotions_controller.rb b/api/app/controllers/spree/api/promotions_controller.rb index 6f53aecfcf7..3af2a62d212 100644 --- a/api/app/controllers/spree/api/promotions_controller.rb +++ b/api/app/controllers/spree/api/promotions_controller.rb @@ -6,7 +6,7 @@ class PromotionsController < Spree::Api::BaseController before_action :load_promotion def show - authorize! :read, @promotion + authorize! :show, @promotion respond_with(@promotion, default_template: :show) end diff --git a/api/app/controllers/spree/api/properties_controller.rb b/api/app/controllers/spree/api/properties_controller.rb index da74cb2cd78..d1f62d42dc1 100644 --- a/api/app/controllers/spree/api/properties_controller.rb +++ b/api/app/controllers/spree/api/properties_controller.rb @@ -6,7 +6,7 @@ class PropertiesController < Spree::Api::BaseController before_action :find_property, only: [:show, :update, :destroy] def index - @properties = Spree::Property.accessible_by(current_ability, :read) + @properties = Spree::Property.accessible_by(current_ability) if params[:ids] ids = params[:ids].split(",").flatten @@ -59,9 +59,9 @@ def destroy private def find_property - @property = Spree::Property.accessible_by(current_ability, :read).find(params[:id]) + @property = Spree::Property.accessible_by(current_ability, :show).find(params[:id]) rescue ActiveRecord::RecordNotFound - @property = Spree::Property.accessible_by(current_ability, :read).find_by!(name: params[:id]) + @property = Spree::Property.accessible_by(current_ability, :show).find_by!(name: params[:id]) end def property_params diff --git a/api/app/controllers/spree/api/resource_controller.rb b/api/app/controllers/spree/api/resource_controller.rb index 8a7fc54b923..f63a515b244 100644 --- a/api/app/controllers/spree/api/resource_controller.rb +++ b/api/app/controllers/spree/api/resource_controller.rb @@ -4,7 +4,7 @@ class Spree::Api::ResourceController < Spree::Api::BaseController before_action :load_resource, only: [:show, :update, :destroy] def index - collection_scope = model_class.accessible_by(current_ability, :read) + collection_scope = model_class.accessible_by(current_ability) if params[:ids] ids = params[:ids].split(",").flatten collection_scope = collection_scope.where(id: ids) @@ -65,7 +65,7 @@ def destroy protected def load_resource - @object = model_class.accessible_by(current_ability, :read).find(params[:id]) + @object = model_class.accessible_by(current_ability, :show).find(params[:id]) instance_variable_set("@#{object_name}", @object) end diff --git a/api/app/controllers/spree/api/return_authorizations_controller.rb b/api/app/controllers/spree/api/return_authorizations_controller.rb index 72fb2a2b7b2..718e5119b0c 100644 --- a/api/app/controllers/spree/api/return_authorizations_controller.rb +++ b/api/app/controllers/spree/api/return_authorizations_controller.rb @@ -29,7 +29,7 @@ def index @return_authorizations = @order. return_authorizations. - accessible_by(current_ability, :read). + accessible_by(current_ability). ransack(params[:q]). result @@ -44,7 +44,7 @@ def new def show authorize! :admin, ReturnAuthorization - @return_authorization = @order.return_authorizations.accessible_by(current_ability, :read).find(params[:id]) + @return_authorization = @order.return_authorizations.accessible_by(current_ability, :show).find(params[:id]) respond_with(@return_authorization) end @@ -70,7 +70,7 @@ def cancel def load_order @order ||= Spree::Order.find_by!(number: order_id) - authorize! :read, @order + authorize! :show, @order end def return_authorization_params diff --git a/api/app/controllers/spree/api/shipments_controller.rb b/api/app/controllers/spree/api/shipments_controller.rb index 3dd16a42294..0a6b20facdb 100644 --- a/api/app/controllers/spree/api/shipments_controller.rb +++ b/api/app/controllers/spree/api/shipments_controller.rb @@ -132,7 +132,7 @@ def load_transfer_params def find_order_on_create @order = Spree::Order.find_by!(number: params[:shipment][:order_id]) - authorize! :read, @order + authorize! :show, @order end def find_shipment diff --git a/api/app/controllers/spree/api/states_controller.rb b/api/app/controllers/spree/api/states_controller.rb index 808529df0e1..87f96aa8ed7 100644 --- a/api/app/controllers/spree/api/states_controller.rb +++ b/api/app/controllers/spree/api/states_controller.rb @@ -25,10 +25,10 @@ def show def scope if params[:country_id] - @country = Spree::Country.accessible_by(current_ability, :read).find(params[:country_id]) - @country.states.accessible_by(current_ability, :read) + @country = Spree::Country.accessible_by(current_ability, :show).find(params[:country_id]) + @country.states.accessible_by(current_ability) else - Spree::State.accessible_by(current_ability, :read) + Spree::State.accessible_by(current_ability) end end end diff --git a/api/app/controllers/spree/api/stock_items_controller.rb b/api/app/controllers/spree/api/stock_items_controller.rb index 16801ca188b..6fddc0999fb 100644 --- a/api/app/controllers/spree/api/stock_items_controller.rb +++ b/api/app/controllers/spree/api/stock_items_controller.rb @@ -58,12 +58,12 @@ def destroy private def load_stock_location - @stock_location ||= Spree::StockLocation.accessible_by(current_ability).find(params.fetch(:stock_location_id)) + @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :show).find(params.fetch(:stock_location_id)) end def scope includes = { variant: [{ option_values: :option_type }, :product] } - @stock_location.stock_items.accessible_by(current_ability, :read).includes(includes) + @stock_location.stock_items.accessible_by(current_ability).includes(includes) end def stock_item_params diff --git a/api/app/controllers/spree/api/stock_locations_controller.rb b/api/app/controllers/spree/api/stock_locations_controller.rb index 2c85f8ca745..37892c5b615 100644 --- a/api/app/controllers/spree/api/stock_locations_controller.rb +++ b/api/app/controllers/spree/api/stock_locations_controller.rb @@ -4,10 +4,10 @@ module Spree module Api class StockLocationsController < Spree::Api::BaseController def index - authorize! :read, StockLocation + authorize! :index, StockLocation @stock_locations = StockLocation. - accessible_by(current_ability, :read). + accessible_by(current_ability). order('name ASC'). ransack(params[:q]). result @@ -49,7 +49,7 @@ def destroy private def stock_location - @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:id]) + @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :show).find(params[:id]) end def stock_location_params diff --git a/api/app/controllers/spree/api/stock_movements_controller.rb b/api/app/controllers/spree/api/stock_movements_controller.rb index 0ac7fb7985b..d6946f77d2a 100644 --- a/api/app/controllers/spree/api/stock_movements_controller.rb +++ b/api/app/controllers/spree/api/stock_movements_controller.rb @@ -6,7 +6,7 @@ class StockMovementsController < Spree::Api::BaseController before_action :stock_location, except: [:update, :destroy] def index - authorize! :read, StockMovement + authorize! :index, StockMovement @stock_movements = paginate(scope.ransack(params[:q]).result) respond_with(@stock_movements) end @@ -29,11 +29,11 @@ def create private def stock_location - @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id]) + @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :show).find(params[:stock_location_id]) end def scope - @stock_location.stock_movements.accessible_by(current_ability, :read) + @stock_location.stock_movements.accessible_by(current_ability) end def stock_movement_params diff --git a/api/app/controllers/spree/api/stores_controller.rb b/api/app/controllers/spree/api/stores_controller.rb index 1dfeb7d0517..edf1a2455ef 100644 --- a/api/app/controllers/spree/api/stores_controller.rb +++ b/api/app/controllers/spree/api/stores_controller.rb @@ -6,8 +6,8 @@ class StoresController < Spree::Api::BaseController before_action :get_store, except: [:index, :create] def index - authorize! :read, Store - @stores = Spree::Store.accessible_by(current_ability, :read).all + authorize! :index, Store + @stores = Spree::Store.accessible_by(current_ability).all respond_with(@stores) end @@ -32,7 +32,7 @@ def update end def show - authorize! :read, @store + authorize! :show, @store respond_with(@store) end diff --git a/api/app/controllers/spree/api/taxonomies_controller.rb b/api/app/controllers/spree/api/taxonomies_controller.rb index 28e1815537f..0874d39a918 100644 --- a/api/app/controllers/spree/api/taxonomies_controller.rb +++ b/api/app/controllers/spree/api/taxonomies_controller.rb @@ -50,7 +50,7 @@ def destroy def taxonomies @taxonomies = Taxonomy. - accessible_by(current_ability, :read). + accessible_by(current_ability). order('name'). includes(root: :children). ransack(params[:q]). @@ -58,7 +58,7 @@ def taxonomies end def taxonomy - @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read). + @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :show). includes(root: :children). find(params[:id]) end diff --git a/api/app/controllers/spree/api/taxons_controller.rb b/api/app/controllers/spree/api/taxons_controller.rb index 10a7ee5e379..f5445f6b0fe 100644 --- a/api/app/controllers/spree/api/taxons_controller.rb +++ b/api/app/controllers/spree/api/taxons_controller.rb @@ -7,9 +7,9 @@ def index if taxonomy @taxons = taxonomy.root.children elsif params[:ids] - @taxons = Spree::Taxon.accessible_by(current_ability, :read).where(id: params[:ids].split(',')) + @taxons = Spree::Taxon.accessible_by(current_ability).where(id: params[:ids].split(',')) else - @taxons = Spree::Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result + @taxons = Spree::Taxon.accessible_by(current_ability).order(:taxonomy_id, :lft).ransack(params[:q]).result end unless params[:without_children] @@ -96,12 +96,12 @@ def default_per_page def taxonomy if params[:taxonomy_id].present? - @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id]) + @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :show).find(params[:taxonomy_id]) end end def taxon - @taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id]) + @taxon ||= taxonomy.taxons.accessible_by(current_ability, :show).find(params[:id]) end def taxon_params diff --git a/api/app/controllers/spree/api/users_controller.rb b/api/app/controllers/spree/api/users_controller.rb index 3ef14787b54..173a0906080 100644 --- a/api/app/controllers/spree/api/users_controller.rb +++ b/api/app/controllers/spree/api/users_controller.rb @@ -2,7 +2,7 @@ class Spree::Api::UsersController < Spree::Api::ResourceController def index - user_scope = model_class.accessible_by(current_ability, :read) + user_scope = model_class.accessible_by(current_ability, :show) if params[:ids] ids = params[:ids].split(",").flatten @users = user_scope.where(id: ids) diff --git a/api/app/controllers/spree/api/variants_controller.rb b/api/app/controllers/spree/api/variants_controller.rb index 79b7d600433..c03f6147a09 100644 --- a/api/app/controllers/spree/api/variants_controller.rb +++ b/api/app/controllers/spree/api/variants_controller.rb @@ -53,7 +53,7 @@ def update private def product - @product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id] + @product ||= Spree::Product.accessible_by(current_ability, :show).friendly.find(params[:product_id]) if params[:product_id] end def scope @@ -69,7 +69,7 @@ def scope in_stock_only = ActiveRecord::Type::Boolean.new.cast(params[:in_stock_only]) suppliable_only = ActiveRecord::Type::Boolean.new.cast(params[:suppliable_only]) - variants = variants.accessible_by(current_ability, :read) + variants = variants.accessible_by(current_ability) if in_stock_only || cannot?(:view_out_of_stock, Spree::Variant) variants = variants.in_stock elsif suppliable_only diff --git a/api/app/controllers/spree/api/zones_controller.rb b/api/app/controllers/spree/api/zones_controller.rb index 3cee1e62470..9e5f47838ca 100644 --- a/api/app/controllers/spree/api/zones_controller.rb +++ b/api/app/controllers/spree/api/zones_controller.rb @@ -21,7 +21,7 @@ def destroy def index @zones = Spree::Zone. - accessible_by(current_ability, :read). + accessible_by(current_ability). order('name ASC'). ransack(params[:q]). result @@ -55,7 +55,7 @@ def zone_params end def zone - @zone ||= Spree::Zone.accessible_by(current_ability, :read).find(params[:id]) + @zone ||= Spree::Zone.accessible_by(current_ability, :show).find(params[:id]) end end end diff --git a/api/spec/requests/spree/api/shipments_controller_spec.rb b/api/spec/requests/spree/api/shipments_controller_spec.rb index 6abb5d3b060..cbd9787b543 100644 --- a/api/spec/requests/spree/api/shipments_controller_spec.rb +++ b/api/spec/requests/spree/api/shipments_controller_spec.rb @@ -458,7 +458,7 @@ let(:user) { create(:user, spree_api_key: 'abc123') } custom_authorization! do |_| - can :read, Spree::Shipment + can :show, Spree::Shipment cannot :update, Spree::Shipment can :create, Spree::Shipment can :destroy, Spree::Shipment @@ -474,7 +474,7 @@ let(:user) { create(:user, spree_api_key: 'abc123') } custom_authorization! do |_| - can :read, Spree::Shipment + can :show, Spree::Shipment can :update, Spree::Shipment cannot :destroy, Spree::Shipment can :create, Spree::Shipment diff --git a/backend/app/controllers/spree/admin/customer_returns_controller.rb b/backend/app/controllers/spree/admin/customer_returns_controller.rb index a1201399f68..be4303077eb 100644 --- a/backend/app/controllers/spree/admin/customer_returns_controller.rb +++ b/backend/app/controllers/spree/admin/customer_returns_controller.rb @@ -37,13 +37,13 @@ def build_resource end def find_resource - Spree::CustomerReturn.accessible_by(current_ability, :read).find(params[:id]) + Spree::CustomerReturn.accessible_by(current_ability, :show).find(params[:id]) end def collection parent # trigger loading the order @collection ||= Spree::ReturnItem - .accessible_by(current_ability, :read) + .accessible_by(current_ability) .where(inventory_unit_id: @order.inventory_units.pluck(:id)) .map(&:customer_return).uniq.compact @customer_returns = @collection diff --git a/backend/app/controllers/spree/admin/promotion_codes_controller.rb b/backend/app/controllers/spree/admin/promotion_codes_controller.rb index 6ee3601c6cb..b426c3e27b6 100644 --- a/backend/app/controllers/spree/admin/promotion_codes_controller.rb +++ b/backend/app/controllers/spree/admin/promotion_codes_controller.rb @@ -6,7 +6,7 @@ module Spree module Admin class PromotionCodesController < Spree::Admin::ResourceController def index - @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id]) + @promotion = Spree::Promotion.accessible_by(current_ability, :show).find(params[:promotion_id]) @promotion_codes = @promotion.promotion_codes.order(:value) respond_to do |format| @@ -22,7 +22,7 @@ def index end def new - @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id]) + @promotion = Spree::Promotion.accessible_by(current_ability, :show).find(params[:promotion_id]) if @promotion.apply_automatically flash[:error] = t('activerecord.errors.models.spree/promotion_code.attributes.base.disallowed_with_apply_automatically') redirect_to admin_promotion_promotion_codes_url(@promotion) @@ -32,7 +32,7 @@ def new end def create - @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id]) + @promotion = Spree::Promotion.accessible_by(current_ability, :show).find(params[:promotion_id]) @promotion_code = @promotion.promotion_codes.build(value: params[:promotion_code][:value]) if @promotion_code.save diff --git a/backend/app/controllers/spree/admin/return_authorizations_controller.rb b/backend/app/controllers/spree/admin/return_authorizations_controller.rb index df85dd7370a..9955343ceaa 100644 --- a/backend/app/controllers/spree/admin/return_authorizations_controller.rb +++ b/backend/app/controllers/spree/admin/return_authorizations_controller.rb @@ -47,7 +47,7 @@ def load_return_items end def load_reimbursement_types - @reimbursement_types = Spree::ReimbursementType.accessible_by(current_ability, :read).active + @reimbursement_types = Spree::ReimbursementType.accessible_by(current_ability).active end def load_return_reasons diff --git a/backend/app/controllers/spree/admin/root_controller.rb b/backend/app/controllers/spree/admin/root_controller.rb index 2bcad02e5ae..40643d52ef3 100644 --- a/backend/app/controllers/spree/admin/root_controller.rb +++ b/backend/app/controllers/spree/admin/root_controller.rb @@ -12,7 +12,7 @@ def index private def admin_root_redirect_path - if can?(:display, Spree::Order) && can?(:admin, Spree::Order) + if can?(:show, Spree::Order) && can?(:admin, Spree::Order) spree.admin_orders_path elsif can?(:admin, :dashboards) && can?(:home, :dashboards) spree.home_admin_dashboards_path diff --git a/backend/app/controllers/spree/admin/stock_items_controller.rb b/backend/app/controllers/spree/admin/stock_items_controller.rb index ae4d480f331..19d5dff7886 100644 --- a/backend/app/controllers/spree/admin/stock_items_controller.rb +++ b/backend/app/controllers/spree/admin/stock_items_controller.rb @@ -15,8 +15,8 @@ class StockItemsController < ResourceController private def build_resource - variant = Spree::Variant.accessible_by(current_ability, :read).find(params[:variant_id]) - stock_location = Spree::StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id]) + variant = Spree::Variant.accessible_by(current_ability, :show).find(params[:variant_id]) + stock_location = Spree::StockLocation.accessible_by(current_ability, :show).find(params[:stock_location_id]) stock_location.stock_movements.build(stock_movement_params).tap do |stock_movement| stock_movement.originator = try_spree_current_user stock_movement.stock_item = stock_location.set_up_stock_item(variant) @@ -36,11 +36,11 @@ def determine_backorderable end def load_product - @product = Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_slug]) if params[:product_slug] + @product = Spree::Product.accessible_by(current_ability, :show).friendly.find(params[:product_slug]) if params[:product_slug] end def load_stock_management_data - @stock_locations = Spree::StockLocation.accessible_by(current_ability, :read) + @stock_locations = Spree::StockLocation.accessible_by(current_ability) @stock_item_stock_locations = params[:stock_location_id].present? ? @stock_locations.where(id: params[:stock_location_id]) : @stock_locations @variant_display_attributes = self.class.variant_display_attributes @variants = Spree::Config.variant_search_class.new(params[:variant_search_term], scope: variant_scope).results @@ -50,7 +50,7 @@ def load_stock_management_data end def variant_scope - scope = Spree::Variant.accessible_by(current_ability, :read) + scope = Spree::Variant.accessible_by(current_ability) scope = scope.where(product: @product) if @product scope end diff --git a/backend/app/helpers/spree/admin/customer_returns_helper.rb b/backend/app/helpers/spree/admin/customer_returns_helper.rb index c1e12875be5..451f3e149da 100644 --- a/backend/app/helpers/spree/admin/customer_returns_helper.rb +++ b/backend/app/helpers/spree/admin/customer_returns_helper.rb @@ -4,7 +4,7 @@ module Spree module Admin module CustomerReturnsHelper def reimbursement_types - @reimbursement_types ||= Spree::ReimbursementType.accessible_by(current_ability, :read).active + @reimbursement_types ||= Spree::ReimbursementType.accessible_by(current_ability).active end end end diff --git a/backend/app/views/spree/admin/promotions/edit.html.erb b/backend/app/views/spree/admin/promotions/edit.html.erb index bfcfaaa9970..f07088ae32b 100644 --- a/backend/app/views/spree/admin/promotions/edit.html.erb +++ b/backend/app/views/spree/admin/promotions/edit.html.erb @@ -5,13 +5,13 @@ <% content_for :page_actions do %>
  • - <% if can?(:display, Spree::PromotionCode) %> + <% if can?(:read, Spree::PromotionCode) %> <%= link_to t('spree.view_promotion_codes_list'), admin_promotion_promotion_codes_path(promotion_id: @promotion.id), class: 'btn btn-primary' %> <%= link_to t('spree.download_promotion_codes_list'), admin_promotion_promotion_codes_path(promotion_id: @promotion.id, format: :csv), class: 'btn btn-primary' %> <% end %> - <% if can?(:display, Spree::PromotionCodeBatch) %> + <% if can?(:read, Spree::PromotionCodeBatch) %> <%= link_to plural_resource_name(Spree::PromotionCodeBatch), admin_promotion_promotion_code_batches_path(promotion_id: @promotion.id), class: 'btn btn-primary' %> <% end %>
  • diff --git a/backend/app/views/spree/admin/shared/_order_submenu.html.erb b/backend/app/views/spree/admin/shared/_order_submenu.html.erb index e01d8a1b6ff..07d7ee6844f 100644 --- a/backend/app/views/spree/admin/shared/_order_submenu.html.erb +++ b/backend/app/views/spree/admin/shared/_order_submenu.html.erb @@ -20,13 +20,13 @@ <%= link_to plural_resource_name(Spree::Shipment), spree.edit_admin_order_url(@order) %> - <% if can? :display, Spree::Adjustment %> + <% if can? :read, Spree::Adjustment %>
  • " data-hook='admin_order_tabs_adjustments'> <%= link_to plural_resource_name(Spree::Adjustment), spree.admin_order_adjustments_url(@order) %>
  • <% end %> - <% if can?(:display, Spree::Payment) %> + <% if can?(:read, Spree::Payment) %>
  • " data-hook='admin_order_tabs_payments'> <%= link_to plural_resource_name(Spree::Payment), spree.admin_order_payments_url(@order) %>
  • @@ -38,7 +38,7 @@ <% end %> - <% if can? :display, Spree::ReturnAuthorization %> + <% if can? :read, Spree::ReturnAuthorization %> <% if @order.completed? %>
  • " data-hook='admin_order_tabs_return_authorizations'> <%= link_to t('spree.admin.tab.rma'), spree.admin_order_return_authorizations_url(@order) %> @@ -46,7 +46,7 @@ <% end %> <% end %> - <% if can? :display, Spree::CustomerReturn %> + <% if can? :read, Spree::CustomerReturn %> <% if @order.completed? %>
  • " data-hook='admin_order_tabs_customer_returns'> <%= link_to plural_resource_name(Spree::CustomerReturn), spree.admin_order_customer_returns_url(@order) %> diff --git a/backend/app/views/spree/admin/shared/_payments_tabs.html.erb b/backend/app/views/spree/admin/shared/_payments_tabs.html.erb index 93cbe62081d..2db6d967d54 100644 --- a/backend/app/views/spree/admin/shared/_payments_tabs.html.erb +++ b/backend/app/views/spree/admin/shared/_payments_tabs.html.erb @@ -1,7 +1,7 @@ <% content_for :tabs do %>