Reputation: 2410
I am trying to specify some custom roles in Spree for example role 'client' and extend the permissions to access the admin section for this role.
This user will be able to access only those Product created by that user. Concept is letting a user with role 'client' manage only products and other certain Models.
To start with I added CanCan plugin and defined a RoleAbility Class in role_ability.rb
Just following this post : Spree Custom Roles Permissions
class RoleAbility
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.has_role? 'admin'
can :manage, :all
elsif user.has_role? 'client_admin'
can :read, Product
can :admin, Product
end
end
end
Added this to an initializer : config/initializers/spree.rb
Ability.register_ability(RetailerAbility)
Also extended admin_products_controller_decorator.rb :app/controllersadmin_products_controller_decorator.rb
Admin::ProductsController.class_eval do
def authorize_admin
authorize! :admin, Product
authorize! params[:action].to_sym, Product
end
end
But I am getting flash message 'Authorisation Failure'
Trying to find some luck, I referred following links
A github gist for Customizing Spree Roles : https://gist.github.com/1277326
Here's a similar issue what I am facing : http://groups.google.com/group/spree-user/browse_thread/thread/1e819e10410d03c5/23b269e09c7ed47e
All efforts in vain...
Any pointers highly appreciated ?
Thanks in advance.
Upvotes: 4
Views: 3267
Reputation: 2410
Finally found it.
After doing some careful research found that spree 1.1.1 had changed the classes by adding "Spree" module to every class, this resulted in url like "spree/admin/overview" which earlier was "admin/overview".
So that worked for me and I was able to control the Permissions for my roles.
Upvotes: 5