From 21e6432b41ecc399593146b3f65b39115cb71d8c Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Wed, 9 Sep 2015 16:56:55 +0200 Subject: [PATCH] fix ability when not logged in --- app/controllers/application_controller.rb | 8 +++----- app/models/ability.rb | 11 ++++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 36957b0..c7cc410 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index 30128c4..c3a4c81 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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