Class: Kaui::EngineController

Inherits:
ApplicationController
  • Object
show all
Includes:
EngineControllerUtil, ErrorHandler
Defined in:
app/controllers/kaui/engine_controller.rb

Constant Summary

Constants included from EngineControllerUtil

Kaui::EngineControllerUtil::MAXIMUM_NUMBER_OF_RECORDS_DOWNLOAD, Kaui::EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD

Instance Method Summary collapse

Methods included from ErrorHandler

#perform_redirect_after_error

Instance Method Details

#check_for_redirect_to_tenant_screenObject



33
34
35
36
37
38
# File 'app/controllers/kaui/engine_controller.rb', line 33

def check_for_redirect_to_tenant_screen
  unless Kaui.user_assigned_valid_tenant?(current_user, session)
    session[:kb_tenant_id] = nil
    redirect_to Kaui.tenant_home_path.call
  end
end

#current_abilityObject

Called lazily by the can? helper



28
29
30
31
# File 'app/controllers/kaui/engine_controller.rb', line 28

def current_ability
  # Redefined here to namespace Ability in the correct module
  @current_ability ||= Kaui::Ability.new(current_user)
end

#current_userObject

Used for auditing purposes



23
24
25
# File 'app/controllers/kaui/engine_controller.rb', line 23

def current_user
  super
end

#options_for_klient(options = {}) ⇒ Object

Common options for the Kill Bill client



13
14
15
16
17
18
19
20
# File 'app/controllers/kaui/engine_controller.rb', line 13

def options_for_klient(options = {})
  user_tenant_options = Kaui.current_tenant_user_options(current_user, session)
  user_tenant_options.merge!(options)
  # Pass the X-Request-Id seen by Rails to Kill Bill
  # Note that this means that subsequent requests issued by a single action will share the same X-Request-Id in Kill Bill
  user_tenant_options[:request_id] ||= request.request_id
  user_tenant_options
end

#populate_account_detailsObject



40
41
42
# File 'app/controllers/kaui/engine_controller.rb', line 40

def 
  @account ||= params[:account_id].present? ? Kaui::.find_by_id(params[:account_id], false, false, options_for_klient) : Kaui::.new
end

#retrieve_allowed_users_for_current_userObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/kaui/engine_controller.rb', line 52

def retrieve_allowed_users_for_current_user
  tenants_for_current_user = retrieve_tenants_for_current_user

  Kaui::AllowedUser.preload(:kaui_tenants).all.select do |user|
    tenants_for_user = user.kaui_tenants.map(&:kb_tenant_id)
    if tenants_for_user.empty?
      current_user.root?
    else
      (tenants_for_user - tenants_for_current_user).empty?
    end
  end
end

#retrieve_tenants_for_current_userObject



44
45
46
47
48
49
50
# File 'app/controllers/kaui/engine_controller.rb', line 44

def retrieve_tenants_for_current_user
  if current_user.root?
    Kaui::Tenant.all.map(&:kb_tenant_id)
  else
    Kaui::AllowedUser.preload(:kaui_tenants).find_by_kb_username(current_user.kb_username).kaui_tenants.map(&:kb_tenant_id)
  end
end