Class: Kaui::TenantsController

Inherits:
EngineController show all
Defined in:
app/controllers/kaui/tenants_controller.rb

Constant Summary

Constants included from EngineControllerUtil

EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD

Instance Method Summary collapse

Methods inherited from EngineController

#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient, #populate_account_details, #retrieve_allowed_users_for_current_user, #retrieve_tenants_for_current_user

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/kaui/tenants_controller.rb', line 5

def index
  # Retrieve current user and extract allowed list of tenants
  allowed_user = Kaui::AllowedUser.find_by_kb_username(current_user.kb_username)
  @tenants = (allowed_user && allowed_user.kaui_tenants) || []

  #
  # If there is nothing, we check for override with KillBillClient.api_key/KillBillClient.api_secret
  # If there is only one, we skip the tenant screen since the choice is obvious
  # If not, we allow user to choose what he wants
  #
  case @tenants.size
    when 0
      tenant = KillBillClient.api_key.nil? ? nil : KillBillClient::Model::Tenant.find_by_api_key(KillBillClient.api_key, :session_id => current_user.kb_session_id)
      if tenant.present?
        select_tenant_for_tenant_id(tenant.tenant_id, tenant.external_key, nil)
      else
        redirect_to new_admin_tenant_path
      end
    when 1
      # If there is only one tenant defined we skip the screen and set the tenant for the user
      select_tenant_for_tenant_id(@tenants[0].kb_tenant_id, @tenants[0].name, @tenants[0].id)
    else
      # Jump to default view allowing to chose which tenant to pick
  end
end

#select_tenantObject



31
32
33
34
# File 'app/controllers/kaui/tenants_controller.rb', line 31

def select_tenant
  tenant = Kaui::Tenant.find_by_kb_tenant_id(params.require(:kb_tenant_id))
  select_tenant_for_tenant_id(tenant.kb_tenant_id, tenant.name, tenant.id)
end