pg_rls 0.0.2.6.7 → 0.0.2.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6783ec3471dcba6dbad4e13ab33933d5f02e4ea336956f1a88d568a0ac4f7943
4
- data.tar.gz: 72d651c7863a7fc8de7df9441b849b58894e37833334d445df814aad402cf8e1
3
+ metadata.gz: '03856745d3bc5307b2e0c0709a39f46d983292b5660cd82fbd5f2f71fce62626'
4
+ data.tar.gz: 5d4401f7ba755c2c640b311434d0aff47139d8212352326b4bc76150e19c2561
5
5
  SHA512:
6
- metadata.gz: ef6b9d2c986f307fe286e7289fd6059a1255f029c1bc4c88d47da7547d5e2a30d1e43fa0bf7161dfbd307e78f996527f015800fc9c1ce44c80ecb2e7720f36fb
7
- data.tar.gz: 15f5f316a234d82bbc6712ba78aaa33edc329ac7e7027d228fddd9aa6ea750a66c2585921e31b83d48e4906ae5ed36169ad57954c49e3ae52dc9158cc17dee34
6
+ metadata.gz: 042f6141b1ea3bdefa87f590893a12564d9aa4f36140aa5e97e062ddc1a4bd7d457fe5a858b6784239bc743b8afcfa7f571b3964cee0b7b59305f69d601a8ec1
7
+ data.tar.gz: df7541a0733e6898558e8e54b0c45c1886ae116e5bba6efe39e3d9b303382bbfec4492ed4c4f9893822485305ef9894e2a80b544e850bedbb306825ad053e8f3
@@ -4,13 +4,14 @@ module PgRls
4
4
  module Errors
5
5
  # Raise Tenant Not found and ensure that the tenant is resetted
6
6
  class TenantNotFound < StandardError
7
- def initialize
7
+ def initialize(msg = nil)
8
8
  reset_tenant_id
9
- super
9
+ @msg = msg
10
+ super(msg)
10
11
  end
11
12
 
12
13
  def message
13
- "Tenant Doesn't exist"
14
+ @msg || "Tenant Doesn't exist"
14
15
  end
15
16
 
16
17
  def reset_tenant_id
@@ -13,7 +13,9 @@ module PgRls
13
13
 
14
14
  return @app.call(env) if tenant.blank?
15
15
 
16
- PgRls::Tenant.with_tenant(tenant) { @app.call(env) }
16
+ PgRls::Tenant.with_tenant!(tenant) { @app.call(env) }
17
+ rescue PgRls::Erorrs::TenantNotFound
18
+ @app.call(env)
17
19
  rescue ActiveRecord::RecordNotFound => e
18
20
  raise e unless rails_active_storage_request?(env)
19
21
 
@@ -7,8 +7,7 @@ module PgRls
7
7
  # Set PgRls Policies
8
8
  class Server
9
9
  def call(_job_instance, msg, _queue)
10
- PgRls::Tenant.with_tenant(msg['pg_rls']) do
11
- process_class = msg['args'].first['job_class']
10
+ PgRls::Tenant.with_tenant!(msg['pg_rls']) do
12
11
  yield
13
12
  end
14
13
  end
@@ -18,13 +18,15 @@ module PgRls
18
18
 
19
19
  def switch_tenant!(&block)
20
20
  fetched_tenant = session[:_tenant] || current_tenant
21
- Tenant.with_tenant(fetched_tenant) do |tenant|
21
+ return block.call if PgRls::Tenant.fetch.present?
22
+
23
+ Tenant.with_tenant!(fetched_tenant) do |tenant|
22
24
  session[:_tenant] = tenant
23
25
  block.call(tenant)
24
26
  end
25
27
  rescue NoMethodError
26
28
  session[:_tenant] = nil
27
- redirect_to '/'
29
+ raise PgRls::Errors::TenantNotFound, 'No tenant was found'
28
30
  end
29
31
 
30
32
  def switch_tenant_by_resource!(resource = nil)
data/lib/pg_rls/tenant.rb CHANGED
@@ -27,11 +27,11 @@ module PgRls
27
27
 
28
28
  def find_each(&)
29
29
  PgRls.main_model.find_each do |tenant|
30
- with_tenant(tenant, &)
30
+ with_tenant!(tenant, &)
31
31
  end
32
32
  end
33
33
 
34
- def with_tenant(resource, &block)
34
+ def with_tenant!(resource, &block)
35
35
  tenant = switch_tenant!(resource)
36
36
 
37
37
  block.call(tenant) if block_given?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRls
4
- VERSION = '0.0.2.6.7'
4
+ VERSION = '0.0.2.6.9'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_rls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.6.7
4
+ version: 0.0.2.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Laloush