Hello everyone. I'm new to solidus and I have a li...
# support
a
Hello everyone. I'm new to solidus and I have a little problem with permissions. I have the role warehouse_admin and I need him to only be able to see his warehouses (stock_locations). I have the following:
Copy code
# config/initializers/spree.rb
 
config.roles.assign_permissions :warehouse_admin, [
    'Spree::PermissionSets::RestrictedStockManagement'
  ]
but the user sees all warehouse. The problem is because of the query that is launched this is the query Where does the
OR ("spree_stock_locations"."active" = TRUE)
?
Copy code
Spree::StockLocation Load (0.3ms)  SELECT "spree_stock_locations".* FROM "spree_stock_locations" WHERE (("spree_stock_locations"."id" = 3) OR ("spree_stock_locations"."active" = TRUE)) /* loading for inspect */ LIMIT $1  [["LIMIT", 11]]
I have tried having a custom permissions class but the result is the same.
Copy code
#app/models/spree/permissions_sets/warehouse_admin.rb(
require 'cancan'

module Spree
  module PermissionSets
    class WarehouseAdmin < Spree::PermissionSets::Base

      def activate!
        can :read, Spree::StockLocation, id: location_ids
      end

      def location_ids
        @location_ids ||= user.stock_locations.pluck(:id)
      end
    end
  end
end

# config/initializers/spree.rb

config.roles.assign_permissions :warehouse_admin, [
    'Spree::PermissionSets::WarehouseAdmin'
  ]
thanks!!
w
Hi @Ant贸n, how are you getting that query?
a
thanks for answering 馃檪 Investigating the code I see that it's done in the
Spree::Admin::StockItemsController
class in the
load_stock_management_data
method with
@stock_locations = Spree::StockLocation.accessible_by(current_ability)
w
That looks like a bug. I created an issue on the repo: https://github.com/solidusio/solidus/issues/4744
a
hi @waiting_for_dev thanks for answering. I have responded to the issue, on how I have solved it.
w
thanks for getting back, @Ant贸n, that can help others as a workaround until we find a better solution
馃檪 1