-
-
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
Fix Spree::Admin::VariantsController#index for deleted products #1804
Conversation
Obviously this isn't as simple as adding |
Seems worth fixing in some way. Some thoughts:
Any chance this might open up any vulnerabilities for custom controllers that stores have that inherit from We could also just override the required methods in |
As I was thinking about it more, this was the direction I was taking. The question now is to what degree: do I just override |
I think the change with the smallest impact that fixes the bug would be overriding |
Another thought: Would it work to just do: belongs_to 'spree/product', find_by: :slug, model_class: Spree::Product.with_deleted ? |
I'm not sure I love the thought of setting an option called |
@jordan-brough your solution is clever, but I think overriding |
Poke. |
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 have one suggestion, otherwise LGTM.
I like @jordan-brough's suggestion, but I agree that it's too clever and makes assumptions about how model_class
is used. I'd be okay if we introduced a model_scope
(or scope
) option, but such a change is outside the scope of this PR.
@parent ||= parent_data[:model_class].with_deleted.send("find_by_#{parent_data[:find_by]}", params["#{model_name}_id"]) | ||
instance_variable_set("@#{model_name}", @parent) | ||
end | ||
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.
We know what all these values are, so we can probably just
def parent
@parent ||= Spree::Product.with_deleted.find_by(slug: params[:product_id])
@product = @parent
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 agree this is an improvement. Will fix.
By using subject we can eliminate duplication in our specs.
With no context blocks, this spec was setup to only test one thing. Let's wrap the current tests in some context so we can add more tests without having unneeded setup.
Per issue solidusio#1803 deleted products could not show their variants due to a missing `with_deleted` scope on `ResourceController#parent`.
These context descriptions are more descriptive and succinct.
Feedback implemented. Ready for another review. |
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.
LGTM. Thanks again Brian
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.
Well done, thank you!
Poke. |
Fixes #1803
When a
Product
was deleted,@parent
would not be set correctly when accessingSpree::Admin::VariantsController#index
. Adding thewith_deleted
scope for the assignment toSpree::Admin::ResourceController#parent
addresses this problem.The heart of the change happens in dec876c while the rest of the commits clean up the specs for
Spree::Admin::VariantsController
.