pg_rls 0.1.0 → 0.1.1

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: 43fa134f2b679ac9b15406226a50a8b7186a0845c030e931e40f17ba226b5a1c
4
- data.tar.gz: 5580815284fecca5bb67435e54e0a9bb775cc56f8524b2bb01a3b85da5c15901
3
+ metadata.gz: 0b51a33bf2c5a0518a96142e8b07e303b32419719dfce1715ee237a0348d19c9
4
+ data.tar.gz: 3bba1aaa681ab9a6d0defff9110c5f2077b08ff6a07332ad429cd040d8c84a7a
5
5
  SHA512:
6
- metadata.gz: 976399696e8c22b692d389c99ae7918e66d67c02f485fa4b6ad157f6940fb215bb1440753086c8ba4e26618edc53de04ad8bd4a27198c03739265cc284598001
7
- data.tar.gz: 4342defbd2a76a1927e93634b26cd1c1103afc011ff2a24066a257a8e0d8dd28bb73b2adf3925781ea8b5a45785301627495293827e27fb43c606e9036999682
6
+ metadata.gz: 3ff073704aeca1d9e1b3e8673353deeca756d06b95a32f62fe85ac65cd3f145007c68d6b0b980b78221bdd0f4330421fc540d8efdc7e11600d8adaada1aa105c
7
+ data.tar.gz: 11711ea29d21eef5d0dccbdfc5916074fe1a98089752f7fc0095ca1d514b40f5c40cb4b0a7a56688160a8afeb67414c3902d88152732774ad62fcbd6c7294140
data/.rubocop.yml CHANGED
@@ -21,3 +21,6 @@ Metrics/BlockLength:
21
21
  Security/MarshalLoad:
22
22
  Exclude:
23
23
  - 'lib/pg_rls/middleware/set_reset_connection.rb'
24
+ Metrics/ModuleLength:
25
+ Exclude:
26
+ - 'lib/pg_rls.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_rls (2.0.0)
4
+ pg_rls (0.1.1)
5
5
  bundler (~> 2.2)
6
6
 
7
7
  GEM
@@ -12,11 +12,11 @@ module PgRls
12
12
  end
13
13
 
14
14
  def load_tenant_attribute!(msg)
15
- if PgRls.username == PgRls.current_db_username
15
+ if PgRls.admin_connection?
16
+ msg['admin'] = true
17
+ else
16
18
  tenant = PgRls::Tenant.fetch!
17
19
  msg['pg_rls'] = tenant.id
18
- else
19
- msg['admin'] = true
20
20
  end
21
21
  end
22
22
  end
data/lib/pg_rls/tenant.rb CHANGED
@@ -81,7 +81,7 @@ module PgRls
81
81
  end
82
82
 
83
83
  def find_tenant(resource)
84
- raise PgRls::Errors::AdminUsername if admin_username?
84
+ raise PgRls::Errors::AdminUsername if PgRls.admin_connection?
85
85
 
86
86
  reset_rls!
87
87
 
@@ -95,10 +95,6 @@ module PgRls
95
95
  raise PgRls::Errors::TenantNotFound if tenant.blank?
96
96
  end
97
97
 
98
- def admin_username?
99
- PgRls.username != PgRls.current_db_username
100
- end
101
-
102
98
  def find_tenant_by_method(resource, method)
103
99
  look_up_value = resource.is_a?(PgRls.main_model) ? resource.send(method) : resource
104
100
  PgRls.main_model.send("find_by_#{method}!", look_up_value)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRls
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/lib/pg_rls.rb CHANGED
@@ -87,6 +87,8 @@ module PgRls
87
87
  end
88
88
 
89
89
  def on_each_tenant(&)
90
+ set_rls_connection! if admin_connection?
91
+
90
92
  result = []
91
93
  main_model.find_each do |tenant|
92
94
  allowed_search_fields = search_methods.map(&:to_s).intersection(main_model.column_names)
@@ -100,6 +102,11 @@ module PgRls
100
102
  result
101
103
  end
102
104
 
105
+ def set_rls_connection!
106
+ self.as_db_admin = false
107
+ establish_new_connection!
108
+ end
109
+
103
110
  def execute_rls_in_shards
104
111
  connection_pool_list = PgRls.connection_class.connection_handler.connection_pool_list
105
112
  result = []
@@ -123,6 +130,10 @@ module PgRls
123
130
  @as_db_admin || false
124
131
  end
125
132
 
133
+ def admin_connection?
134
+ current_db_username != username
135
+ end
136
+
126
137
  private
127
138
 
128
139
  attr_writer :as_db_admin
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Laloush