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
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

View file

@ -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