multi-tenant-support 1.1.1 → 1.2.0

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: f6c137c5f91a50070226bf5943aa074b8efb8041493e022b194e950c4a828900
4
- data.tar.gz: 75981d65c8fcaee0be43716a4cd98529425847ff88c7dc428348fd557fb3ab89
3
+ metadata.gz: 9834d4e3e978120e9a85d8da767d2079a34c416086557b84c4e54730819a1ffb
4
+ data.tar.gz: 41e2d934baa4668efc23bddb8d76dbb4a5b759ae4103f172c71b9406bc08c80d
5
5
  SHA512:
6
- metadata.gz: 648bafb81bc655e8b5e5ce5f69cb5396c3d462e6ac67f6d95492a8f23063869c2202457fc76e944d5059bf9cd7fc6d77e898550851e40af5a88c2a912bb4d25c
7
- data.tar.gz: 984a0ab95e23d14bbe45f4814d265c5afb7b90a05147d7a3e31f2d2eec587c2e088a1a57adfea8316bf7137ff7f73d2c0500257cb1eb95fc734b7c94888d7b04
6
+ metadata.gz: fc6ba9df8591e04abcc454981b15435261708ab23c39f54bcf9d321e362c8e631c5d74aa35c29a81030da7215b2e96e868acca238318f98a656ad38de37e6028
7
+ data.tar.gz: bdf08283a7363e65198a8de9d6ce1039886377d85870b7da13938cfe05c4d66d09c6281d743e6f9b6f8cd0792ae32cd218ea3513c9d21f8570318d74e797415e
data/README.md CHANGED
@@ -306,6 +306,29 @@ Currently, we don't have a good way to protect this method. So please use `upser
306
306
 
307
307
  This gem has override `unscoped` to prevent the default tenant scope be scoped out. But if you really want to scope out the default tenant scope, you can use `unscope_tenant`.
308
308
 
309
+ ### Console
310
+
311
+ Console does not allow read across tenant by default. But you have several ways to change that:
312
+
313
+ 1. Set `allow_read_across_tenant_by_default` in the initialize file
314
+
315
+ ```ruby
316
+ console do |config|
317
+ config.allow_read_across_tenant_by_default = true
318
+ end
319
+ ```
320
+ 2. Set the environment variable `ALLOW_READ_ACROSS_TENANT` when call consoel command
321
+
322
+ ```bash
323
+ ALLOW_READ_ACROSS_TENANT=1 rails console
324
+ ```
325
+ 3. Manual change it in console
326
+
327
+ ```ruby
328
+ $ rails c
329
+ $ irb(main):001:0> MultiTenantSupport.allow_read_across_tenant
330
+ ```
331
+
309
332
  ## Code Example
310
333
 
311
334
  ### Database Schema
@@ -340,6 +363,10 @@ MultiTenantSupport.configure do
340
363
  config.excluded_subdomains = ['www']
341
364
  config.host = 'example.com'
342
365
  end
366
+
367
+ console do |config|
368
+ config.allow_read_across_tenant_by_default = false
369
+ end
343
370
  end
344
371
  ```
345
372
 
@@ -12,6 +12,10 @@ MultiTenantSupport.configure do
12
12
  config.excluded_subdomains = ['www']
13
13
  config.host = 'REPLACE.ME'
14
14
  end
15
+
16
+ console do |config|
17
+ config.allow_read_across_tenant_by_default = false
18
+ end
15
19
  end
16
20
 
17
21
  # Uncomment if you are using sidekiq without ActiveJob
@@ -4,6 +4,7 @@ require "multi_tenant_support/errors"
4
4
  require "multi_tenant_support/config/app"
5
5
  require "multi_tenant_support/config/controller"
6
6
  require "multi_tenant_support/config/model"
7
+ require "multi_tenant_support/config/console"
7
8
  require "multi_tenant_support/current"
8
9
  require "multi_tenant_support/find_tenant_account"
9
10
  require "multi_tenant_support/concern/controller_concern"
@@ -33,6 +34,10 @@ module MultiTenantSupport
33
34
  end
34
35
  end
35
36
 
37
+ def allow_read_across_tenant?
38
+ !disallow_read_across_tenant?
39
+ end
40
+
36
41
  def disallow_read_across_tenant?
37
42
  !Current.allow_read_across_tenant
38
43
  end
@@ -8,6 +8,7 @@ module MultiTenantSupport
8
8
  end
9
9
 
10
10
  class_methods do
11
+
11
12
  if Gem::Version.new(Rails.version) < Gem::Version.new("7.0.0.alpha1")
12
13
  def perform_now(*args)
13
14
  job = job_or_instantiate(*args)
@@ -23,6 +24,21 @@ module MultiTenantSupport
23
24
  end
24
25
  ")
25
26
  end
27
+
28
+ def execute(job_data)
29
+ keep_current_tenant_unchange do
30
+ super(job_data)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def keep_current_tenant_unchange
37
+ _current_tenant = MultiTenantSupport::Current.tenant_account
38
+ yield
39
+ ensure
40
+ MultiTenantSupport::Current.tenant_account = _current_tenant
41
+ end
26
42
  end
27
43
 
28
44
  def perform_now
@@ -0,0 +1,21 @@
1
+ module MultiTenantSupport
2
+
3
+ module Config
4
+ class Console
5
+ attr_writer :allow_read_across_tenant_by_default
6
+
7
+ def allow_read_across_tenant_by_default
8
+ @allow_read_across_tenant_by_default ||= false
9
+ end
10
+ end
11
+ end
12
+
13
+ module_function
14
+ def console
15
+ @console ||= Config::Console.new
16
+ return @console unless block_given?
17
+
18
+ yield @console
19
+ end
20
+
21
+ end
@@ -9,5 +9,13 @@ module MultiTenantSupport
9
9
  config.app_generators.templates.unshift(active_record_templates)
10
10
  end
11
11
 
12
+ console do
13
+ if ENV["ALLOW_READ_ACROSS_TENANT"] || MultiTenantSupport.console.allow_read_across_tenant_by_default
14
+ MultiTenantSupport.allow_read_across_tenant
15
+ else
16
+ MultiTenantSupport.disallow_read_across_tenant
17
+ end
18
+ end
19
+
12
20
  end
13
21
  end
@@ -1,3 +1,3 @@
1
1
  module MultiTenantSupport
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi-tenant-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hopper Gee
@@ -45,6 +45,7 @@ files:
45
45
  - lib/multi_tenant_support/concern/controller_concern.rb
46
46
  - lib/multi_tenant_support/concern/model_concern.rb
47
47
  - lib/multi_tenant_support/config/app.rb
48
+ - lib/multi_tenant_support/config/console.rb
48
49
  - lib/multi_tenant_support/config/controller.rb
49
50
  - lib/multi_tenant_support/config/model.rb
50
51
  - lib/multi_tenant_support/current.rb