diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/application_controller.rb | 4 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4e71ff8..14f50bf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,8 +7,10 @@ class ApplicationController < ActionController::Base protected + include ApplicationHelper + def current_agent - @current_agent = session[:current_agent] || current_user.presence&.agents&.first&.name || 'IN COMMON' + @current_agent = Agent.find_by(name: session[:current_agent] || current_user.presence&.agents&.first&.name || 'incommon') end helper_method :current_agent diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..0b22f4b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,10 @@ module ApplicationHelper + def current_agency + current_user.agencies.where(agent: current_agent).first + end + %w(observer editor maintainer leader).each do |role| + define_method :"current_user_#{role}?" do + current_agency.send(:"#{role}?") + end + end end |