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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0aad312dfaac45befa64752dc639ef151cea896
4
- data.tar.gz: ef6961bfb900171c169e0c6323216b43b3796e36
3
+ metadata.gz: 3b44ece79b0218ae58e6e4c2a7331ffe257f7654
4
+ data.tar.gz: 233c3b8ebabfba00eccf49881cf36a5f991373e0
5
5
  SHA512:
6
- metadata.gz: 9730d9d7176c30a7b1ec1f8009db1012e2c75a07493b9191df86d4f09898b5b36b7894f90af9e170813d24b41299275a07aa600709364699d4e84fd4f11bed6d
7
- data.tar.gz: 1d8c161a1721415b08e38f968b7d32893d1668fd2659f233a4554b5a611567715c235b9044f2c1a009c60cf5be95e8ecefec446fbd0ef44a06f46e985f8f11e0
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("../spec/dummy/Rakefile", __FILE__)
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 root_url(subdomain: 'www') and return unless current_client = client_class.enabled.find_by_subdomain(request.subdomains.first)
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
@@ -3,4 +3,4 @@ module MultiClientHelper
3
3
  clients = MultiClient::Client.all
4
4
  render 'multi_client/client_navigation', clients: clients
5
5
  end
6
- end
6
+ 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
- self.const_set 'Unscoped', klass
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, lambda { where(MultiClient::Configuration.foreign_key.to_sym => MultiClient::Configuration.model_name.constantize.current_id) }
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 self.name.demodulize.underscore.pluralize.to_sym, class_name: "::#{self.name}", foreign_key: MultiClient::Configuration.foreign_key.to_sym
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 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', '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 "Generates the initializer"
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 "multi_client.rb", "config/initializers/multi_client.rb"
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
@@ -16,6 +16,10 @@ module MultiClient
16
16
  'client'
17
17
  end
18
18
 
19
+ mattr_accessor(:allowed_unscoped_callers) { [] }
20
+
21
+ mattr_accessor(:force_client_scope_for_unscoped_callers) { [] }
22
+
19
23
  def self.namespaced_model_name
20
24
  "MultiClient::#{model_name}"
21
25
  end
@@ -9,4 +9,4 @@ module MultiClient
9
9
  end
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -9,4 +9,4 @@ module MultiClient
9
9
  end
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module MultiClient
2
- VERSION = "1.0.1"
2
+ VERSION = '1.1.0'.freeze
3
3
  end
data/lib/multi_client.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "multi_client/engine"
2
- require "multi_client/configuration"
1
+ require 'multi_client/engine'
2
+ require 'multi_client/configuration'
3
3
 
4
4
  module MultiClient
5
5
  extend Configuration
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel