fix ability when not logged in

This commit is contained in:
Ilion Beyst 2015-09-09 16:56:55 +02:00
parent 3a0d5f1017
commit 21e6432b41
2 changed files with 7 additions and 12 deletions

View file

@ -16,10 +16,8 @@ class ApplicationController < ActionController::Base
end end
def current_ability def current_ability
if current_user @current_ability ||=
@current_ability ||= Ability.new(current_user) current_client.try { |c| ClientAbility.new(c) } ||
elsif current_client Ability.new(current_user)
@current_ability ||= ClientAbility.new(current_client)
end
end end
end end

View file

@ -2,13 +2,10 @@ class Ability
include CanCan::Ability include CanCan::Ability
def initialize(user) def initialize(user)
user ||= User.new # guest user (not logged in) return unless user
if user.penning? can :manage, :all if user.penning?
can :manage, :all can :read, user, id: user.id
else can :create, Transaction, debtor: user
can :read, user, id: user.id
can :create, Transaction, debtor: user
end
end end
end end