-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 configuration flag deprecated associated user #4201
Add configuration flag deprecated associated user #4201
Conversation
A configuration flag was needed to start a cycle of deprecation of the Spree::Core::ControllerHelpers::Order#associate_user method. This method is deprecated because now this association is done immediately by the authentication system when needed.
…ttps:https://github.com/carlosep/solidus into add_configuration_flag_deprecated_associated_user � Conflicts: � core/lib/spree/testing_support/dummy_app.rb
@waiting-for-dev @kennyadsl. check please my last commit. I removed also In my local environment by default behavior is :stedrr and tests are true. But circle/ci return error. I see deprecation return ActiveSupport::DeprecationException. How I understood correct it is mean behavior assigned as |
core/lib/spree/app_configuration.rb
Outdated
@@ -169,6 +169,10 @@ class AppConfiguration < Preferences::Configuration | |||
# @return [String] Email address used as +From:+ field in transactional emails. | |||
preference :mails_from, :string, default: '[email protected]' | |||
|
|||
# @!attribute [rw] associate_user_in_authentication_extension | |||
# @return [Boolean] manually call associate_user instead of relying on current_order | |||
preference :associate_user_in_authentication_extension, :boolean, default: by_version(false, "4.0.0" => true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preference :associate_user_in_authentication_extension, :boolean, default: by_version(false, "4.0.0" => true) | |
preference :associate_user_in_authentication_extension, :boolean, default: by_version(false, "3.2.0.alpha" => true) |
We're going to remove the setting in v4.0 completely. We want it to be false
on 3.1, but true
on master (v3.2.0.alpha) and onward (v3.2.0). When users update v3.1 to v3.2 with bin/rails g solidus:update
, they will keep having it to false
as it will be overridden by the generated initializer new_solidus_defaults.rb
. Then, they'll adapt their app (if needed) and remove the override. Once done, they'll be using true
(default in v3.2), and their app will be ready for the future update to v4.0, where we'll completely remove all references to :associate_user_in_authentication_extension
.
Once done this change, no error should be raised on the CI.
@@ -40,6 +40,8 @@ Spree.config do |config| | |||
# Template to use when rendering layout | |||
# config.layout = "spree/layouts/spree_application" | |||
|
|||
# manually call associate_user instead of relying on current_order | |||
# config.associate_user_in_authentication_extension = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we're going to remove the setting in v4.0 altogether, I think it's better not to add it in the generated spree.rb
for fresh installations. They should be using the new default, and there's no need for them to know anything about the old behavior that will be removed. Thoughts @kennyadsl ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still would like some thought about it. @kennyadsl, what are we usually doing in these cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @waiting-for-dev, I'd remove this as well.
Thanks for your continued work on this, @dborovsky! I tried to explain better the deprecation path. I hope it's clearer now. I'm also pinging @kennyadsl for a minor question.
Once my comment is addressed, the CI should be 💚 |
context "configuration associate_user_in_authentication_extension is false" do | ||
before do | ||
stub_spree_preferences(associate_user_in_authentication_extension: false) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move the above specs into this context since they will start failing once we update the version and also they are only relevant in the case where the value of this setting is false
.
We could also add a test for the new behaviour which should not associate the user nor show a deprecation warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also add a test for the new behaviour which should not associate the user nor show a deprecation warning.
Agree
I think we should move the above specs into this context since they will start failing once we update the version and also they are only relevant in the case where the value of this setting is false.
What I've been doing is still to test that the deprecation warning is shown. As it's useful for users, I like to have it covered. We'd remove it alongside the setting on v4.0
. But, in this case, mine is not a strong opinion, so I'd be good with any outcome.
@forkata @waiting-for-dev check please my solution, could you check the tests which are failed in CI/circleci. |
@@ -54,6 +54,7 @@ | |||
# The first step for checkout controller is address | |||
# Transitioning into this state first is required | |||
order.update_column(:state, "address") | |||
stub_spree_preferences(associate_user_in_authentication_extension: false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it that we need to override the new setting value here? Wasn't the method useless?
You need to rebase from master because of #4209 |
@forkata @waiting-for-dev If the method
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking care of this. I left a comment on the approach, which I think it's not the right one. Let me know!
@@ -37,6 +37,11 @@ def current_order(options = {}) | |||
end | |||
|
|||
def associate_user | |||
return if Spree::Config.associate_user_in_authentication_extension |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just stop calling this method from inside our core codebase instead of returning if the preference is true.
I can see at least a couple of occurrences:
associate_user before_action :associate_user
If it's useless, things should keep working as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding a conditional on the value of the preference in multiple places may be slightly worse than just checking it in the method itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@forkata I believe @kennyadsl is suggesting not having an option at all. We can simply deprecate it and stop using it in core, then later remove it entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes, sense, I misread the comment here 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@waiting-for-dev @forkata @kennyadsl Please read my comment above #4201 (comment)
@@ -37,6 +37,11 @@ def current_order(options = {}) | |||
end | |||
|
|||
def associate_user | |||
return if Spree::Config.associate_user_in_authentication_extension |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding a conditional on the value of the preference in multiple places may be slightly worse than just checking it in the method itself.
stub_spree_preferences(associate_user_in_authentication_extension: true) | ||
end | ||
|
||
it "should associate the order with a user" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably say "should not associate the order with a user"
.
order.update_column :user_id, nil | ||
expect(order).to receive(:associate_user!).with(user) | ||
get :edit | ||
context "current behavior" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better if we say "with associate_user_in_authentication_extension enabled"
as this behaviour will change with the version bump.
end | ||
end | ||
|
||
context "new behavior" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the above comment, this may be better as "with associate_user_in_authentication_extension disabled"
.
end | ||
|
||
context "user isn't blank" do | ||
it 'does not calls Spree::Order#associate_user! method' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "does not call Spree::Order#associate_user! method"
.
Did you get why this is happening? Can you please explain where exactly and in which circumstances? |
It happens here:
Because now |
I guess we need to keep |
Yes. The method @forkata @waiting-for-dev What do you think? |
@forkata @waiting-for-dev @kennyadsl any news? |
I've been reviewing it, and I think we can close it. Thanks for your work, @dborovsky, and for discovering that the method is still helpful for the checkout controller. We could still remove the call from the orders controller. However, given that we're going to deprecate the current frontend in favor of |
Hi Marc. (@waiting-for-dev ) I agree. I would like to help contributing solidus. Tell me which tasks are actual and in priority now. |
Hey, @dborovsky, that would be amazing! Would contact me through DM on Slack work for you? My nickname is @waiting_for_dev. Let me know if you prefer any other channel. |
Description
task - #3559
Checklist: