pg_rls 0.0.2.4 → 0.0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97b8d67f3ffcd5b65cc10db46a9a0b981545881ad1e6ce40152c73feadf18b3f
4
- data.tar.gz: fd084b44bc7a6301e196aafeb670071426e8f85bc861a83c1dc7e025386a6ecd
3
+ metadata.gz: da4bc81a35329089d15f9170a1413a59a744031cd5dda56039a63670e12893f6
4
+ data.tar.gz: '039d986cac7335ca9e7b272079f2332923935a5868aeb81a62549a7032d4a0d4'
5
5
  SHA512:
6
- metadata.gz: 461960383dd168e92d23a7d046c9baf521a03dca494f60918cf4712c878ae3d37abd5d3b357c09e59eb4d8cfbbb50b00d18c6110217f2add95f230f767bb58b5
7
- data.tar.gz: 0febfe88828a1875c8156a5cd010e5ee25f3b10e7e714e3bbe07233f70e09abb7201ea357f1e22dd3733c48854ef4aa7cfc214775b42365c77ec04a3463113b8
6
+ metadata.gz: 531778ca364c83747de7626e4671daf37fd74d8f58c6e3df880dfe09bfebdbd0ba36896228d3950fbb37495cf5452a92c8c46a39d7515fc90b05add8fda19401
7
+ data.tar.gz: a77bd764951f8468d9be4866040862a7808b721f2f8c5344dbf0f4cefaf11ce1ac0d8af19d0cc9a0bc5d31ef34dfdf7400f44b1d74f10948ad25fdde76f5c676
@@ -5,15 +5,26 @@ module PgRls
5
5
  module MultiTenancy
6
6
  def self.included(base)
7
7
  base.class_eval do
8
- before_action :switch_tenant
8
+ before_action :switch_tenant!
9
9
  end
10
10
  end
11
11
 
12
12
  private
13
13
 
14
- def switch_tenant
15
- Tenant.switch!(request.subdomain)
16
- session[:_tenant] = request.subdomain
14
+ def switch_tenant!
15
+ tenant = request.subdomain
16
+ Tenant.switch!(tenant)
17
+ session[:_tenant] = tenant
18
+ rescue PgRls::Errors::TenantNotFound, ActiveRecord::RecordNotFound
19
+ Tenant.switch(session[:_tenant])
20
+ rescue NoMethodError
21
+ session[:_tenant] = nil
22
+ redirect_to '/'
23
+ end
24
+
25
+ def switch_tenant_by_resource!(resource = nil)
26
+ Tenant.switch!(resource)
27
+ session[:_tenant] = resource
17
28
  rescue PgRls::Errors::TenantNotFound, ActiveRecord::RecordNotFound
18
29
  Tenant.switch(session[:_tenant])
19
30
  rescue NoMethodError
@@ -17,7 +17,7 @@ module PgRls
17
17
 
18
18
  def self.included(base)
19
19
  establish_secure_connection
20
- base.ignored_columns = %w(tenant_id)
20
+ base.ignored_columns = %w[tenant_id]
21
21
  end
22
22
  end
23
23
  end
data/lib/pg_rls/tenant.rb CHANGED
@@ -37,6 +37,15 @@ module PgRls
37
37
  'no tenant is selected'
38
38
  end
39
39
 
40
+ def find_main_model
41
+ PgRls.main_model.ignored_columns = []
42
+ PgRls.main_model.find_by!(
43
+ tenant_id: PgRls.connection_class.connection.execute(
44
+ "SELECT current_setting('rls.tenant_id')"
45
+ ).getvalue(0, 0)
46
+ )
47
+ end
48
+
40
49
  def reset_rls!
41
50
  @fetch = nil
42
51
  @tenant = nil
@@ -46,6 +55,8 @@ module PgRls
46
55
  private
47
56
 
48
57
  def switch_tenant!(resource)
58
+ PgRls.main_model.ignored_columns = []
59
+
49
60
  connection_adapter = PgRls.connection_class
50
61
  find_tenant(resource)
51
62
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRls
4
- VERSION = '0.0.2.4'
4
+ VERSION = '0.0.2.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_rls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.4
4
+ version: 0.0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Laloush
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-30 00:00:00.000000000 Z
11
+ date: 2023-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,7 +80,7 @@ licenses:
80
80
  - MIT
81
81
  metadata:
82
82
  rubygems_mfa_required: 'true'
83
- post_install_message:
83
+ post_install_message:
84
84
  rdoc_options: []
85
85
  require_paths:
86
86
  - lib
@@ -95,8 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.3.15
99
- signing_key:
98
+ rubygems_version: 3.3.26
99
+ signing_key:
100
100
  specification_version: 4
101
101
  summary: Write a short summary, because RubyGems requires one.
102
102
  test_files: []