multi_client 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -5
- data/app/controllers/concerns/multi_client/controller_with_client.rb +2 -2
- data/app/exceptions/unscoped_forbidden_error.rb +1 -1
- data/app/helpers/multi_client_helper.rb +1 -1
- data/app/models/concerns/multi_client/model_with_client.rb +10 -17
- data/lib/generators/multi_client/install/install_generator.rb +3 -3
- data/lib/generators/multi_client/install/templates/multi_client.rb +40 -0
- data/lib/multi_client/configuration.rb +4 -0
- data/lib/multi_client/no_subdomain.rb +1 -1
- data/lib/multi_client/subdomain.rb +1 -1
- data/lib/multi_client/version.rb +1 -1
- data/lib/multi_client.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b44ece79b0218ae58e6e4c2a7331ffe257f7654
|
4
|
+
data.tar.gz: 233c3b8ebabfba00eccf49881cf36a5f991373e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 182613c3ea3f06da0d634aa7b55fecdb89b79875903089ebba085aa23e9a0aa6341ac51cf486bd2ba1504c24940bf3d03004610faab2f6fe5dc2dd0d8eded802
|
7
|
+
data.tar.gz: 0db9559ccab05da28ab07dc01f93fd88b8761910ef76898f1cf89f357c533c00e16149ce505342866dd16412bd9890e32e856f475a857c165084e7fe5996a5bb
|
data/Rakefile
CHANGED
@@ -14,13 +14,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
17
|
-
APP_RAKEFILE = File.expand_path(
|
17
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
18
18
|
load 'rails/tasks/engine.rake'
|
19
19
|
|
20
|
-
|
21
20
|
load 'rails/tasks/statistics.rake'
|
22
21
|
|
23
|
-
|
24
|
-
|
25
22
|
Bundler::GemHelper.install_tasks
|
26
|
-
|
@@ -19,7 +19,7 @@ module MultiClient
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def set_current_client
|
22
|
-
redirect_to
|
22
|
+
redirect_to(root_url(subdomain: 'www')) && return unless current_client = client_class.enabled.find_by_subdomain(request.subdomains.first)
|
23
23
|
client_class.current_id = current_client.id
|
24
24
|
begin
|
25
25
|
yield
|
@@ -28,4 +28,4 @@ module MultiClient
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
class UnscopedForbiddenError < StandardError
|
2
|
-
end
|
2
|
+
end
|
@@ -5,38 +5,31 @@ module MultiClient
|
|
5
5
|
included do
|
6
6
|
klass = Class.new(self) do
|
7
7
|
default_scope { unscoped }
|
8
|
-
|
8
|
+
|
9
9
|
def unscoped
|
10
10
|
super
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
const_set 'Unscoped', klass
|
14
14
|
|
15
15
|
belongs_to MultiClient::Configuration.method_name.to_sym, class_name: MultiClient::Configuration.model_name
|
16
16
|
|
17
|
-
scope "for_current_#{MultiClient::Configuration.method_name}".to_sym,
|
17
|
+
scope "for_current_#{MultiClient::Configuration.method_name}".to_sym, -> { where(MultiClient::Configuration.foreign_key.to_sym => MultiClient::Configuration.model_name.constantize.current_id) }
|
18
18
|
default_scope { send("for_current_#{MultiClient::Configuration.method_name}".to_sym) }
|
19
19
|
|
20
20
|
validates MultiClient::Configuration.foreign_key.to_sym, presence: true
|
21
21
|
|
22
|
-
::MultiClient::Client.has_many
|
23
|
-
|
22
|
+
::MultiClient::Client.has_many name.demodulize.underscore.pluralize.to_sym, class_name: "::#{name}", foreign_key: MultiClient::Configuration.foreign_key.to_sym
|
24
23
|
end
|
25
24
|
|
26
25
|
class_methods do
|
27
26
|
def unscoped
|
28
|
-
return super if
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
|
34
|
-
if ['_create_record', 'scope', 'validate_each', 'eval_scope', '_update_record', 'aggregate_column', 'bottom_item', 'scope_for_slug_generator', 'update_counters'].include?(caller_locations(1,1)[0].label)
|
35
|
-
super
|
36
|
-
else
|
37
|
-
raise UnscopedForbiddenError, "Calling unscoped from #{caller_locations(1,1)[0].label} is not allowed to prevent client data leakage"
|
38
|
-
end
|
27
|
+
return super if name.demodulize == 'Unscoped'
|
28
|
+
caller = caller_locations(1, 1)[0].label
|
29
|
+
return where(MultiClient::Configuration.foreign_key.to_sym => MultiClient::Configuration.model_name.constantize.current_id) if MultiClient::Configuration.force_client_scope_for_unscoped_callers.include?(caller)
|
30
|
+
return super if MultiClient::Configuration.allowed_unscoped_callers.include?(caller)
|
31
|
+
raise UnscopedForbiddenError, "Calling unscoped from #{caller} is not allowed to prevent client data leakage"
|
39
32
|
end
|
40
33
|
end
|
41
34
|
end
|
42
|
-
end
|
35
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module MultiClient
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
|
-
desc
|
4
|
+
desc 'Generates the initializer'
|
5
5
|
|
6
6
|
source_root File.expand_path('../templates', __FILE__)
|
7
7
|
|
8
8
|
def generate_intializer
|
9
|
-
copy_file
|
9
|
+
copy_file 'multi_client.rb', 'config/initializers/multi_client.rb'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
@@ -13,4 +13,44 @@ MultiClient.configure do |config|
|
|
13
13
|
#
|
14
14
|
# default: config.method_name = 'client'
|
15
15
|
config.method_name = 'client'
|
16
|
+
|
17
|
+
# Calling unscoped is blocked to prevent data leakage. You can define
|
18
|
+
# exceptions here.
|
19
|
+
#
|
20
|
+
# default: config.allowed_unscoped_callers = %w(
|
21
|
+
# _create_record
|
22
|
+
# _update_record
|
23
|
+
# aggregate_column
|
24
|
+
# bottom_item
|
25
|
+
# eval_scope
|
26
|
+
# relation_for_destroy
|
27
|
+
# reload
|
28
|
+
# scope
|
29
|
+
# scope_for_slug_generator
|
30
|
+
# update_counters
|
31
|
+
# update_positions
|
32
|
+
# validate_each
|
33
|
+
# )
|
34
|
+
#
|
35
|
+
config.allowed_unscoped_callers = %w(
|
36
|
+
_create_record
|
37
|
+
_update_record
|
38
|
+
aggregate_column
|
39
|
+
bottom_item
|
40
|
+
eval_scope
|
41
|
+
relation_for_destroy
|
42
|
+
reload
|
43
|
+
scope
|
44
|
+
scope_for_slug_generator
|
45
|
+
update_counters
|
46
|
+
update_positions
|
47
|
+
validate_each
|
48
|
+
)
|
49
|
+
|
50
|
+
# Calling unscoped is blocked to prevent data leakage. You can override the behaviour of unscoped
|
51
|
+
# here. If the caller is in this list, it wont get the unscoped scope, but a client scoped relation.
|
52
|
+
#
|
53
|
+
# default: config.force_client_scope_for_unscoped_callers = ['aggregate_column']
|
54
|
+
#
|
55
|
+
config.force_client_scope_for_unscoped_callers = ['aggregate_column']
|
16
56
|
end
|
data/lib/multi_client/version.rb
CHANGED
data/lib/multi_client.rb
CHANGED