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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +23 -9
- data/Appraisals +17 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +11 -14
- data/README.md +40 -13
- data/app/controllers/concerns/g5_authenticatable/authorization.rb +4 -1
- data/app/controllers/g5_authenticatable/application_controller.rb +3 -0
- data/app/controllers/g5_authenticatable/error_controller.rb +3 -2
- data/app/controllers/g5_authenticatable/failure_app.rb +35 -0
- data/app/controllers/g5_authenticatable/sessions_controller.rb +7 -3
- data/app/helpers/g5_authenticatable/application_helper.rb +3 -0
- data/app/models/g5_authenticatable/role.rb +5 -2
- data/app/models/g5_authenticatable/user.rb +12 -5
- data/app/policies/g5_authenticatable/base_policy.rb +75 -58
- data/app/policies/g5_updatable/client_policy.rb +5 -5
- data/app/policies/g5_updatable/location_policy.rb +6 -5
- data/app/policies/g5_updatable/selectable_client_policy.rb +6 -7
- data/app/services/g5_authenticatable/impersonate_sessionable.rb +12 -7
- data/config/initializers/devise.rb +4 -0
- data/config/initializers/impersonate_strategy.rb +5 -2
- data/config/initializers/rolify.rb +2 -0
- data/config/routes.rb +3 -1
- data/g5_authenticatable.gemspec +11 -7
- data/gemfiles/rails_4.1.gemfile +28 -0
- data/gemfiles/rails_4.2.gemfile +28 -0
- data/gemfiles/rails_5.0.gemfile +28 -0
- data/gemfiles/rails_5.1.gemfile +28 -0
- data/lib/g5_authenticatable.rb +3 -1
- data/lib/g5_authenticatable/engine.rb +5 -2
- data/lib/g5_authenticatable/rspec.rb +2 -0
- data/lib/g5_authenticatable/test/controller_helpers.rb +14 -9
- data/lib/g5_authenticatable/test/env_helpers.rb +3 -0
- data/lib/g5_authenticatable/test/factories/client_users.rb +45 -0
- data/lib/g5_authenticatable/test/factories/global_users.rb +43 -0
- data/lib/g5_authenticatable/test/factories/location_users.rb +45 -0
- data/lib/g5_authenticatable/test/factories/roles.rb +63 -0
- data/lib/g5_authenticatable/test/factory.rb +7 -59
- data/lib/g5_authenticatable/test/feature_helpers.rb +31 -17
- data/lib/g5_authenticatable/test/request_helpers.rb +5 -1
- data/lib/g5_authenticatable/test/token_validation_helpers.rb +15 -10
- data/lib/g5_authenticatable/version.rb +3 -1
- data/lib/generators/g5_authenticatable/install/install_generator.rb +49 -37
- data/lib/generators/g5_authenticatable/install/templates/application_policy.rb +2 -0
- data/lib/generators/g5_authenticatable/install/templates/initializer.rb +2 -0
- data/lib/generators/g5_authenticatable/install/templates/migrate/add_g5_authenticatable_users_contact_info.rb +3 -1
- data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_roles.rb +3 -1
- data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_users.rb +3 -1
- data/lib/tasks/g5_authenticatable/purge_users.rake +2 -0
- data/spec/config/application_spec.rb +7 -4
- data/spec/controllers/application_controller_spec.rb +10 -5
- data/spec/controllers/concerns/g5_authenticatable/{authorization.rb → authorization_spec.rb} +11 -6
- data/spec/dummy/app/controllers/home_controller.rb +5 -5
- data/spec/dummy/app/controllers/rails_api/secure_resources_controller.rb +6 -4
- data/spec/dummy/app/models/post.rb +1 -1
- data/spec/dummy/config/environments/test.rb +25 -4
- data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
- data/spec/dummy/db/migrate/20140206070137_create_g5_authenticatable_users.rb +3 -1
- data/spec/dummy/db/migrate/20150428182339_add_g5_authenticatable_users_contact_info.rb +3 -1
- data/spec/dummy/db/migrate/20150429212919_create_g5_authenticatable_roles.rb +2 -1
- data/spec/dummy/db/migrate/20150509061150_create_posts.rb +3 -1
- data/spec/dummy/db/migrate/20150603224032_create_g5_updatable_clients_and_locations.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224033_create_integration_setting.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224034_remove_integration_setting.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224035_add_name_to_clients_and_locations.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224036_update_names.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20170613201430_add_latitude_and_longitude_to_location.g5_updatable.rb +7 -0
- data/spec/dummy/db/migrate/20170613201431_copy_lat_long_props_to_lat_long_columns.g5_updatable.rb +20 -0
- data/spec/dummy/db/migrate/20170613201432_add_latitude_longitude_indexes_to_location.g5_updatable.rb +7 -0
- data/spec/dummy/db/migrate/{20161122070749_add_amenities.rb → 20170613201433_add_amenities.g5_updatable.rb} +2 -1
- data/spec/dummy/db/migrate/{20161209070749_add_client_urn_to_locations.rb → 20170613201434_add_client_urn_to_locations.g5_updatable.rb} +2 -1
- data/spec/dummy/db/migrate/20170613201435_add_points_of_interest.g5_updatable.rb +21 -0
- data/spec/dummy/db/migrate/20170613201436_add_unique_urn_indexes.g5_updatable.rb +11 -0
- data/spec/dummy/db/schema.rb +73 -61
- data/spec/factories/post.rb +2 -0
- data/spec/features/auth_error_path_spec.rb +3 -3
- data/spec/features/default_role_authorization_spec.rb +8 -4
- data/spec/features/sign_in_spec.rb +23 -13
- data/spec/features/token_validation_spec.rb +4 -2
- data/spec/g5_authenticatable/version_spec.rb +3 -1
- data/spec/lib/generators/g5_authenticatable/install_generator_spec.rb +73 -28
- data/spec/models/g5_authenticatable/role_spec.rb +8 -4
- data/spec/models/g5_authenticatable/user_spec.rb +119 -84
- data/spec/models/post_spec.rb +4 -2
- data/spec/policies/application_policy_spec.rb +80 -47
- data/spec/policies/client_policy_spec.rb +8 -5
- data/spec/policies/location_policy_spec.rb +21 -8
- data/spec/policies/selectable_client_policy_spec.rb +26 -15
- data/spec/rails_helper.rb +41 -0
- data/spec/requests/default_role_authorization_spec.rb +18 -14
- data/spec/requests/grape_api_spec.rb +7 -5
- data/spec/requests/rails_api_spec.rb +11 -9
- data/spec/requests/sign_out_spec.rb +10 -6
- data/spec/requests/token_validation_spec.rb +9 -5
- data/spec/routing/auth_error_routing_spec.rb +7 -6
- data/spec/routing/sign_out_routing_spec.rb +7 -5
- data/spec/services/g5_authenticatable/impersonate_sessionable_spec.rb +41 -18
- data/spec/spec_helper.rb +78 -45
- data/spec/support/devise.rb +3 -1
- data/spec/support/safe_request_helpers.rb +36 -0
- data/spec/support/shared_contexts/rake.rb +10 -4
- data/spec/support/shared_examples/super_admin_authorizer.rb +3 -1
- data/spec/tasks/purge_users_spec.rb +3 -1
- metadata +75 -39
- data/spec/controllers/.gitkeep +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a76fa37dacb1777aa7e76189bf050ffdae4bab7a
|
|
4
|
+
data.tar.gz: e323ad93ec0f5f40500e999c5303828b4f7070c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 83e1c15d70f574298141c0515335fe6bb7d3e9dd31c356b8dec6aba013209a3b6e1423b23ed366307c84bd53e25a35eb5eb7ddd0b2a7565b8e908b65861bb5f7
|
|
7
|
+
data.tar.gz: c1117229b44ca11584355e70c4262d023f708e1b604cd8f6de1fed0c064aff583668184dd064dad172c5aff717d1e671934b4c3d47f29f9480f6f2d1f69d4530
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.3.4
|
data/.travis.yml
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
language: ruby
|
|
2
2
|
rvm:
|
|
3
|
-
- 2.
|
|
4
|
-
- 2.
|
|
5
|
-
- 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
|
-
-
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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.
|
|
21
|
+
1.0.0.pre.1
|
|
22
22
|
|
|
23
23
|
## Requirements
|
|
24
24
|
|
|
25
|
-
* [rails](https://github.com/rails/rails) >=
|
|
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 :
|
|
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
|
|
136
|
+
To set up a controller that requires authentication, use this before_action:
|
|
137
137
|
|
|
138
138
|
```ruby
|
|
139
|
-
|
|
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
|
-
|
|
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/
|
|
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 `
|
|
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
|
-
|
|
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
|
-
|
|
751
|
-
|
|
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
|
-
|
|
772
|
-
|
|
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,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(
|
|
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(
|
|
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(
|
|
27
|
+
def after_sign_out_path_for(_resource_or_scope)
|
|
24
28
|
main_app.root_path
|
|
25
29
|
end
|
|
26
30
|
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, :
|
|
4
|
-
belongs_to :resource, :
|
|
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)
|
|
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)
|
|
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)
|
|
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
|