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/locale_helper.rb,
app/helpers/kaui/object_helper.rb,
app/helpers/kaui/plugin_helper.rb,
app/helpers/kaui/account_helper.rb,
app/helpers/kaui/payment_helper.rb,
app/helpers/kaui/us_states_helper.rb,
app/models/kaui/application_record.rb,
app/helpers/kaui/application_helper.rb,
app/helpers/kaui/permissions_helper.rb,
app/models/kaui/allowed_user_tenant.rb,
app/helpers/kaui/subscription_helper.rb,
app/helpers/kaui/payment_method_helper.rb,
app/controllers/kaui/sessions_controller.rb,
app/controllers/kaui/login_proxy_controller.rb,
app/controllers/kaui/registrations_controller.rb,
lib/generators/kaui/install/install_generator.rb

Defined Under Namespace

Modules: AccountHelper, ApplicationHelper, DateHelper, EngineControllerUtil, HomeHelper, LocaleHelper, MoneyHelper, ObjectHelper, PaymentHelper, PaymentMethodHelper, PaymentState, PermissionsHelper, PluginHelper, RailsMethods, SubscriptionHelper, UsStatesHelper, UuidHelper Classes: Ability, Account, AccountChildrenController, AccountCustomFieldsController, AccountEmail, AccountEmailsController, AccountTagsController, AccountTimeline, AccountTimelinesController, AccountsController, Admin, AdminAllowedUsersController, AdminController, AdminTenant, AdminTenantsController, AllowedUser, AllowedUserTenant, ApplicationRecord, AuditLog, AuditLogsController, Base, Bundle, BundleTagsController, BundlesController, Catalog, Chargeback, ChargebacksController, ChargesController, Credit, CreditsController, CustomField, CustomFieldsController, Engine, EngineController, HomeController, InstallGenerator, Invoice, InvoiceItem, InvoiceItemsController, InvoicePayment, InvoicesController, LoginProxyController, Overdue, Payment, PaymentMethod, PaymentMethodsController, PaymentsController, QueuesController, Refund, RefundsController, RegistrationsController, RoleDefinition, RoleDefinitionsController, SessionsController, SimplePlan, Subscription, SubscriptionsController, Tag, TagDefinition, TagDefinitionsController, TagsController, Tenant, TenantsController, Transaction, TransactionsController, User, UserRole

Constant Summary collapse

VERSION =
'2.0.2'

Class Method Summary collapse

Class Method Details

.config(&block) ⇒ Object


146
147
148
149
150
# File 'lib/kaui.rb', line 146

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

.current_tenant_user_options(user, session) ⇒ Object


128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/kaui.rb', line 128

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)

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/kaui.rb', line 108

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?

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

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