multi_client 0.1.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +5 -1
- 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 +17 -10
- data/lib/generators/multi_client/install/install_generator.rb +3 -3
- data/lib/generators/multi_client/install/templates/multi_client.rb +0 -40
- data/lib/multi_client/configuration.rb +0 -4
- 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 +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 870e44c8e39778573342067fc5f7e1a0b3259418
|
4
|
+
data.tar.gz: 8f9bcbd1516b65c100eed8497e92ba5fac0eb8bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64f12b209c88af029f201321dbc3165a83ea226ae0d5d132e6f4df7588872eca35a61dc4450c05c4428a056bd9b20d0cdaa61dfcff800a1977426835edcf4dd8
|
7
|
+
data.tar.gz: 0154ef2e3637469500cf8119578e5a0dba4ecce8f0e4df3adb7bf1da4af4bc06714ab31a7b703778ffa5a780d4c79bfc036773a5be98241af29cd570168ee452
|
data/Rakefile
CHANGED
@@ -14,9 +14,13 @@ 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
|
+
|
20
21
|
load 'rails/tasks/statistics.rake'
|
21
22
|
|
23
|
+
|
24
|
+
|
22
25
|
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') and 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,31 +5,38 @@ 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
|
-
const_set 'Unscoped', klass
|
13
|
+
self.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, lambda { 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 name.demodulize.underscore.pluralize.to_sym, class_name: "::#{name}", foreign_key: MultiClient::Configuration.foreign_key.to_sym
|
22
|
+
::MultiClient::Client.has_many self.name.demodulize.underscore.pluralize.to_sym, class_name: "::#{self.name}", foreign_key: MultiClient::Configuration.foreign_key.to_sym
|
23
|
+
|
23
24
|
end
|
24
25
|
|
25
26
|
class_methods do
|
26
27
|
def unscoped
|
27
|
-
return super if name.demodulize == 'Unscoped'
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
return super if self.name.demodulize == 'Unscoped'
|
29
|
+
return where(MultiClient::Configuration.foreign_key.to_sym => MultiClient::Configuration.model_name.constantize.current_id) if caller_locations(1,1)[0].label == 'aggregate_column'
|
30
|
+
|
31
|
+
# Experimental
|
32
|
+
# return where(MultiClient::Configuration.foreign_key.to_sym => MultiClient::Configuration.model_name.constantize.current_id) if ['aggregate_column', 'bottom_item', 'scope_for_slug_generator'].include?(caller_locations(1,1)[0].label)
|
33
|
+
|
34
|
+
if ['_create_record', 'scope', 'validate_each', 'eval_scope', '_update_record', 'aggregate_column', 'bottom_item', 'scope_for_slug_generator'].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
|
32
39
|
end
|
33
40
|
end
|
34
41
|
end
|
35
|
-
end
|
42
|
+
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,44 +13,4 @@ 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']
|
56
16
|
end
|
data/lib/multi_client/version.rb
CHANGED
data/lib/multi_client.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|