acts_as_tenant 0.5.1 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -4
- data/lib/acts_as_tenant/errors.rb +0 -3
- data/lib/acts_as_tenant/model_extensions.rb +19 -9
- data/lib/acts_as_tenant/sidekiq.rb +12 -2
- data/lib/acts_as_tenant/version.rb +1 -1
- data/lib/acts_as_tenant.rb +19 -1
- metadata +4 -170
- data/spec/acts_as_tenant/configuration_spec.rb +0 -17
- data/spec/acts_as_tenant/sidekiq_spec.rb +0 -58
- data/spec/controllers/filter_spec.rb +0 -28
- data/spec/controllers/subdomain_or_domain_spec.rb +0 -55
- data/spec/controllers/subdomain_spec.rb +0 -49
- data/spec/dummy/.ruby-version +0 -1
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
- data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
- data/spec/dummy/app/controllers/application_controller.rb +0 -2
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/javascript/packs/application.js +0 -15
- data/spec/dummy/app/jobs/application_job.rb +0 -7
- data/spec/dummy/app/mailers/application_mailer.rb +0 -4
- data/spec/dummy/app/mailers/user_mailer.rb +0 -5
- data/spec/dummy/app/models/account.rb +0 -4
- data/spec/dummy/app/models/aliased_task.rb +0 -4
- data/spec/dummy/app/models/article.rb +0 -3
- data/spec/dummy/app/models/comment.rb +0 -5
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/custom_counter_cache_task.rb +0 -4
- data/spec/dummy/app/models/custom_foreign_key_task.rb +0 -4
- data/spec/dummy/app/models/custom_primary_key_task.rb +0 -4
- data/spec/dummy/app/models/global_project.rb +0 -6
- data/spec/dummy/app/models/global_project_with_conditions.rb +0 -6
- data/spec/dummy/app/models/global_project_with_if.rb +0 -6
- data/spec/dummy/app/models/manager.rb +0 -4
- data/spec/dummy/app/models/polymorphic_tenant_comment.rb +0 -5
- data/spec/dummy/app/models/project.rb +0 -8
- data/spec/dummy/app/models/task.rb +0 -7
- data/spec/dummy/app/models/unique_task.rb +0 -5
- data/spec/dummy/app/models/unscoped_model.rb +0 -3
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/bin/setup +0 -33
- data/spec/dummy/config/application.rb +0 -19
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/cable.yml +0 -10
- data/spec/dummy/config/database.yml +0 -19
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -62
- data/spec/dummy/config/environments/production.rb +0 -112
- data/spec/dummy/config/environments/test.rb +0 -49
- data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
- data/spec/dummy/config/initializers/assets.rb +0 -12
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/content_security_policy.rb +0 -28
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -40
- data/spec/dummy/config/puma.rb +0 -38
- data/spec/dummy/config/routes.rb +0 -4
- data/spec/dummy/config/spring.rb +0 -6
- data/spec/dummy/config/storage.yml +0 -34
- data/spec/dummy/config.ru +0 -5
- data/spec/dummy/db/schema.rb +0 -84
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/development_secret.txt +0 -1
- data/spec/fixtures/accounts.yml +0 -10
- data/spec/fixtures/custom_primary_key_tasks.yml +0 -2
- data/spec/fixtures/global_projects.yml +0 -13
- data/spec/fixtures/projects.yml +0 -10
- data/spec/helpers/tenant_helper_spec.rb +0 -16
- data/spec/middlewares/test_tenant_middleware_spec.rb +0 -86
- data/spec/models/model_extensions_spec.rb +0 -413
- data/spec/spec_helper.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df411b08fd69234fdd767f98232148eef42a147986b9417eb08f8f0dbdbd5479
|
4
|
+
data.tar.gz: 25b9bdd0ab15e9b08ddea8b7b310a7d2968529b882409551209d4a59b9157a20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 119a2b3e43b5a04f589f352943121d483d12c4ab44ec73ef493453bccc749fb512236f647eedc82a88bcdb13968627f3471b0f1a67f9e5a8c13080d3307393d1
|
7
|
+
data.tar.gz: '080c80a34f7c5f8dc1c235c3ebaa28f98ba97566776749de51ca9e4e6e795d2da21e19270d66d34b3633679233c8553237f012eb1b250224f75855584399e2da'
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Row-level multitenancy each model must have a tenant ID column on it. This make
|
|
25
25
|
|
26
26
|
Schema multitenancy uses database schemas to handle multitenancy. For this approach, your database has multiple schemas and each schema contains your database tables. Schemas require migrations to be run against each tenant and generally makes it harder to scale as you add more tenants. The Apartment gem uses schema multitenancy.
|
27
27
|
|
28
|
-
#### 🎬 Walkthrough
|
28
|
+
#### 🎬 Walkthrough
|
29
29
|
|
30
30
|
Want to see how it works? Check out [the ActsAsTenant walkthrough video](https://www.youtube.com/watch?v=BIyxM9f8Jus):
|
31
31
|
|
@@ -101,7 +101,7 @@ Setting the `current_tenant` yourself, requires you to declare `set_current_tena
|
|
101
101
|
|
102
102
|
If you are setting the tenant in a specific controller (except `application_controller`), it should to be included **AT THE TOP** of the file.
|
103
103
|
|
104
|
-
```
|
104
|
+
```ruby
|
105
105
|
class MembersController < ActionController::Base
|
106
106
|
set_current_tenant_through_filter
|
107
107
|
before_action :set_tenant
|
@@ -210,6 +210,28 @@ You can also explicitly specifiy a primary_key for AaT to use should the key dif
|
|
210
210
|
acts_as_tenant(:account, :primary_key => 'primaryID') # by default AaT expects id
|
211
211
|
```
|
212
212
|
|
213
|
+
|
214
|
+
### Has and belongs to many ###
|
215
|
+
|
216
|
+
You can scope a model that is part of a HABTM relationship by using the `through` option.
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
class Organisation < ActiveRecord::Base
|
220
|
+
has_many :organisations_users
|
221
|
+
has_many :users, through: :organisations_users
|
222
|
+
end
|
223
|
+
|
224
|
+
class User < ActiveRecord::Base
|
225
|
+
has_many :organisations_users
|
226
|
+
acts_as_tenant :organisation, through: :organisations_users
|
227
|
+
end
|
228
|
+
|
229
|
+
class OrganisationsUser < ActiveRecord::Base
|
230
|
+
belongs_to :user
|
231
|
+
acts_as_tenant :organisation
|
232
|
+
end
|
233
|
+
```
|
234
|
+
|
213
235
|
Configuration options
|
214
236
|
---------------------
|
215
237
|
An initializer can be created to control (currently one) option in ActsAsTenant. Defaults
|
@@ -223,12 +245,26 @@ end
|
|
223
245
|
|
224
246
|
* `config.require_tenant` when set to true will raise an ActsAsTenant::NoTenant error whenever a query is made without a tenant set.
|
225
247
|
|
248
|
+
`config.require_tenant` can also be assigned a lambda that is evaluated at run time. For example:
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
ActsAsTenant.configure do |config|
|
252
|
+
config.require_tenant = lambda do
|
253
|
+
if $request_env.present?
|
254
|
+
return false if $request_env["REQUEST_PATH"].start_with?("/admin/")
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
```
|
259
|
+
|
260
|
+
`ActsAsTenant.should_require_tenant?` is used to determine if a tenant is required in the current context, either by evaluating the lambda provided, or by returning the boolean value assigned to `config.require_tenant`.
|
261
|
+
|
226
262
|
belongs_to options
|
227
263
|
---------------------
|
228
|
-
`acts_as_tenant :account` includes the belongs_to relationship.
|
264
|
+
`acts_as_tenant :account` includes the belongs_to relationship.
|
229
265
|
So when using acts_as_tenant on a model, do not add `belongs_to :account` alongside `acts_as_tenant :account`:
|
230
266
|
|
231
|
-
```
|
267
|
+
```ruby
|
232
268
|
class User < ActiveRecord::Base
|
233
269
|
acts_as_tenant(:account) # YES
|
234
270
|
belongs_to :account # REDUNDANT
|
@@ -9,14 +9,14 @@ module ActsAsTenant
|
|
9
9
|
ActsAsTenant.add_global_record_model(self) if options[:has_global_records]
|
10
10
|
|
11
11
|
# Create the association
|
12
|
-
valid_options = options.slice(:foreign_key, :class_name, :inverse_of, :optional, :primary_key, :counter_cache)
|
12
|
+
valid_options = options.slice(:foreign_key, :class_name, :inverse_of, :optional, :primary_key, :counter_cache, :polymorphic)
|
13
13
|
fkey = valid_options[:foreign_key] || ActsAsTenant.fkey
|
14
14
|
pkey = valid_options[:primary_key] || ActsAsTenant.pkey
|
15
15
|
polymorphic_type = valid_options[:foreign_type] || ActsAsTenant.polymorphic_type
|
16
16
|
belongs_to tenant, **valid_options
|
17
17
|
|
18
18
|
default_scope lambda {
|
19
|
-
if ActsAsTenant.
|
19
|
+
if ActsAsTenant.should_require_tenant? && ActsAsTenant.current_tenant.nil? && !ActsAsTenant.unscoped?
|
20
20
|
raise ActsAsTenant::Errors::NoTenantSet
|
21
21
|
end
|
22
22
|
|
@@ -24,9 +24,15 @@ module ActsAsTenant
|
|
24
24
|
keys = [ActsAsTenant.current_tenant.send(pkey)].compact
|
25
25
|
keys.push(nil) if options[:has_global_records]
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
if options[:through]
|
28
|
+
query_criteria = {options[:through] => {fkey.to_sym => keys}}
|
29
|
+
query_criteria[polymorphic_type.to_sym] = ActsAsTenant.current_tenant.class.to_s if options[:polymorphic]
|
30
|
+
joins(options[:through]).where(query_criteria)
|
31
|
+
else
|
32
|
+
query_criteria = {fkey.to_sym => keys}
|
33
|
+
query_criteria[polymorphic_type.to_sym] = ActsAsTenant.current_tenant.class.to_s if options[:polymorphic]
|
34
|
+
where(query_criteria)
|
35
|
+
end
|
30
36
|
else
|
31
37
|
all
|
32
38
|
end
|
@@ -71,15 +77,19 @@ module ActsAsTenant
|
|
71
77
|
to_include = Module.new {
|
72
78
|
define_method "#{fkey}=" do |integer|
|
73
79
|
write_attribute(fkey.to_s, integer)
|
74
|
-
raise ActsAsTenant::Errors::TenantIsImmutable if
|
80
|
+
raise ActsAsTenant::Errors::TenantIsImmutable if tenant_modified?
|
75
81
|
integer
|
76
82
|
end
|
77
83
|
|
78
84
|
define_method "#{ActsAsTenant.tenant_klass}=" do |model|
|
79
85
|
super(model)
|
80
|
-
raise ActsAsTenant::Errors::TenantIsImmutable if
|
86
|
+
raise ActsAsTenant::Errors::TenantIsImmutable if tenant_modified?
|
81
87
|
model
|
82
88
|
end
|
89
|
+
|
90
|
+
define_method :tenant_modified? do
|
91
|
+
will_save_change_to_attribute?(fkey) && persisted? && attribute_in_database(fkey).present?
|
92
|
+
end
|
83
93
|
}
|
84
94
|
include to_include
|
85
95
|
|
@@ -95,9 +105,9 @@ module ActsAsTenant
|
|
95
105
|
|
96
106
|
fkey = reflect_on_association(ActsAsTenant.tenant_klass).foreign_key
|
97
107
|
|
98
|
-
validation_args = args.
|
108
|
+
validation_args = args.deep_dup
|
99
109
|
validation_args[:scope] = if args[:scope]
|
100
|
-
Array(args[:scope])
|
110
|
+
Array(args[:scope]) + [fkey]
|
101
111
|
else
|
102
112
|
fkey
|
103
113
|
end
|
@@ -1,6 +1,14 @@
|
|
1
1
|
module ActsAsTenant::Sidekiq
|
2
|
+
class BaseMiddleware
|
3
|
+
def self.sidekiq_7_and_up?
|
4
|
+
Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("7")
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
2
8
|
# Get the current tenant and store in the message to be sent to Sidekiq.
|
3
|
-
class Client
|
9
|
+
class Client < BaseMiddleware
|
10
|
+
include Sidekiq::ClientMiddleware if sidekiq_7_and_up?
|
11
|
+
|
4
12
|
def call(worker_class, msg, queue, redis_pool)
|
5
13
|
if ActsAsTenant.current_tenant.present?
|
6
14
|
msg["acts_as_tenant"] ||=
|
@@ -15,7 +23,9 @@ module ActsAsTenant::Sidekiq
|
|
15
23
|
end
|
16
24
|
|
17
25
|
# Pull the tenant out and run the current thread with it.
|
18
|
-
class Server
|
26
|
+
class Server < BaseMiddleware
|
27
|
+
include Sidekiq::ServerMiddleware if sidekiq_7_and_up?
|
28
|
+
|
19
29
|
def call(worker_class, msg, queue)
|
20
30
|
if msg.has_key?("acts_as_tenant")
|
21
31
|
account = msg["acts_as_tenant"]["class"].constantize.find msg["acts_as_tenant"]["id"]
|
data/lib/acts_as_tenant.rb
CHANGED
@@ -14,7 +14,6 @@ module ActsAsTenant
|
|
14
14
|
@@models_with_global_records = []
|
15
15
|
|
16
16
|
class << self
|
17
|
-
attr_accessor :test_tenant
|
18
17
|
attr_writer :default_tenant
|
19
18
|
end
|
20
19
|
|
@@ -64,6 +63,14 @@ module ActsAsTenant
|
|
64
63
|
RequestStore.store[:current_tenant] || test_tenant || default_tenant
|
65
64
|
end
|
66
65
|
|
66
|
+
def self.test_tenant=(tenant)
|
67
|
+
Thread.current[:test_tenant] = tenant
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.test_tenant
|
71
|
+
Thread.current[:test_tenant]
|
72
|
+
end
|
73
|
+
|
67
74
|
def self.unscoped=(unscoped)
|
68
75
|
RequestStore.store[:acts_as_tenant_unscoped] = unscoped
|
69
76
|
end
|
@@ -99,16 +106,27 @@ module ActsAsTenant
|
|
99
106
|
end
|
100
107
|
|
101
108
|
old_tenant = current_tenant
|
109
|
+
old_test_tenant = test_tenant
|
102
110
|
old_unscoped = unscoped
|
103
111
|
|
104
112
|
self.current_tenant = nil
|
113
|
+
self.test_tenant = nil
|
105
114
|
self.unscoped = true
|
106
115
|
value = block.call
|
107
116
|
value
|
108
117
|
ensure
|
109
118
|
self.current_tenant = old_tenant
|
119
|
+
self.test_tenant = old_test_tenant
|
110
120
|
self.unscoped = old_unscoped
|
111
121
|
end
|
122
|
+
|
123
|
+
def self.should_require_tenant?
|
124
|
+
if configuration.require_tenant.respond_to?(:call)
|
125
|
+
!!configuration.require_tenant.call
|
126
|
+
else
|
127
|
+
!!configuration.require_tenant
|
128
|
+
end
|
129
|
+
end
|
112
130
|
end
|
113
131
|
|
114
132
|
ActiveSupport.on_load(:active_record) do |base|
|
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.
|
4
|
+
version: 0.5.3
|
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: 2022-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: request_store
|
@@ -153,89 +153,6 @@ files:
|
|
153
153
|
- lib/acts_as_tenant/tenant_helper.rb
|
154
154
|
- lib/acts_as_tenant/test_tenant_middleware.rb
|
155
155
|
- lib/acts_as_tenant/version.rb
|
156
|
-
- spec/acts_as_tenant/configuration_spec.rb
|
157
|
-
- spec/acts_as_tenant/sidekiq_spec.rb
|
158
|
-
- spec/controllers/filter_spec.rb
|
159
|
-
- spec/controllers/subdomain_or_domain_spec.rb
|
160
|
-
- spec/controllers/subdomain_spec.rb
|
161
|
-
- spec/dummy/.ruby-version
|
162
|
-
- spec/dummy/Rakefile
|
163
|
-
- spec/dummy/app/assets/config/manifest.js
|
164
|
-
- spec/dummy/app/assets/images/.keep
|
165
|
-
- spec/dummy/app/assets/stylesheets/application.css
|
166
|
-
- spec/dummy/app/channels/application_cable/channel.rb
|
167
|
-
- spec/dummy/app/channels/application_cable/connection.rb
|
168
|
-
- spec/dummy/app/controllers/application_controller.rb
|
169
|
-
- spec/dummy/app/controllers/concerns/.keep
|
170
|
-
- spec/dummy/app/helpers/application_helper.rb
|
171
|
-
- spec/dummy/app/javascript/packs/application.js
|
172
|
-
- spec/dummy/app/jobs/application_job.rb
|
173
|
-
- spec/dummy/app/mailers/application_mailer.rb
|
174
|
-
- spec/dummy/app/mailers/user_mailer.rb
|
175
|
-
- spec/dummy/app/models/account.rb
|
176
|
-
- spec/dummy/app/models/aliased_task.rb
|
177
|
-
- spec/dummy/app/models/article.rb
|
178
|
-
- spec/dummy/app/models/comment.rb
|
179
|
-
- spec/dummy/app/models/concerns/.keep
|
180
|
-
- spec/dummy/app/models/custom_counter_cache_task.rb
|
181
|
-
- spec/dummy/app/models/custom_foreign_key_task.rb
|
182
|
-
- spec/dummy/app/models/custom_primary_key_task.rb
|
183
|
-
- spec/dummy/app/models/global_project.rb
|
184
|
-
- spec/dummy/app/models/global_project_with_conditions.rb
|
185
|
-
- spec/dummy/app/models/global_project_with_if.rb
|
186
|
-
- spec/dummy/app/models/manager.rb
|
187
|
-
- spec/dummy/app/models/polymorphic_tenant_comment.rb
|
188
|
-
- spec/dummy/app/models/project.rb
|
189
|
-
- spec/dummy/app/models/task.rb
|
190
|
-
- spec/dummy/app/models/unique_task.rb
|
191
|
-
- spec/dummy/app/models/unscoped_model.rb
|
192
|
-
- spec/dummy/app/views/layouts/application.html.erb
|
193
|
-
- spec/dummy/app/views/layouts/mailer.html.erb
|
194
|
-
- spec/dummy/app/views/layouts/mailer.text.erb
|
195
|
-
- spec/dummy/bin/rails
|
196
|
-
- spec/dummy/bin/rake
|
197
|
-
- spec/dummy/bin/setup
|
198
|
-
- spec/dummy/config.ru
|
199
|
-
- spec/dummy/config/application.rb
|
200
|
-
- spec/dummy/config/boot.rb
|
201
|
-
- spec/dummy/config/cable.yml
|
202
|
-
- spec/dummy/config/database.yml
|
203
|
-
- spec/dummy/config/environment.rb
|
204
|
-
- spec/dummy/config/environments/development.rb
|
205
|
-
- spec/dummy/config/environments/production.rb
|
206
|
-
- spec/dummy/config/environments/test.rb
|
207
|
-
- spec/dummy/config/initializers/application_controller_renderer.rb
|
208
|
-
- spec/dummy/config/initializers/assets.rb
|
209
|
-
- spec/dummy/config/initializers/backtrace_silencers.rb
|
210
|
-
- spec/dummy/config/initializers/content_security_policy.rb
|
211
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
212
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
213
|
-
- spec/dummy/config/initializers/inflections.rb
|
214
|
-
- spec/dummy/config/initializers/mime_types.rb
|
215
|
-
- spec/dummy/config/initializers/wrap_parameters.rb
|
216
|
-
- spec/dummy/config/locales/en.yml
|
217
|
-
- spec/dummy/config/puma.rb
|
218
|
-
- spec/dummy/config/routes.rb
|
219
|
-
- spec/dummy/config/spring.rb
|
220
|
-
- spec/dummy/config/storage.yml
|
221
|
-
- spec/dummy/db/schema.rb
|
222
|
-
- spec/dummy/lib/assets/.keep
|
223
|
-
- spec/dummy/log/.keep
|
224
|
-
- spec/dummy/public/404.html
|
225
|
-
- spec/dummy/public/422.html
|
226
|
-
- spec/dummy/public/500.html
|
227
|
-
- spec/dummy/public/apple-touch-icon-precomposed.png
|
228
|
-
- spec/dummy/public/apple-touch-icon.png
|
229
|
-
- spec/dummy/public/favicon.ico
|
230
|
-
- spec/dummy/tmp/development_secret.txt
|
231
|
-
- spec/fixtures/accounts.yml
|
232
|
-
- spec/fixtures/custom_primary_key_tasks.yml
|
233
|
-
- spec/fixtures/global_projects.yml
|
234
|
-
- spec/fixtures/projects.yml
|
235
|
-
- spec/helpers/tenant_helper_spec.rb
|
236
|
-
- spec/middlewares/test_tenant_middleware_spec.rb
|
237
|
-
- spec/models/model_extensions_spec.rb
|
238
|
-
- spec/spec_helper.rb
|
239
156
|
homepage: https://github.com/ErwinM/acts_as_tenant
|
240
157
|
licenses: []
|
241
158
|
metadata: {}
|
@@ -254,91 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
171
|
- !ruby/object:Gem::Version
|
255
172
|
version: '0'
|
256
173
|
requirements: []
|
257
|
-
rubygems_version: 3.
|
174
|
+
rubygems_version: 3.3.26
|
258
175
|
signing_key:
|
259
176
|
specification_version: 4
|
260
177
|
summary: Add multi-tenancy to Rails applications using a shared db strategy
|
261
|
-
test_files:
|
262
|
-
- spec/acts_as_tenant/configuration_spec.rb
|
263
|
-
- spec/acts_as_tenant/sidekiq_spec.rb
|
264
|
-
- spec/controllers/filter_spec.rb
|
265
|
-
- spec/controllers/subdomain_or_domain_spec.rb
|
266
|
-
- spec/controllers/subdomain_spec.rb
|
267
|
-
- spec/dummy/.ruby-version
|
268
|
-
- spec/dummy/Rakefile
|
269
|
-
- spec/dummy/app/assets/config/manifest.js
|
270
|
-
- spec/dummy/app/assets/images/.keep
|
271
|
-
- spec/dummy/app/assets/stylesheets/application.css
|
272
|
-
- spec/dummy/app/channels/application_cable/channel.rb
|
273
|
-
- spec/dummy/app/channels/application_cable/connection.rb
|
274
|
-
- spec/dummy/app/controllers/application_controller.rb
|
275
|
-
- spec/dummy/app/controllers/concerns/.keep
|
276
|
-
- spec/dummy/app/helpers/application_helper.rb
|
277
|
-
- spec/dummy/app/javascript/packs/application.js
|
278
|
-
- spec/dummy/app/jobs/application_job.rb
|
279
|
-
- spec/dummy/app/mailers/application_mailer.rb
|
280
|
-
- spec/dummy/app/mailers/user_mailer.rb
|
281
|
-
- spec/dummy/app/models/account.rb
|
282
|
-
- spec/dummy/app/models/aliased_task.rb
|
283
|
-
- spec/dummy/app/models/article.rb
|
284
|
-
- spec/dummy/app/models/comment.rb
|
285
|
-
- spec/dummy/app/models/concerns/.keep
|
286
|
-
- spec/dummy/app/models/custom_counter_cache_task.rb
|
287
|
-
- spec/dummy/app/models/custom_foreign_key_task.rb
|
288
|
-
- spec/dummy/app/models/custom_primary_key_task.rb
|
289
|
-
- spec/dummy/app/models/global_project.rb
|
290
|
-
- spec/dummy/app/models/global_project_with_conditions.rb
|
291
|
-
- spec/dummy/app/models/global_project_with_if.rb
|
292
|
-
- spec/dummy/app/models/manager.rb
|
293
|
-
- spec/dummy/app/models/polymorphic_tenant_comment.rb
|
294
|
-
- spec/dummy/app/models/project.rb
|
295
|
-
- spec/dummy/app/models/task.rb
|
296
|
-
- spec/dummy/app/models/unique_task.rb
|
297
|
-
- spec/dummy/app/models/unscoped_model.rb
|
298
|
-
- spec/dummy/app/views/layouts/application.html.erb
|
299
|
-
- spec/dummy/app/views/layouts/mailer.html.erb
|
300
|
-
- spec/dummy/app/views/layouts/mailer.text.erb
|
301
|
-
- spec/dummy/bin/rails
|
302
|
-
- spec/dummy/bin/rake
|
303
|
-
- spec/dummy/bin/setup
|
304
|
-
- spec/dummy/config.ru
|
305
|
-
- spec/dummy/config/application.rb
|
306
|
-
- spec/dummy/config/boot.rb
|
307
|
-
- spec/dummy/config/cable.yml
|
308
|
-
- spec/dummy/config/database.yml
|
309
|
-
- spec/dummy/config/environment.rb
|
310
|
-
- spec/dummy/config/environments/development.rb
|
311
|
-
- spec/dummy/config/environments/production.rb
|
312
|
-
- spec/dummy/config/environments/test.rb
|
313
|
-
- spec/dummy/config/initializers/application_controller_renderer.rb
|
314
|
-
- spec/dummy/config/initializers/assets.rb
|
315
|
-
- spec/dummy/config/initializers/backtrace_silencers.rb
|
316
|
-
- spec/dummy/config/initializers/content_security_policy.rb
|
317
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
318
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
319
|
-
- spec/dummy/config/initializers/inflections.rb
|
320
|
-
- spec/dummy/config/initializers/mime_types.rb
|
321
|
-
- spec/dummy/config/initializers/wrap_parameters.rb
|
322
|
-
- spec/dummy/config/locales/en.yml
|
323
|
-
- spec/dummy/config/puma.rb
|
324
|
-
- spec/dummy/config/routes.rb
|
325
|
-
- spec/dummy/config/spring.rb
|
326
|
-
- spec/dummy/config/storage.yml
|
327
|
-
- spec/dummy/db/schema.rb
|
328
|
-
- spec/dummy/lib/assets/.keep
|
329
|
-
- spec/dummy/log/.keep
|
330
|
-
- spec/dummy/public/404.html
|
331
|
-
- spec/dummy/public/422.html
|
332
|
-
- spec/dummy/public/500.html
|
333
|
-
- spec/dummy/public/apple-touch-icon-precomposed.png
|
334
|
-
- spec/dummy/public/apple-touch-icon.png
|
335
|
-
- spec/dummy/public/favicon.ico
|
336
|
-
- spec/dummy/tmp/development_secret.txt
|
337
|
-
- spec/fixtures/accounts.yml
|
338
|
-
- spec/fixtures/custom_primary_key_tasks.yml
|
339
|
-
- spec/fixtures/global_projects.yml
|
340
|
-
- spec/fixtures/projects.yml
|
341
|
-
- spec/helpers/tenant_helper_spec.rb
|
342
|
-
- spec/middlewares/test_tenant_middleware_spec.rb
|
343
|
-
- spec/models/model_extensions_spec.rb
|
344
|
-
- spec/spec_helper.rb
|
178
|
+
test_files: []
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe ActsAsTenant::Configuration do
|
4
|
-
after { ActsAsTenant.configure }
|
5
|
-
|
6
|
-
it "provides defaults" do
|
7
|
-
expect(ActsAsTenant.configuration.require_tenant).not_to be_truthy
|
8
|
-
end
|
9
|
-
|
10
|
-
it "stores config" do
|
11
|
-
ActsAsTenant.configure do |config|
|
12
|
-
config.require_tenant = true
|
13
|
-
end
|
14
|
-
|
15
|
-
expect(ActsAsTenant.configuration.require_tenant).to eq(true)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "sidekiq"
|
3
|
-
require "acts_as_tenant/sidekiq"
|
4
|
-
|
5
|
-
describe ActsAsTenant::Sidekiq do
|
6
|
-
let(:account) { Account.new(id: 1234) }
|
7
|
-
let(:message) { {"acts_as_tenant" => {"class" => "Account", "id" => 1234}} }
|
8
|
-
|
9
|
-
describe ActsAsTenant::Sidekiq::Client do
|
10
|
-
subject { ActsAsTenant::Sidekiq::Client.new }
|
11
|
-
|
12
|
-
it "saves tenant if present" do
|
13
|
-
ActsAsTenant.current_tenant = account
|
14
|
-
|
15
|
-
msg = {}
|
16
|
-
subject.call(nil, msg, nil, nil) {}
|
17
|
-
expect(msg).to eq message
|
18
|
-
end
|
19
|
-
|
20
|
-
it "does not set tenant if not present" do
|
21
|
-
expect(ActsAsTenant.current_tenant).to be_nil
|
22
|
-
|
23
|
-
msg = {}
|
24
|
-
subject.call(nil, msg, nil, nil) {}
|
25
|
-
expect(msg).not_to eq message
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe ActsAsTenant::Sidekiq::Server do
|
30
|
-
subject { ActsAsTenant::Sidekiq::Server.new }
|
31
|
-
|
32
|
-
it "restores tenant if tenant saved" do
|
33
|
-
expect(Account).to receive(:find).with(1234).once { account }
|
34
|
-
|
35
|
-
msg = message
|
36
|
-
subject.call(nil, msg, nil) do
|
37
|
-
expect(ActsAsTenant.current_tenant).to be_a_kind_of Account
|
38
|
-
end
|
39
|
-
expect(ActsAsTenant.current_tenant).to be_nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it "runs without tenant if no tenant saved" do
|
43
|
-
expect(Account).not_to receive(:find)
|
44
|
-
|
45
|
-
msg = {}
|
46
|
-
subject.call(nil, msg, nil) do
|
47
|
-
expect(ActsAsTenant.current_tenant).to be_nil
|
48
|
-
end
|
49
|
-
expect(ActsAsTenant.current_tenant).to be_nil
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "includes ActsAsTenant client middleware" do
|
54
|
-
expect(Sidekiq.client_middleware.exists?(ActsAsTenant::Sidekiq::Client)).to eq(true)
|
55
|
-
end
|
56
|
-
|
57
|
-
# unable to test server configuration
|
58
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
class ApplicationController2 < ActionController::Base
|
4
|
-
include Rails.application.routes.url_helpers
|
5
|
-
set_current_tenant_through_filter
|
6
|
-
before_action :your_method_that_finds_the_current_tenant
|
7
|
-
|
8
|
-
def your_method_that_finds_the_current_tenant
|
9
|
-
current_account = Account.new(name: "account1")
|
10
|
-
set_current_tenant(current_account)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# Start testing
|
15
|
-
describe ApplicationController2, type: :controller do
|
16
|
-
controller do
|
17
|
-
def index
|
18
|
-
# Exercise current_tenant helper method
|
19
|
-
render plain: current_tenant.name
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it "Finds the correct tenant using the filter command" do
|
24
|
-
get :index
|
25
|
-
expect(ActsAsTenant.current_tenant.name).to eq "account1"
|
26
|
-
expect(response.body).to eq "account1"
|
27
|
-
end
|
28
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
class DomainController < ActionController::Base
|
4
|
-
include Rails.application.routes.url_helpers
|
5
|
-
set_current_tenant_by_subdomain_or_domain
|
6
|
-
end
|
7
|
-
|
8
|
-
describe DomainController, type: :controller do
|
9
|
-
let(:account) { accounts(:with_domain) }
|
10
|
-
|
11
|
-
controller do
|
12
|
-
def index
|
13
|
-
# Exercise current_tenant helper method
|
14
|
-
render plain: current_tenant.name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "finds the correct tenant with a example1.com" do
|
19
|
-
@request.host = account.domain
|
20
|
-
get :index
|
21
|
-
expect(ActsAsTenant.current_tenant).to eq account
|
22
|
-
expect(response.body).to eq account.name
|
23
|
-
end
|
24
|
-
|
25
|
-
it "finds the correct tenant with a subdomain.example.com" do
|
26
|
-
@request.host = "#{account.subdomain}.example.com"
|
27
|
-
get :index
|
28
|
-
expect(ActsAsTenant.current_tenant).to eq account
|
29
|
-
expect(response.body).to eq account.name
|
30
|
-
end
|
31
|
-
|
32
|
-
it "finds the correct tenant with a www.subdomain.example.com" do
|
33
|
-
@request.host = "www.#{account.subdomain}.example.com"
|
34
|
-
get :index
|
35
|
-
expect(ActsAsTenant.current_tenant).to eq account
|
36
|
-
end
|
37
|
-
|
38
|
-
it "ignores case when finding tenant by subdomain" do
|
39
|
-
@request.host = "#{account.subdomain.upcase}.example.com"
|
40
|
-
get :index
|
41
|
-
expect(ActsAsTenant.current_tenant).to eq account
|
42
|
-
end
|
43
|
-
|
44
|
-
context "overriding subdomain lookup" do
|
45
|
-
after { controller.subdomain_lookup = :last }
|
46
|
-
|
47
|
-
it "allows overriding the subdomain lookup" do
|
48
|
-
controller.subdomain_lookup = :first
|
49
|
-
@request.host = "#{account.subdomain}.another.example.com"
|
50
|
-
get :index
|
51
|
-
expect(ActsAsTenant.current_tenant).to eq account
|
52
|
-
expect(response.body).to eq(account.subdomain)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
class SubdomainController < ActionController::Base
|
4
|
-
include Rails.application.routes.url_helpers
|
5
|
-
set_current_tenant_by_subdomain
|
6
|
-
end
|
7
|
-
|
8
|
-
describe SubdomainController, type: :controller do
|
9
|
-
let(:account) { accounts(:with_domain) }
|
10
|
-
|
11
|
-
controller(SubdomainController) do
|
12
|
-
def index
|
13
|
-
# Exercise current_tenant helper method
|
14
|
-
render plain: current_tenant.name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "finds the correct tenant with a subdomain.example.com" do
|
19
|
-
@request.host = "#{account.subdomain}.example.com"
|
20
|
-
get :index
|
21
|
-
expect(ActsAsTenant.current_tenant).to eq account
|
22
|
-
expect(response.body).to eq(account.subdomain)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "finds the correct tenant with a www.subdomain.example.com" do
|
26
|
-
@request.host = "www.#{account.subdomain}.example.com"
|
27
|
-
get :index
|
28
|
-
expect(ActsAsTenant.current_tenant).to eq account
|
29
|
-
expect(response.body).to eq(account.subdomain)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "ignores case when finding tenant by subdomain" do
|
33
|
-
@request.host = "#{account.subdomain.upcase}.example.com"
|
34
|
-
get :index
|
35
|
-
expect(ActsAsTenant.current_tenant).to eq account
|
36
|
-
end
|
37
|
-
|
38
|
-
context "overriding subdomain lookup" do
|
39
|
-
after { controller.subdomain_lookup = :last }
|
40
|
-
|
41
|
-
it "allows overriding the subdomain lookup" do
|
42
|
-
controller.subdomain_lookup = :first
|
43
|
-
@request.host = "#{account.subdomain}.another.example.com"
|
44
|
-
get :index
|
45
|
-
expect(ActsAsTenant.current_tenant).to eq account
|
46
|
-
expect(response.body).to eq(account.subdomain)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/spec/dummy/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.7.1
|