acts_as_tenant 0.5.3 → 0.6.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: df411b08fd69234fdd767f98232148eef42a147986b9417eb08f8f0dbdbd5479
4
- data.tar.gz: 25b9bdd0ab15e9b08ddea8b7b310a7d2968529b882409551209d4a59b9157a20
3
+ metadata.gz: f5bed52bb9172b8035bbe0f9ac6d837acf6bfdf9f4bcec542556dddf3b3b3f5d
4
+ data.tar.gz: fe3c6219243da29201e4965c5906398e06df9e80a7e9de948bbe53b702804d8f
5
5
  SHA512:
6
- metadata.gz: 119a2b3e43b5a04f589f352943121d483d12c4ab44ec73ef493453bccc749fb512236f647eedc82a88bcdb13968627f3471b0f1a67f9e5a8c13080d3307393d1
7
- data.tar.gz: '080c80a34f7c5f8dc1c235c3ebaa28f98ba97566776749de51ca9e4e6e795d2da21e19270d66d34b3633679233c8553237f012eb1b250224f75855584399e2da'
6
+ metadata.gz: b5a499156656e313c113d2dddc9c922d49447bcecc2bb76a421c01fc8401a1a0501cb4515ac6323b48b71b046197da52dc3850634ba12435c44a6b95bb6724fc
7
+ data.tar.gz: c046fa7c06351158b437b83b61030abce8b7b95d0a453c9ee44b93a4518b50a6acfef59a00840a8624b6515a09979c12c2cc31783a959a412c21dad0f35d9ca3
data/README.md CHANGED
@@ -137,6 +137,16 @@ end
137
137
  ```
138
138
  This is useful in shared routes such as admin panels or internal dashboards when `require_tenant` option is enabled throughout the app.
139
139
 
140
+ ### Allowing tenant updating for a block ###
141
+
142
+ ```ruby
143
+ ActsAsTenant.with_mutable_tenant do
144
+ # Tenant updating is enabled for all code in this block
145
+ end
146
+ ```
147
+
148
+ This will allow you to change the tenant of a model. This feature is useful for admin screens, where it is ok to allow certain users to change the tenant on existing models in specific cases.
149
+
140
150
  ### Require tenant to be set always ###
141
151
 
142
152
  If you want to require the tenant to be set at all times, you can configure acts_as_tenant to raise an error when a query is made without a tenant available. See below under configuration options.
@@ -5,6 +5,7 @@ module ActsAsTenant
5
5
  class_methods do
6
6
  def acts_as_tenant(tenant = :account, **options)
7
7
  ActsAsTenant.set_tenant_klass(tenant)
8
+ ActsAsTenant.mutable_tenant!(false)
8
9
 
9
10
  ActsAsTenant.add_global_record_model(self) if options[:has_global_records]
10
11
 
@@ -77,13 +78,13 @@ module ActsAsTenant
77
78
  to_include = Module.new {
78
79
  define_method "#{fkey}=" do |integer|
79
80
  write_attribute(fkey.to_s, integer)
80
- raise ActsAsTenant::Errors::TenantIsImmutable if tenant_modified?
81
+ raise ActsAsTenant::Errors::TenantIsImmutable if !ActsAsTenant.mutable_tenant? && tenant_modified?
81
82
  integer
82
83
  end
83
84
 
84
85
  define_method "#{ActsAsTenant.tenant_klass}=" do |model|
85
86
  super(model)
86
- raise ActsAsTenant::Errors::TenantIsImmutable if tenant_modified?
87
+ raise ActsAsTenant::Errors::TenantIsImmutable if !ActsAsTenant.mutable_tenant? && tenant_modified?
87
88
  model
88
89
  end
89
90
 
@@ -1,3 +1,3 @@
1
1
  module ActsAsTenant
2
- VERSION = "0.5.3"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -12,6 +12,7 @@ module ActsAsTenant
12
12
  @@configuration = nil
13
13
  @@tenant_klass = nil
14
14
  @@models_with_global_records = []
15
+ @@mutable_tenant = false
15
16
 
16
17
  class << self
17
18
  attr_writer :default_tenant
@@ -87,6 +88,14 @@ module ActsAsTenant
87
88
  @default_tenant unless unscoped
88
89
  end
89
90
 
91
+ def self.mutable_tenant!(toggle)
92
+ @@mutable_tenant = toggle
93
+ end
94
+
95
+ def self.mutable_tenant?
96
+ @@mutable_tenant
97
+ end
98
+
90
99
  def self.with_tenant(tenant, &block)
91
100
  if block.nil?
92
101
  raise ArgumentError, "block required"
@@ -120,6 +129,13 @@ module ActsAsTenant
120
129
  self.unscoped = old_unscoped
121
130
  end
122
131
 
132
+ def self.with_mutable_tenant(&block)
133
+ ActsAsTenant.mutable_tenant!(true)
134
+ without_tenant(&block)
135
+ ensure
136
+ ActsAsTenant.mutable_tenant!(false)
137
+ end
138
+
123
139
  def self.should_require_tenant?
124
140
  if configuration.require_tenant.respond_to?(:call)
125
141
  !!configuration.require_tenant.call
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Matthijssen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-12-02 00:00:00.000000000 Z
12
+ date: 2022-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: request_store