acts_as_tenant 0.5.3 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/acts_as_tenant/model_extensions.rb +4 -3
- data/lib/acts_as_tenant/version.rb +1 -1
- data/lib/acts_as_tenant.rb +16 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 157bb94b2c59bdc0699a43f247141e44f4f8b9f41979186d678e996adfdbda2e
|
4
|
+
data.tar.gz: c4f559b0b12e8e92fc5025f9c926f437f01742cca85c91f4e3d306373a0e3492
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f843cea7abb50c0745b51e0850b93176c4a0713dcc875d62c733b4ff1df3b5cd7d9d2bf0b46de892af7009dfe106a3932d6698ed0132a2411466f43ecf243123
|
7
|
+
data.tar.gz: 1efe052c243a8fc2a7d857d559945f99646f237cb16c22dd6219ea4f94697f2ecd299384ca86bb57758cd37e7773186f2f75becb66998c5c00218ffa0a42f3fd
|
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.
|
@@ -272,7 +282,7 @@ end
|
|
272
282
|
```
|
273
283
|
|
274
284
|
You can add the following `belongs_to` options to `acts_as_tenant`:
|
275
|
-
`:foreign_key, :class_name, :inverse_of, :optional, :primary_key, :counter_cache`
|
285
|
+
`:foreign_key, :class_name, :inverse_of, :optional, :primary_key, :counter_cache, :polymorphic, :touch`
|
276
286
|
|
277
287
|
Example: `acts_as_tenant(:account, counter_cache: true)`
|
278
288
|
|
@@ -5,11 +5,12 @@ 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
|
|
11
12
|
# Create the association
|
12
|
-
valid_options = options.slice(:foreign_key, :class_name, :inverse_of, :optional, :primary_key, :counter_cache, :polymorphic)
|
13
|
+
valid_options = options.slice(:foreign_key, :class_name, :inverse_of, :optional, :primary_key, :counter_cache, :polymorphic, :touch)
|
13
14
|
fkey = valid_options[:foreign_key] || ActsAsTenant.fkey
|
14
15
|
pkey = valid_options[:primary_key] || ActsAsTenant.pkey
|
15
16
|
polymorphic_type = valid_options[:foreign_type] || ActsAsTenant.polymorphic_type
|
@@ -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
|
|
data/lib/acts_as_tenant.rb
CHANGED
@@ -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.
|
4
|
+
version: 0.6.1
|
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:
|
12
|
+
date: 2023-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: request_store
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
|
-
rubygems_version: 3.
|
174
|
+
rubygems_version: 3.4.4
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: Add multi-tenancy to Rails applications using a shared db strategy
|