Module: Kaui

Defined in:
lib/kaui.rb,
lib/kaui/engine.rb,
lib/kaui/version.rb,
app/models/kaui/user.rb,
app/models/kaui/tenant.rb,
app/models/kaui/ability.rb,
app/helpers/kaui/date_helper.rb,
app/helpers/kaui/home_helper.rb,
app/helpers/kaui/uuid_helper.rb,
app/models/kaui/allowed_user.rb,
app/helpers/kaui/money_helper.rb,
app/models/kaui/rails_methods.rb,
app/helpers/kaui/application_helper.rb,
app/models/kaui/allowed_user_tenant.rb,
app/helpers/kaui/subscription_helper.rb,
app/controllers/kaui/tenants_controller.rb,
app/controllers/kaui/sessions_controller.rb,
app/controllers/kaui/login_proxy_controller.rb,
app/controllers/kaui/admin_tenants_controller.rb,
lib/generators/kaui/install/install_generator.rb,
app/controllers/kaui/admin_allowed_users_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, DateHelper, EngineControllerUtil, HomeHelper, MoneyHelper, RailsMethods, SubscriptionHelper, UuidHelper Classes: Ability, Account, AccountEmail, AccountEmailsController, AccountTagsController, AccountTimeline, AccountTimelinesController, AccountsController, AdminAllowedUsersController, AdminTenant, AdminTenantsController, AllowedUser, AllowedUserTenant, AuditLog, Base, Bundle, BundleTagsController, BundlesController, Catalog, Chargeback, ChargebacksController, ChargesController, Credit, CreditsController, CustomField, CustomFieldsController, Engine, EngineController, HomeController, InstallGenerator, Invoice, InvoiceItem, InvoiceItemsController, InvoicePayment, InvoicesController, LoginProxyController, Payment, PaymentMethod, PaymentMethodsController, PaymentsController, Refund, RefundsController, SessionsController, Subscription, SubscriptionsController, Tag, TagDefinition, TagDefinitionsController, TagsController, Tenant, TenantsController, Transaction, TransactionsController, User

Constant Summary collapse

VERSION =
'0.9.0'

Class Method Summary collapse

Class Method Details

.config(&block) ⇒ Object



69
70
71
72
73
# File 'lib/kaui.rb', line 69

def self.config(&block)
  {
    :layout => layout || 'kaui/layouts/kaui_application',
  }
end

.current_tenant_user_options(user, session) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kaui.rb', line 51

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

.is_user_assigned_valid_tenant?(user, session) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kaui.rb', line 34

def self.is_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?

  # 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?

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