-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
745 move authenticate user method (#788)
* add: authenticate_user! as a before action in application controller instead of calling it within multiple controllers * add: skip_before_action authenticate_user! for controllers that don't need user authentication * remove: commented out 'skip_before_action' from controllers * fix failing tests: after adding authentication these tests were failing as these controller tests required authentication * add: config for devise configuration for setting up custom failures through warden in the devise.rb * add custom failure file this custom failure module redirects a user to the sign-in page if they arent no authenticated * update: failure app This failure app is mostly reproduced from Devises FailureApp class. The 5th line ```opts[:script_name] = nil``` was preventing the OrganizationMiddleware from generating the correct route with the Organization slug. This version allows us to keep the full functionality of the scoped_url method within Devises FailureApp and generate the route Co-authored-by: Paul DobbinSchmaltz <[email protected]> * add more context to why this authentication failure app is needed. * update: rails standard fix
- Loading branch information
1 parent
7dfb98c
commit d2cdc9d
Showing
18 changed files
with
82 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
app/controllers/organizations/adopter_fosterer/adopter_applications_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
app/controllers/organizations/adopter_fosterer/profiles_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class AuthenticationFailureApp < Devise::FailureApp | ||
# This method is used to generate the URL for the redirect after a user fails to authenticate, | ||
# for example, when an unauthenticated user tries to access an authenticated route within an organization's scope. | ||
# The issue was that if a user failed to authenticate while in the context of an organization, | ||
# the organization's slug should be in the URL. So, after failing, the user would be redirected | ||
# to the sign-in page, but the organization's scope would be lost in the URL, | ||
# and it would fall back to the root URL instead of the organization's sign-in URL. | ||
# This fixes that to ensure the organization's slug is present in the URL. | ||
# | ||
# This code is 99% reproduced from the Devise gem's Devise::FailureApp class | ||
# at: lib/devise/failure_app.rb. The only exception is that we comment out the | ||
# 5th line: | ||
# opts[:script_name] = nil | ||
# | ||
# This line was causing the`env["SCRIPT_NAME"]` value that's set by | ||
# OrganizationMiddleware to not be used when generating the route in the | ||
# statement `context.send(route, opts)`, which wipes out the current | ||
# Organization context on authentication failure. | ||
# | ||
# If Devise is upgraded, may need to compare this method across versions for | ||
# any needed updates. | ||
def scope_url | ||
opts = {} | ||
|
||
# Initialize script_name with nil to prevent infinite loops in | ||
# authenticated mounted engines in rails 4.2 and 5.0 | ||
# opts[:script_name] = nil | ||
|
||
route = route(scope) | ||
|
||
opts[:format] = request_format unless skip_format? | ||
|
||
router_name = Devise.mappings[scope].router_name || Devise.available_router_name | ||
context = send(router_name) | ||
|
||
if relative_url_root? | ||
opts[:script_name] = relative_url_root | ||
|
||
# We need to add the rootpath to `script_name` manually for applications that use a Rails | ||
# version lower than 5.1. Otherwise, it is going to generate a wrong path for Engines | ||
# that use Devise. Remove it when the support of Rails 5.0 is dropped. | ||
elsif root_path_defined?(context) && !rails_51_and_up? | ||
rootpath = context.routes.url_helpers.root_path | ||
opts[:script_name] = rootpath.chomp("/") if rootpath.length > 1 | ||
end | ||
|
||
if context.respond_to?(route) | ||
context.send(route, opts) | ||
elsif respond_to?(:root_url) | ||
root_url(opts) | ||
else | ||
"/" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters