Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option 'use_redirect_back_or_to_by_rails' to avoid definition conflicts of redirect_back_or_to #373

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

atolix
Copy link

@atolix atolix commented May 1, 2024

Fix: #296

Rails 7 released a new method called redirect_back_or_to as a replacement for redirect_back. That may conflicts with the method by the same name defined by Sorcery.

This commit adds an option to set whether to use redirect_back_or_to defined by Rails 7, and add a method redirect_to_before_login_path as an alternative to sorcery's `redirect_back_or_to.

ref: rails/rails#40671

Please ensure your pull request includes the following:

  • Description of changes
  • Update to CHANGELOG.md with short description and link to pull request
  • Changes have related RSpec tests that ensure functionality does not break

@atolix atolix force-pushed the rails-7-redirect-back-or-to-fix branch from ce4db7e to 14be051 Compare May 1, 2024 06:30
@atolix atolix marked this pull request as ready for review May 1, 2024 06:32
@@ -96,7 +96,16 @@ def current_user=(user)

# used when a user tries to access a page while logged out, is asked to login,
# and we want to return him back to the page he originally wanted.
def redirect_back_or_to(url, flash_hash = {})
def redirect_back_or_to(...)
if Config.use_redirect_back_or_to_by_rails
Copy link
Member

@willnet willnet May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are using Rails 6.1, calling super will cause an exception. Therefore, I want to ensure that super is not called even if Config.use_redirect_back_or_to_by_rails returns true.

Can you update the tests to expect a NoMethodError exception when using Rails 6.1?

The tests are currently failing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed in 7a494fc

if Config.use_redirect_back_or_to_by_rails
super
else
warn('[WARNING] `redirect_back_or_to` overrides the method of the same name defined in Rails 7. If you want to avoid overriding, you can set `config.use_redirect_back_or_to_by_rails = true` and use `redirect_to_before_login_path`.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is desirable for this setting to default to true in the future, I would like to add that "in a future version, config.use_redirect_back_or_to_by_rails = true will become the default."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the message in 8ebe075

…conflicts 'redirect_back_or_to'

Fix: Sorcery#296

Rails 7 released a new method called `redirect_back_or_to` as a replacement for `redirect_back`.
That may conflicts with the method by the same name defined by Sorcery.

This commit adds an option to set whether to use `redirect_back_or_to` defined by Rails 7, and add
the method `redirect_to_before_login_path` as an alternative to sorcery's `redirect_back_or_to.

ref: rails/rails#40671
@atolix atolix force-pushed the rails-7-redirect-back-or-to-fix branch from 42bab9a to f2106da Compare May 9, 2024 16:23
@atolix atolix force-pushed the rails-7-redirect-back-or-to-fix branch from f2106da to 7a494fc Compare May 9, 2024 16:25
@atolix atolix requested a review from willnet May 9, 2024 16:28
Copy link
Member

@willnet willnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very good at English, so I'm not sure if the comments and warning messages sound natural, but I think the implementation is fine.

@willnet
Copy link
Member

willnet commented May 29, 2024

@joshbuker As far as I have reviewed, I think the implementation is fine, but I'm not sure if the comments and other texts are clear. Could you please review them?

@willnet willnet requested a review from joshbuker May 29, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should Sorcery rename redirect_back_or_to?
2 participants