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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb959e3e7261ece07ebd98c3c50024e9aeeebf00
4
- data.tar.gz: 12f046e79761540fa66f8ac99f6cd23c78e08b56
3
+ metadata.gz: 870e44c8e39778573342067fc5f7e1a0b3259418
4
+ data.tar.gz: 8f9bcbd1516b65c100eed8497e92ba5fac0eb8bf
5
5
  SHA512:
6
- metadata.gz: ffd03a80b02d73e9354aea0581d0192685217591380e5d1f602f9e5aae486f2fb45c20f07d59542f04354c9c51d637d5de5a39db273a7f4afcf905c60ce08a27
7
- data.tar.gz: 575e6f74d0533afdfe35dababf3b6a998bd5506909f3572f1367458897e34d12081c0089280b5aee5ac5216666563c1dbb68d8dbd1f0e0997f3e80f00afa1ea4
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('../spec/dummy/Rakefile', __FILE__)
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(root_url(subdomain: 'www')) && return unless current_client = client_class.enabled.find_by_subdomain(request.subdomains.first)
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
@@ -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,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, -> { where(MultiClient::Configuration.foreign_key.to_sym => MultiClient::Configuration.model_name.constantize.current_id) }
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
- 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"
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 '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,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
@@ -16,10 +16,6 @@ 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
-
23
19
  def self.namespaced_model_name
24
20
  "MultiClient::#{model_name}"
25
21
  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 = '0.1.1'.freeze
2
+ VERSION = "1.0.0"
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
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-10 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails