In my Spree Application i have created new role having name sales_rep and i want to give admin access to users having this role.
Here you can find my cancan ability file:
module Spree
class SalesRepAbility
include CanCan::Ability
def initialize(user)
if user.respond_to?(:has_spree_role?) && user.has_spree_role?('sales_rep')
can :manage, :all
end
end
end
end
but when i try to login via admin with admin/login URL it is not authenticating user other than admin.
Actually i want to override Spree::Admin::UserSessionsController's create method in which authenticate_spree_user! is failing.
Is there any way to override Spree::Admin::UserSessionsController's authenticate_spree_user! method so that having role of sales_rep can access this Admin panel.
Here is my method of controller:
def create
authenticate_spree_user!
if spree_user_signed_in?
respond_to do |format|
format.html {
flash[:success] = Spree.t(:logged_in_succesfully)
redirect_back_or_default(after_sign_in_path_for(spree_current_user))
}
format.js {
user = resource.record
render :json => {:ship_address => user.ship_address, :bill_address => user.bill_address}.to_json
}
end
end
I just want to allow user having sales_rep role to login same as Admin do in Spree and for that i want to override Spree::Admin::UserSessionsController's create method.
Is there any way to achieve this? How i can allow user having different role than admin to access panel.
Any help appreciated!!
You have to register your ability also. Add
Spree::Ability.register_ability(Spree:: SalesRepAbility)in spree.rb and restart you server