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

filter distributors before listing on checkout options #11079

Conversation

abdellani
Copy link
Member

@abdellani abdellani commented Jun 19, 2023

What? Why?

What should we test?

Release notes

Changelog Category: Technical changes

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@abdellani abdellani self-assigned this Jun 19, 2023
@abdellani abdellani force-pushed the fix-distributors-listing-on-checkout-options branch 4 times, most recently from 090203e to aa58562 Compare June 21, 2023 08:31
@abdellani abdellani marked this pull request as ready for review June 21, 2023 09:03
@Matt-Yorkley
Copy link
Contributor

I think we should add a couple more tests for the two cases mentioned in the issue that explicitly set up this scenario where there are multiple suppliers in the OC and the current user manages a supplier that's assigned to the OC but isn't the coordinator.

@abdellani abdellani force-pushed the fix-distributors-listing-on-checkout-options branch from aa58562 to b072da1 Compare June 22, 2023 08:00
Copy link
Contributor

@Matt-Yorkley Matt-Yorkley left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Comment on lines 43 to 45
order_cycle.distributors.select do |distributor|
distributor.in? Enterprise.managed_by(spree_current_user)
end
Copy link
Member

Choose a reason for hiding this comment

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

I would hope that Enterprise.managed_by(spree_current_user) is cached but it wouldn't hurt to store it in a variable first. It could also be represented as a union:

Suggested change
order_cycle.distributors.select do |distributor|
distributor.in? Enterprise.managed_by(spree_current_user)
end
order_cycle.distributors & Enterprise.managed_by(spree_current_user)

But super-admin can see all enterprises which would make this list very long. So we could add a condition to shortcut super admin.

Oh, hang on, I'm just realising that we completely missed the greatest feature of ActiveRecord scopes: chaining!

Suggested change
order_cycle.distributors.select do |distributor|
distributor.in? Enterprise.managed_by(spree_current_user)
end
order_cycle.distributors.managed_by(spree_current_user)

I reckon that this change is worth doing before merging.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, tried that and it turns out that order_cycle.distributors is an array, not a scope. Oh, hang on, just in the spec...

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

I added a few commits. That's my suggestion but I may have overlooked something. This needs another review by someone else, including @abdellani. If you are happy with this, then move it to Test Ready.

@mkllnk mkllnk force-pushed the fix-distributors-listing-on-checkout-options branch from d89483f to c3d49bf Compare June 26, 2023 02:56
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

I believe it's good, but I must admit I don't know much about coordinator and distributor.

@@ -94,24 +94,27 @@
end

describe "distibutors that have editable shipping/payment methods" do
let(:result) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would use subject here :

Suggested change
let(:result) {
subject(:result) {
helper.distributors_with_editable_shipping_and_payment_methods(order_cycle)
}

app/helpers/order_cycles_helper.rb Show resolved Hide resolved
@dacook
Copy link
Member

dacook commented Jun 27, 2023

Hi @abdellani , it looks like we just need to you confirm Maikel's latest changes and move to Test Ready if you're happy with them.

@abdellani
Copy link
Member Author

Ok, it looks good to me :)
thank you @mkllnk for the updates
thanks to everyone.

@filipefurtad0 filipefurtad0 self-assigned this Jun 29, 2023
@filipefurtad0 filipefurtad0 added the pr-staged-uk staging.openfoodnetwork.org.uk label Jun 29, 2023
@filipefurtad0
Copy link
Contributor

Hey @abdellani ,

I've checked now, that supplier enterprises which do not coordinated the OC cannot view/edit payment/shipping methods from the other enterprises:

image

Also, I've checked that a distributor which is not the coordinator of the OC, can only see/edit their own shipping/payment methods:

image

This looks great!!
Thanks, merging 🚀

@filipefurtad0 filipefurtad0 merged commit d27a632 into openfoodfoundation:master Jun 29, 2023
@filipefurtad0 filipefurtad0 removed the pr-staged-uk staging.openfoodnetwork.org.uk label Jun 29, 2023
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.

6 participants