g5_authenticatable 0.9.1.pre.2 → 1.0.0.pre.1

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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +23 -9
  5. data/Appraisals +17 -0
  6. data/CHANGELOG.md +14 -0
  7. data/Gemfile +11 -14
  8. data/README.md +40 -13
  9. data/app/controllers/concerns/g5_authenticatable/authorization.rb +4 -1
  10. data/app/controllers/g5_authenticatable/application_controller.rb +3 -0
  11. data/app/controllers/g5_authenticatable/error_controller.rb +3 -2
  12. data/app/controllers/g5_authenticatable/failure_app.rb +35 -0
  13. data/app/controllers/g5_authenticatable/sessions_controller.rb +7 -3
  14. data/app/helpers/g5_authenticatable/application_helper.rb +3 -0
  15. data/app/models/g5_authenticatable/role.rb +5 -2
  16. data/app/models/g5_authenticatable/user.rb +12 -5
  17. data/app/policies/g5_authenticatable/base_policy.rb +75 -58
  18. data/app/policies/g5_updatable/client_policy.rb +5 -5
  19. data/app/policies/g5_updatable/location_policy.rb +6 -5
  20. data/app/policies/g5_updatable/selectable_client_policy.rb +6 -7
  21. data/app/services/g5_authenticatable/impersonate_sessionable.rb +12 -7
  22. data/config/initializers/devise.rb +4 -0
  23. data/config/initializers/impersonate_strategy.rb +5 -2
  24. data/config/initializers/rolify.rb +2 -0
  25. data/config/routes.rb +3 -1
  26. data/g5_authenticatable.gemspec +11 -7
  27. data/gemfiles/rails_4.1.gemfile +28 -0
  28. data/gemfiles/rails_4.2.gemfile +28 -0
  29. data/gemfiles/rails_5.0.gemfile +28 -0
  30. data/gemfiles/rails_5.1.gemfile +28 -0
  31. data/lib/g5_authenticatable.rb +3 -1
  32. data/lib/g5_authenticatable/engine.rb +5 -2
  33. data/lib/g5_authenticatable/rspec.rb +2 -0
  34. data/lib/g5_authenticatable/test/controller_helpers.rb +14 -9
  35. data/lib/g5_authenticatable/test/env_helpers.rb +3 -0
  36. data/lib/g5_authenticatable/test/factories/client_users.rb +45 -0
  37. data/lib/g5_authenticatable/test/factories/global_users.rb +43 -0
  38. data/lib/g5_authenticatable/test/factories/location_users.rb +45 -0
  39. data/lib/g5_authenticatable/test/factories/roles.rb +63 -0
  40. data/lib/g5_authenticatable/test/factory.rb +7 -59
  41. data/lib/g5_authenticatable/test/feature_helpers.rb +31 -17
  42. data/lib/g5_authenticatable/test/request_helpers.rb +5 -1
  43. data/lib/g5_authenticatable/test/token_validation_helpers.rb +15 -10
  44. data/lib/g5_authenticatable/version.rb +3 -1
  45. data/lib/generators/g5_authenticatable/install/install_generator.rb +49 -37
  46. data/lib/generators/g5_authenticatable/install/templates/application_policy.rb +2 -0
  47. data/lib/generators/g5_authenticatable/install/templates/initializer.rb +2 -0
  48. data/lib/generators/g5_authenticatable/install/templates/migrate/add_g5_authenticatable_users_contact_info.rb +3 -1
  49. data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_roles.rb +3 -1
  50. data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_users.rb +3 -1
  51. data/lib/tasks/g5_authenticatable/purge_users.rake +2 -0
  52. data/spec/config/application_spec.rb +7 -4
  53. data/spec/controllers/application_controller_spec.rb +10 -5
  54. data/spec/controllers/concerns/g5_authenticatable/{authorization.rb → authorization_spec.rb} +11 -6
  55. data/spec/dummy/app/controllers/home_controller.rb +5 -5
  56. data/spec/dummy/app/controllers/rails_api/secure_resources_controller.rb +6 -4
  57. data/spec/dummy/app/models/post.rb +1 -1
  58. data/spec/dummy/config/environments/test.rb +25 -4
  59. data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
  60. data/spec/dummy/db/migrate/20140206070137_create_g5_authenticatable_users.rb +3 -1
  61. data/spec/dummy/db/migrate/20150428182339_add_g5_authenticatable_users_contact_info.rb +3 -1
  62. data/spec/dummy/db/migrate/20150429212919_create_g5_authenticatable_roles.rb +2 -1
  63. data/spec/dummy/db/migrate/20150509061150_create_posts.rb +3 -1
  64. data/spec/dummy/db/migrate/20150603224032_create_g5_updatable_clients_and_locations.g5_updatable.rb +3 -1
  65. data/spec/dummy/db/migrate/20150603224033_create_integration_setting.g5_updatable.rb +3 -1
  66. data/spec/dummy/db/migrate/20150603224034_remove_integration_setting.g5_updatable.rb +3 -1
  67. data/spec/dummy/db/migrate/20150603224035_add_name_to_clients_and_locations.g5_updatable.rb +3 -1
  68. data/spec/dummy/db/migrate/20150603224036_update_names.g5_updatable.rb +3 -1
  69. data/spec/dummy/db/migrate/20170613201430_add_latitude_and_longitude_to_location.g5_updatable.rb +7 -0
  70. data/spec/dummy/db/migrate/20170613201431_copy_lat_long_props_to_lat_long_columns.g5_updatable.rb +20 -0
  71. data/spec/dummy/db/migrate/20170613201432_add_latitude_longitude_indexes_to_location.g5_updatable.rb +7 -0
  72. data/spec/dummy/db/migrate/{20161122070749_add_amenities.rb → 20170613201433_add_amenities.g5_updatable.rb} +2 -1
  73. data/spec/dummy/db/migrate/{20161209070749_add_client_urn_to_locations.rb → 20170613201434_add_client_urn_to_locations.g5_updatable.rb} +2 -1
  74. data/spec/dummy/db/migrate/20170613201435_add_points_of_interest.g5_updatable.rb +21 -0
  75. data/spec/dummy/db/migrate/20170613201436_add_unique_urn_indexes.g5_updatable.rb +11 -0
  76. data/spec/dummy/db/schema.rb +73 -61
  77. data/spec/factories/post.rb +2 -0
  78. data/spec/features/auth_error_path_spec.rb +3 -3
  79. data/spec/features/default_role_authorization_spec.rb +8 -4
  80. data/spec/features/sign_in_spec.rb +23 -13
  81. data/spec/features/token_validation_spec.rb +4 -2
  82. data/spec/g5_authenticatable/version_spec.rb +3 -1
  83. data/spec/lib/generators/g5_authenticatable/install_generator_spec.rb +73 -28
  84. data/spec/models/g5_authenticatable/role_spec.rb +8 -4
  85. data/spec/models/g5_authenticatable/user_spec.rb +119 -84
  86. data/spec/models/post_spec.rb +4 -2
  87. data/spec/policies/application_policy_spec.rb +80 -47
  88. data/spec/policies/client_policy_spec.rb +8 -5
  89. data/spec/policies/location_policy_spec.rb +21 -8
  90. data/spec/policies/selectable_client_policy_spec.rb +26 -15
  91. data/spec/rails_helper.rb +41 -0
  92. data/spec/requests/default_role_authorization_spec.rb +18 -14
  93. data/spec/requests/grape_api_spec.rb +7 -5
  94. data/spec/requests/rails_api_spec.rb +11 -9
  95. data/spec/requests/sign_out_spec.rb +10 -6
  96. data/spec/requests/token_validation_spec.rb +9 -5
  97. data/spec/routing/auth_error_routing_spec.rb +7 -6
  98. data/spec/routing/sign_out_routing_spec.rb +7 -5
  99. data/spec/services/g5_authenticatable/impersonate_sessionable_spec.rb +41 -18
  100. data/spec/spec_helper.rb +78 -45
  101. data/spec/support/devise.rb +3 -1
  102. data/spec/support/safe_request_helpers.rb +36 -0
  103. data/spec/support/shared_contexts/rake.rb +10 -4
  104. data/spec/support/shared_examples/super_admin_authorizer.rb +3 -1
  105. data/spec/tasks/purge_users_spec.rb +3 -1
  106. metadata +75 -39
  107. data/spec/controllers/.gitkeep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4ea16474bb9af27d71cc19d0860500e289b1183
4
- data.tar.gz: 888f2f21d3516ef5832df070d3da0c193c9bb8f8
3
+ metadata.gz: a76fa37dacb1777aa7e76189bf050ffdae4bab7a
4
+ data.tar.gz: e323ad93ec0f5f40500e999c5303828b4f7070c0
5
5
  SHA512:
6
- metadata.gz: a1390a2a326b668987b0b1dd78a8a131b24f4a092f746776605dbfde284aabe7df899d9507d76ec170980510f293453042864183576054edc5e770e5270e05c9
7
- data.tar.gz: fc5a84542730f57401d3080e6fb8682a7b5f6cac0c00bdb31281a4424ab57b37420de941cfed4d7931749d7b3e34790243934e90f5f847c158ff046356fcfd56
6
+ metadata.gz: 83e1c15d70f574298141c0515335fe6bb7d3e9dd31c356b8dec6aba013209a3b6e1423b23ed366307c84bd53e25a35eb5eb7ddd0b2a7565b8e908b65861bb5f7
7
+ data.tar.gz: c1117229b44ca11584355e70c4262d023f708e1b604cd8f6de1fed0c064aff583668184dd064dad172c5aff717d1e671934b4c3d47f29f9480f6f2d1f69d4530
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  .config
6
6
  .yardoc
7
7
  Gemfile.lock
8
+ gemfiles/*.gemfile.lock
8
9
  InstalledFiles
9
10
  _yardoc
10
11
  coverage
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.3.4
data/.travis.yml CHANGED
@@ -1,18 +1,32 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1
5
- - 2.2
3
+ - 2.2.7
4
+ - 2.3.4
5
+ - 2.4.1
6
+ gemfile:
7
+ - gemfiles/rails_4.1.gemfile
8
+ - gemfiles/rails_4.2.gemfile
9
+ - gemfiles/rails_5.0.gemfile
10
+ - gemfiles/rails_5.1.gemfile
11
+ matrix:
12
+ exclude:
13
+ - rvm: 2.4.1
14
+ gemfile: gemfiles/rails_4.1.gemfile
15
+ allow_failures:
16
+ - rvm: 2.4.1
17
+ dist: trusty
18
+ sudo: false
19
+ cache:
20
+ bundler: true
6
21
  before_install:
7
22
  - gem install bundler
8
- script:
9
- - RAILS_ENV=test bundle exec rake app:db:setup
10
- - bundle exec rspec spec
11
23
  before_script:
12
24
  - cp spec/dummy/config/database.yml.ci spec/dummy/config/database.yml
13
- - psql -c 'create database g5_authenticatable_test;' -U postgres
25
+ - RAILS_ENV=test bundle exec rake app:db:create app:db:migrate
26
+ script:
27
+ - bundle exec rspec spec
28
+ after_script:
29
+ - RAILS_ENV=test bundle exec rake app:db:drop
14
30
  env:
15
31
  global:
16
32
  - DEVISE_SECRET_KEY=foo
17
- addons:
18
- postgresql: "9.2"
data/Appraisals ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'rails-4.1' do
4
+ gem 'rails', '~> 4.1.16'
5
+ end
6
+
7
+ appraise 'rails-4.2' do
8
+ gem 'rails', '~> 4.2.8'
9
+ end
10
+
11
+ appraise 'rails-5.0' do
12
+ gem 'rails', '~> 5.0.3'
13
+ end
14
+
15
+ appraise 'rails-5.1' do
16
+ gem 'rails', '~> 5.1.1'
17
+ end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## v1.0.0.pre.1 (TBD)
2
+
3
+ * **Backwards incompatible changes**
4
+ * Dropped support for rails < 4.1
5
+ * The `:g5_authenticatable_user` factory no longer assigns a default role to
6
+ the user. If you specifically need a user with a global viewer role, use the
7
+ new `:g5_authenticatable_viewer` factory instead.
8
+ * Bug fixes
9
+ * Fixed problem with route generation in devise failure app
10
+ * Deprecations
11
+ * The `has_global_role?` method on `G5Authenticatable::BasePolicy` and
12
+ `G5Authenticatable::BasePolicy::BaseScope` has been deprecated in favor of
13
+ `global_role?`
14
+
1
15
  ## v0.9.0 (2016-11-03)
2
16
 
3
17
  * Refactor custom mapping logic into devise_g5_authenticatable callbacks
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Declare your gem's dependencies in g5_authenticatable.gemspec.
@@ -6,35 +8,30 @@ source 'https://rubygems.org'
6
8
  gemspec
7
9
 
8
10
  # Gems used by the dummy application
9
- gem 'rails', '4.2.0'
11
+ gem 'active_model_serializers', '<= 0.10.0' # For compatibility with ruby 2.0.0
12
+ gem 'grape'
10
13
  gem 'jquery-rails'
11
14
  gem 'pg'
12
- gem 'grape'
13
- gem 'active_model_serializers', '<= 0.10.0' # For compatibility with ruby 2.0.0
15
+ gem 'rails', '~> 5.1.1'
14
16
 
15
17
  group :test, :development do
16
- gem 'rspec-rails', '~> 3.1'
17
- gem 'pry-byebug'
18
+ gem 'appraisal'
18
19
  gem 'dotenv-rails'
20
+ gem 'pry-byebug'
21
+ gem 'rspec-rails', '~> 3.6'
19
22
  gem 'web-console', '~> 2.0'
20
23
  end
21
24
 
22
25
  group :test do
23
26
  gem 'capybara'
24
- gem 'factory_girl_rails', '~> 4.3', require: false
25
- gem 'simplecov', require: false
26
- gem 'codeclimate-test-reporter', require: false
27
- gem 'webmock'
28
- gem 'shoulda-matchers', '~> 2.6'
27
+ gem 'codeclimate-test-reporter'
29
28
  gem 'generator_spec'
30
- gem 'rspec-http', require: 'rspec/http'
31
29
  gem 'rspec-activemodel-mocks'
30
+ gem 'shoulda-matchers', '~> 3.1'
31
+ gem 'simplecov', require: false
32
32
  end
33
33
 
34
34
  # Declare any dependencies that are still in development here instead of in
35
35
  # your gemspec. These might include edge Rails or gems from your path or
36
36
  # Git. Remember to move these dependencies to your gemspec before releasing
37
37
  # your gem to rubygems.org.
38
-
39
- # To use debugger
40
- # gem 'debugger'
data/README.md CHANGED
@@ -18,11 +18,11 @@ library in isolation.
18
18
 
19
19
  ## Current Version
20
20
 
21
- 0.9.0
21
+ 1.0.0.pre.1
22
22
 
23
23
  ## Requirements
24
24
 
25
- * [rails](https://github.com/rails/rails) >= 3.2
25
+ * [rails](https://github.com/rails/rails) >= 4.1
26
26
 
27
27
  ## Installation
28
28
 
@@ -68,7 +68,7 @@ Devise requires you to define a root route in your application's
68
68
  `config/routes.rb`. For example:
69
69
 
70
70
  ```ruby
71
- root :to => 'home#index'
71
+ root to: 'home#index'
72
72
  ```
73
73
 
74
74
  ### Registering your OAuth application
@@ -133,10 +133,10 @@ G5Authenticatable.strict_token_validation = true
133
133
  ### Controller filters and helpers
134
134
 
135
135
  G5 Authenticatable installs all of the usual devise controllers and helpers.
136
- To set up a controller that requires authentication, use this before_filter:
136
+ To set up a controller that requires authentication, use this before_action:
137
137
 
138
138
  ```ruby
139
- before_filter :authenticate_user!
139
+ before_action :authenticate_user!
140
140
  ```
141
141
 
142
142
  To verify if a user is signed in, use the following helper:
@@ -157,6 +157,32 @@ To access scoped session storage:
157
157
  user_session
158
158
  ```
159
159
 
160
+ ### Securing an engine (e.g. sidekiq or resque web UI)
161
+
162
+ To use G5 Auth to secure another Rails engine mounted within your application,
163
+ modify your `config/routes.rb` file like so:
164
+
165
+ ```ruby
166
+ # To allow any authenticated user to access the mounted engine
167
+ authenticate :user do
168
+ mount Sidekiq::Web => '/sidekiq'
169
+ end
170
+
171
+ # To restrict access to a particular user role
172
+ authenticate :user, ->(user) { user.has_role?(:super_admin) } do
173
+ mount Sidekiq::Web => '/sidekiq'
174
+ end
175
+ ```
176
+
177
+ Note that some additional configuration may be necessary, depending on the
178
+ engine which you are securing. For instance, sidekiq web tries to manage its
179
+ own independent session store, which must be disabled by adding this line to
180
+ your `config/initializers/sidekiq.rb` file:
181
+
182
+ ```ruby
183
+ Sidekiq::Web.set(:sessions, false)
184
+ ```
185
+
160
186
  ### Route helpers
161
187
 
162
188
  There are several generic helper methods for session and omniauth
@@ -233,7 +259,7 @@ method:
233
259
  class MyResourcesController < ApplicationController
234
260
  respond_to :json
235
261
 
236
- before_filter :authenticate_api_user!
262
+ before_action :authenticate_api_user!
237
263
 
238
264
  def get
239
265
  @resource = MyResource.find(params[:id])
@@ -457,7 +483,8 @@ your javascript driver instead.
457
483
  #### Installation ####
458
484
 
459
485
  To automatically mix in helpers to your feature and request specs, include the
460
- following line in your `spec/spec_helper.rb`:
486
+ following line in your `spec/rails_helper.rb`, after your app and rspec-rails
487
+ have been loaded:
461
488
 
462
489
  ```ruby
463
490
  require 'g5_authenticatable/rspec'
@@ -685,14 +712,14 @@ when reconfiguring a client application to use a different auth endpoint
685
712
 
686
713
  ### Protecting a particular Rails controller action
687
714
 
688
- You can use all of the usual options to `before_filter` for more fine-grained
715
+ You can use all of the usual options to `before_action` for more fine-grained
689
716
  control over where authentication is required. For example, to require
690
717
  authentication only to edit a resource while leaving all other actions
691
718
  unsecured:
692
719
 
693
720
  ```ruby
694
721
  class MyResourcesController < ApplicationController
695
- before_filter :authenticate_user!, only: [:edit, :update]
722
+ before_action :authenticate_user!, only: [:edit, :update]
696
723
 
697
724
  # ...
698
725
  end
@@ -747,8 +774,8 @@ the request format:
747
774
 
748
775
  ```ruby
749
776
  class MyMixedUpController < ApplicationController
750
- before_filter :authenticate_api_user!, unless: :is_navigational_format?
751
- before_filter :authenticate_user!, if: :is_navigational_format?
777
+ before_action :authenticate_api_user!, unless: :is_navigational_format?
778
+ before_action :authenticate_user!, if: :is_navigational_format?
752
779
 
753
780
  respond_to :html, :json
754
781
 
@@ -768,8 +795,8 @@ a signup form, you can try something like this:
768
795
 
769
796
  ```ruby
770
797
  class MyMixedUpController < ApplicationController
771
- before_filter :authenticate_api_user!, if: :is_api_request?
772
- before_filter :authenticate_user!, unless: :is_api_request?
798
+ before_action :authenticate_api_user!, if: :is_api_request?
799
+ before_action :authenticate_user!, unless: :is_api_request?
773
800
 
774
801
  respond_to :html
775
802
 
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
4
+ # Authorization helpers and error handling for controllers
2
5
  module Authorization
3
6
  extend ActiveSupport::Concern
4
7
 
@@ -10,7 +13,7 @@ module G5Authenticatable
10
13
  def user_not_authorized
11
14
  respond_to do |format|
12
15
  format.json do
13
- render status: :forbidden, json: {error: 'Access forbidden'}
16
+ render status: :forbidden, json: { error: 'Access forbidden' }
14
17
  end
15
18
  format.html do
16
19
  render status: :forbidden, file: "#{Rails.root}/public/403"
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
4
+ # Base class for all controllers in the G5Authenticatable engine
2
5
  class ApplicationController < ActionController::Base
3
6
  end
4
7
  end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
4
+ # For handling errors returned by the auth server
2
5
  class ErrorController < G5Authenticatable::ApplicationController
3
-
4
6
  def auth_error
5
7
  flash[:error] = 'There was a problem with the Auth Server!'
6
8
  end
7
-
8
9
  end
9
10
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module G5Authenticatable
4
+ # Custom failure app that generates urls correctly within an isolated engine
5
+ # https://github.com/plataformatec/devise/issues/4127
6
+ class FailureApp < Devise::FailureApp
7
+ def scope_url
8
+ opts = {}
9
+ route = :"new_#{scope}_session_url"
10
+ opts[:format] = request_format unless skip_format?
11
+
12
+ config = Rails.application.config
13
+
14
+ if config.try(:relative_url_root)
15
+ opts[:script_name] = config.relative_url_root
16
+ end
17
+
18
+ failure_url(route, opts)
19
+ end
20
+
21
+ private
22
+
23
+ def failure_url(route, opts)
24
+ context = send(Devise.available_router_name)
25
+
26
+ if context.respond_to?(route)
27
+ context.send(route, opts)
28
+ elsif respond_to?(:root_url)
29
+ root_url(opts)
30
+ else
31
+ '/'
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,12 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
4
+ # Custom sessions controller to handle auth server interaction
2
5
  class SessionsController < DeviseG5Authenticatable::SessionsController
3
6
  protected
7
+
4
8
  def register_resource
5
9
  create_resource
6
10
  sign_in_resource
7
11
  end
8
12
 
9
- def signed_in_root_path(resource_or_scope)
13
+ def signed_in_root_path(_resource_or_scope)
10
14
  main_app.root_path
11
15
  end
12
16
 
@@ -16,11 +20,11 @@ module G5Authenticatable
16
20
  resource.save!
17
21
  end
18
22
 
19
- def after_omniauth_failure_path_for(scope)
23
+ def after_omniauth_failure_path_for(_scope)
20
24
  auth_error_path
21
25
  end
22
26
 
23
- def after_sign_out_path_for(resource_or_scope)
27
+ def after_sign_out_path_for(_resource_or_scope)
24
28
  main_app.root_path
25
29
  end
26
30
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
4
+ # Helper methods for all G5Authenticatable controllers/views
2
5
  module ApplicationHelper
3
6
  end
4
7
  end
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
4
+ # A user role (e.g. admin, viewer), optionally scoped to a client or location
2
5
  class Role < ActiveRecord::Base
3
- has_and_belongs_to_many :users, :join_table => :g5_authenticatable_users_roles
4
- belongs_to :resource, :polymorphic => true
6
+ has_and_belongs_to_many :users, join_table: :g5_authenticatable_users_roles
7
+ belongs_to :resource, polymorphic: true
5
8
 
6
9
  scopify
7
10
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
4
+ # Cache of local user data, populated based on G5 Auth
2
5
  class User < ActiveRecord::Base
3
6
  devise :g5_authenticatable, :trackable, :timeoutable
4
7
  rolify role_cname: 'G5Authenticatable::Role',
@@ -10,13 +13,13 @@ module G5Authenticatable
10
13
  GLOBAL_ROLE = 'GLOBAL'
11
14
 
12
15
  def attributes_from_auth(auth_data)
13
- super(auth_data).merge({
16
+ super(auth_data).merge(
14
17
  first_name: auth_data.info.first_name,
15
18
  last_name: auth_data.info.last_name,
16
19
  phone_number: auth_data.info.phone,
17
20
  title: auth_data.extra.title,
18
21
  organization_name: auth_data.extra.organization_name
19
- })
22
+ )
20
23
  end
21
24
 
22
25
  def update_roles_from_auth(auth_data)
@@ -27,18 +30,22 @@ module G5Authenticatable
27
30
  end
28
31
 
29
32
  def selectable_clients
30
- G5Updatable::SelectableClientPolicy::Scope.new(self, G5Updatable::Client).resolve
33
+ G5Updatable::SelectableClientPolicy::Scope.new(self, G5Updatable::Client)
34
+ .resolve
31
35
  end
32
36
 
33
37
  def clients
34
- G5Updatable::ClientPolicy::Scope.new(self, G5Updatable::Client).resolve
38
+ G5Updatable::ClientPolicy::Scope.new(self, G5Updatable::Client)
39
+ .resolve
35
40
  end
36
41
 
37
42
  def locations
38
- G5Updatable::LocationPolicy::Scope.new(self, G5Updatable::Location).resolve
43
+ G5Updatable::LocationPolicy::Scope.new(self, G5Updatable::Location)
44
+ .resolve
39
45
  end
40
46
 
41
47
  private
48
+
42
49
  def add_scoped_role(role)
43
50
  the_class = Object.const_get(role.type)
44
51
  resource = the_class.where(urn: role.urn).first