Sha256: 256f5fa1c82ae979d3aaf326d4b864ef00ee624642236f0bb775f429e8de9c3f

Contents?: true

Size: 914 Bytes

Versions: 17

Compression:

Stored size: 914 Bytes

Contents

# frozen_string_literal: true

module PgEngine
  module TenantHelper
    # rubocop:disable Metrics/AbcSize
    def set_tenant_from_params_or_fail!
      if ActsAsTenant.current_tenant.present?
        return unless Rails.env.test?

        # Si es un controller test
        # TODO: migrar a request
        ua = Current.user.user_accounts.ua_active.where(account: ActsAsTenant.current_tenant).first
        Current.active_user_account = ua

        # Si no fue seteado por el domain

        return
      end

      uaid = UserAccount.decode_id(params[:tid]) if params[:tid].present?

      ua = ActsAsTenant.without_tenant do
        Current.user.user_accounts.ua_active.where(id: uaid).first if uaid.present?
      end

      raise ActsAsTenant::Errors::NoTenantSet if ua.blank?

      set_current_tenant(ua.account)
      Current.active_user_account = ua
    end
    # rubocop:enable Metrics/AbcSize
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pg_rails-7.6.23 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.22 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.22.pre.3 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.22.pre.2 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.22.pre.1 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.11 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.10 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.9 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.8 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.7 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.6 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.5 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.4 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.3 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.2 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb
pg_rails-7.6.21.pre.1 pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb