company_scope 0.7 → 0.9

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: 79de46e2b5ca59bec724094c5858229a1e336798
4
- data.tar.gz: b0f45349ac3462c5d1ebfa495084232e466be606
3
+ metadata.gz: afc9477877707a43dea45f4700e9bd2901a39709
4
+ data.tar.gz: d0afae4228b12188111476a736228f03ae26654e
5
5
  SHA512:
6
- metadata.gz: 61fe3ea5c9f4cb1535cace527c0a9c2cca55fc831ab887f548231b12572ba7f882dffdf9bccfe6191ee7576ef0cabd96798e7f2411bda5ea2690fd4dc72be569
7
- data.tar.gz: 4e976917b07f0561e269043b241fc8a16a96bdb5b57df7fa77b6557c0b9d05d1e57cd33050e334c4cdf98f8f9110983bae579ecff03eb2bafc089d61cded1922
6
+ metadata.gz: 2437b536e02709af7019f4859aaf8aaa253dcf8338ef7aebf906d4148dfaa523d57c84b59d5c3f14d6d777488bc73100d45970697f685308d69fb30d9e688235
7
+ data.tar.gz: 53f8a2ff5a11fb53f3aa64626517730bbb96b2b858601d3f506963b2868b05346b2bd8ed46674da7569e0130082e82ba330629e8566314ef1986a57c51cdf1b7
data/README.md CHANGED
@@ -47,7 +47,8 @@ There are three main steps in adding multi-tenancy/company to your app with comp
47
47
  The gem has an install generator that adds a configuration setting to config/application.rb
48
48
  and also creates two models with associated migrations. The models are company and user.
49
49
  The company has the acts_as_guardian company_scope module inserted, and the user has
50
- the acts_as_company company_scope module inserted.
50
+ the acts_as_company company_scope module inserted. It finally also adds the filtering configuration
51
+ into the Application Controller. (See further below for an explanation)
51
52
 
52
53
  ```
53
54
  rails generate company_scope:install
@@ -72,7 +73,7 @@ to be enabled once the configuration is completed.
72
73
  ```
73
74
 
74
75
  This is deliberately set to false at the outset. Set this to true AFTER all the configuration of
75
- the gem is completed.
76
+ the gem is completed, i.e. the company model exists and you have run the migration.
76
77
 
77
78
  ### Process of determining the company/account
78
79
 
@@ -182,9 +183,9 @@ class ApplicationController < ActionController::Base
182
183
  end
183
184
  ```
184
185
 
185
- The above three methods need to be added to the Rails Controllers. For small systems they
186
- will typically be added to the ApplicationController. However they can be split into
187
- child-controllers dependent on the layout of the application.
186
+ The above three methods have been added to the Rails Application Controller, by the install
187
+ generator. For small systems they will typically remain there unless you have pages that do
188
+ not require to be scoped by the company in which case they should be added to a child.
188
189
 
189
190
  All Controllers that inherit from the Controller that implements the acts_as_company_filter
190
191
  will have an around filter applied that set the Company class attribute required for the scoping
@@ -238,15 +239,11 @@ class User < ActiveRecord::Base
238
239
  end
239
240
  ```
240
241
 
241
- ### The Gem is currently being used in Rails 4 and Rails-API apps and is tested against Postgres
242
+ #### The Gem is currently being used in Rails 4 and Rails-API apps and is tested against Postgres
242
243
 
243
- ### It should work with other databases such as MySQL without any issues
244
+ #### It should work with other databases such as MySQL without any issues
244
245
 
245
-
246
- ## Development
247
-
248
-
249
- ## Contributing
246
+ ### Contributing
250
247
 
251
248
  1. Fork it ( https://github.com/[my-github-username]/company_scope/fork )
252
249
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -32,16 +32,20 @@ module CompanyScope
32
32
  module FilterClassMethods
33
33
  # - the default is set by the Rails application configuration!
34
34
  def set_scoping_class(scope_model = :company)
35
- self.class_eval do
36
- cattr_accessor :scope_class
35
+ if CompanyScope.config.enabled
36
+ self.class_eval do
37
+ cattr_accessor :scope_class
38
+ end
39
+ self.scope_class = scope_model.to_s.camelcase.constantize
37
40
  end
38
- self.scope_class = scope_model.to_s.camelcase.constantize
39
41
  end
40
42
  #
41
43
  def company_setup
42
- helper_method :current_company
43
- #set_scoping_class Rails.application.config.company_scope[:company_model]
44
- set_scoping_class CompanyScope.config.company_model
44
+ if CompanyScope.config.enabled
45
+ helper_method :current_company
46
+ #set_scoping_class Rails.application.config.company_scope[:company_model]
47
+ set_scoping_class CompanyScope.config.company_model
48
+ end
45
49
  end
46
50
  #
47
51
  def acts_as_company_filter
@@ -1,3 +1,3 @@
1
1
  module CompanyScope
2
- VERSION = "0.7"
2
+ VERSION = "0.9"
3
3
  end
@@ -17,7 +17,7 @@ module CompanyScope
17
17
  config_file = 'config/application.rb'
18
18
  line = "class Application < Rails::Application"
19
19
  insert_config = <<-RUBY
20
- config.company_scope[:configured] = false
20
+ config.company_scope[:configured] = false
21
21
  RUBY
22
22
  if File.readlines(config_file).grep(/config.company_scope\[:configured\] = false/).size == 0
23
23
  gsub_file config_file, /(#{Regexp.escape(line)})/mi do |match|
@@ -37,7 +37,7 @@ module CompanyScope
37
37
  unless options.no_migrations?
38
38
  # - generate a user model and migration with a company_id reference a few basic user auth fields
39
39
  migrate_user_model = <<-RUBY
40
- company_id:id
40
+ company_id:references
41
41
  password_hash:string
42
42
  password_salt:string
43
43
  first_name:string{50}
@@ -57,7 +57,7 @@ module CompanyScope
57
57
  insert_guardian_scope = "acts_as_guardian"
58
58
  if File.readlines(config_file).grep(/acts_as_guardian/).size == 0
59
59
  gsub_file config_file, /(#{Regexp.escape(line)})/mi do |match|
60
- match << "\n#{insert_guardian_scope}"
60
+ match << "\n\t#{insert_guardian_scope}"
61
61
  end
62
62
  end
63
63
  end
@@ -71,10 +71,26 @@ module CompanyScope
71
71
  insert_tenant_scope = "acts_as_company"
72
72
  if File.readlines(config_file).grep(/acts_as_company/).size == 0
73
73
  gsub_file config_file, /(#{Regexp.escape(line)})/mi do |match|
74
- match << "\n#{insert_tenant_scope}"
74
+ match << "\n\t#{insert_tenant_scope}"
75
75
  end
76
76
  end
77
77
  end
78
78
  end
79
+
80
+ def add_scoping_to_application_controller
81
+ controller_file = 'app/controllers/application_controller.rb'
82
+ line = 'class ApplicationController < ActionController::Base'
83
+ insert_company_scope = <<-RUBY
84
+ company_setup\n
85
+ set_scoping_class :company\n
86
+ acts_as_company_filter\n
87
+ RUBY
88
+ if File.readlines(controller_file).grep(/company_setup/).size == 0
89
+ gsub_file controller_file, /(#{Regexp.escape(line)})/mi do |match|
90
+ match << "\n#{insert_company_scope}"
91
+ end
92
+ end
93
+ end
94
+
79
95
  end
80
96
  end
data/log/test.log CHANGED
@@ -510,3 +510,51 @@ Processing by DummyApplicationController#index as HTML
510
510
  Completed 200 OK in 0ms (Views: 0.2ms)
511
511
  Processing by DummyApplicationController#index as HTML
512
512
  Completed 500 Internal Server Error in 0ms
513
+ Processing by DummyApplicationController#index as HTML
514
+ Completed 500 Internal Server Error in 3ms
515
+ Processing by DummyApplicationController#index as HTML
516
+ Completed 500 Internal Server Error in 3ms
517
+ Processing by DummyApplicationController#index as HTML
518
+ Completed 500 Internal Server Error in 2ms
519
+ Processing by DummyApplicationController#index as HTML
520
+ Completed 500 Internal Server Error in 2ms
521
+ Processing by DummyApplicationController#index as HTML
522
+ Completed 200 OK in 1ms (Views: 0.4ms)
523
+ Processing by DummyApplicationController#index as HTML
524
+ Completed 200 OK in 0ms (Views: 0.1ms)
525
+ Processing by DummyApplicationController#index as HTML
526
+ Completed 200 OK in 0ms (Views: 0.2ms)
527
+ Processing by DummyApplicationController#index as HTML
528
+ Completed 500 Internal Server Error in 0ms
529
+ Processing by DummyApplicationController#index as HTML
530
+ Completed 500 Internal Server Error in 2ms
531
+ Processing by DummyApplicationController#index as HTML
532
+ Completed 500 Internal Server Error in 3ms
533
+ Processing by DummyApplicationController#index as HTML
534
+ Completed 500 Internal Server Error in 3ms
535
+ Processing by DummyApplicationController#index as HTML
536
+ Completed 500 Internal Server Error in 3ms
537
+ Processing by DummyApplicationController#index as HTML
538
+ Completed 200 OK in 0ms (Views: 0.1ms)
539
+ Processing by DummyApplicationController#index as HTML
540
+ Completed 200 OK in 0ms (Views: 0.1ms)
541
+ Processing by DummyApplicationController#index as HTML
542
+ Completed 200 OK in 0ms (Views: 0.1ms)
543
+ Processing by DummyApplicationController#index as HTML
544
+ Completed 500 Internal Server Error in 0ms
545
+ Processing by DummyApplicationController#index as HTML
546
+ Completed 200 OK in 0ms (Views: 0.2ms)
547
+ Processing by DummyApplicationController#index as HTML
548
+ Completed 200 OK in 0ms (Views: 0.1ms)
549
+ Processing by DummyApplicationController#index as HTML
550
+ Completed 200 OK in 0ms (Views: 0.1ms)
551
+ Processing by DummyApplicationController#index as HTML
552
+ Completed 500 Internal Server Error in 0ms
553
+ Processing by DummyApplicationController#index as HTML
554
+ Completed 200 OK in 0ms (Views: 0.2ms)
555
+ Processing by DummyApplicationController#index as HTML
556
+ Completed 200 OK in 0ms (Views: 0.2ms)
557
+ Processing by DummyApplicationController#index as HTML
558
+ Completed 200 OK in 0ms (Views: 0.2ms)
559
+ Processing by DummyApplicationController#index as HTML
560
+ Completed 500 Internal Server Error in 0ms
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: company_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Forkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-03 00:00:00.000000000 Z
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler