module Kaui

Constants

VERSION

Public Class Methods

config() click to toggle source
# File lib/kaui.rb, line 208
def self.config
  {
    layout: layout || 'kaui/layouts/kaui_application'
  }
end
current_tenant_user_options(user, session) click to toggle source
# File lib/kaui.rb, line 193
def self.current_tenant_user_options(user, session)
  kb_tenant_id = session[:kb_tenant_id]
  user_tenant = Kaui::Tenant.find_by_kb_tenant_id(kb_tenant_id) if kb_tenant_id
  result = {
    username: user.kb_username,
    password: user.password,
    session_id: user.kb_session_id
  }
  if user_tenant
    result[:api_key] = user_tenant.api_key
    result[:api_secret] = user_tenant.api_secret
  end
  result
end
user_assigned_valid_tenant?(user, session) click to toggle source
# File lib/kaui.rb, line 173
def self.user_assigned_valid_tenant?(user, session)
  #
  # If those are set in config initializer then we bypass the check
  # For multi-tenant production deployment, those should not be set!
  #
  return true if KillBillClient.api_key.present? && KillBillClient.api_secret.present?

  # Not tenant in the session, returns right away...
  return false if session[:kb_tenant_id].nil?

  # Signed-out?
  return false if user.nil?

  # If there is a kb_tenant_id in the session then we check if the user is allowed to access it
  au = Kaui::AllowedUser.find_by_kb_username(user.kb_username)
  return false if au.nil?

  au.kaui_tenants.select { |t| t.kb_tenant_id == session[:kb_tenant_id] }.first
end