fix ability when not logged in
This commit is contained in:
parent
3a0d5f1017
commit
21e6432b41
2 changed files with 7 additions and 12 deletions
|
@ -16,10 +16,8 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def current_ability
|
||||
if current_user
|
||||
@current_ability ||= Ability.new(current_user)
|
||||
elsif current_client
|
||||
@current_ability ||= ClientAbility.new(current_client)
|
||||
end
|
||||
@current_ability ||=
|
||||
current_client.try { |c| ClientAbility.new(c) } ||
|
||||
Ability.new(current_user)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,13 +2,10 @@ class Ability
|
|||
include CanCan::Ability
|
||||
|
||||
def initialize(user)
|
||||
user ||= User.new # guest user (not logged in)
|
||||
return unless user
|
||||
|
||||
if user.penning?
|
||||
can :manage, :all
|
||||
else
|
||||
can :read, user, id: user.id
|
||||
can :create, Transaction, debtor: user
|
||||
end
|
||||
can :manage, :all if user.penning?
|
||||
can :read, user, id: user.id
|
||||
can :create, Transaction, debtor: user
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue