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

Allow producer to edit their products on hubs' orders #13113

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

Conversation

chahmedejaz
Copy link
Collaborator

@chahmedejaz chahmedejaz commented Feb 1, 2025

⚠️ Please use clockify code #12476 Flower Farms

What? Why?

What should we test?

  • As mention in the issue
  • Along with this, please test the whole existing order module

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

@chahmedejaz chahmedejaz force-pushed the task/13031-allow-producers-to-edit-orders branch from 764ea78 to ae86821 Compare February 1, 2025 23:56
@chahmedejaz chahmedejaz force-pushed the task/13031-allow-producers-to-edit-orders branch from 2e12ce7 to a747c88 Compare February 10, 2025 20:46
@chahmedejaz chahmedejaz force-pushed the task/13031-allow-producers-to-edit-orders branch from d9f0454 to e4ef890 Compare February 15, 2025 20:57
@chahmedejaz chahmedejaz changed the title Task/13031 allow producers to edit orders Allow producer to edit their products on hubs' orders Feb 15, 2025
@chahmedejaz chahmedejaz marked this pull request as ready for review February 15, 2025 21:07

# Users can manage line items in orders if they have producer enterprise and
# any of order distributors allow them to edit their orders.
def can_manage_line_items_in_orders?(user)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding the same user method names here for the sake of writing ability specs to better show the assigned abilities

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.

Hi @chahmedejaz It's a good start, but I would like to see more unit test. It's a bit hard to follow if all changes are covered by some specs as you added them at the end. In general it's better to commit the specs whit the actual changes, at least the unit test.
I am wondering if we should also add a some system spec, at least for the order edit page.

Comment on lines +46 to +52
if @user.can_manage_line_items_in_orders_only?
Spree::LineItem.editable_by_producers(
@permissions.managed_enterprises.select("enterprises.id")
)
else
Spree::LineItem.where(order_id: editable_orders.select(:id))
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

specs ?

@@ -4,7 +4,7 @@

module Permissions
RSpec.describe Order do
let(:user) { double(:user) }
let(:user) { double(:user, can_manage_line_items_in_orders_only?: false) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might as well improve the spec here by using instance_doubleinstead of double . instance_double actually checks if the stubbed method would exist on an actual instance see: https://rspec.info/features/3-13/rspec-mocks/verifying-doubles/instance-doubles/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, will look into this improvement. 👍🏻

@chahmedejaz
Copy link
Collaborator Author

chahmedejaz commented Feb 17, 2025

Thanks @rioug for the feedback. Let me incorporate and get back to you.

@chahmedejaz chahmedejaz force-pushed the task/13031-allow-producers-to-edit-orders branch from 206acdd to 361e7da Compare March 3, 2025 00:52
@chahmedejaz chahmedejaz force-pushed the task/13031-allow-producers-to-edit-orders branch from 5858014 to 53ec662 Compare March 3, 2025 01:15
@chahmedejaz chahmedejaz requested a review from rioug March 3, 2025 01:19
Ferrum::BrowserError:
       Argument should belong to the same JavaScript world as target object
@chahmedejaz
Copy link
Collaborator Author

chahmedejaz commented Mar 3, 2025

Hi @rioug - I've improved the specs now. It's ready for review. Thanks. :)

Edit: Sorry I added specs in the last commit. From future, I'll try to add them in the same commit as the changes

@dacook dacook self-requested a review March 3, 2025 23:58
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

A big effort, who would have guessed it would be so complicated! It's great to see thorough specs 💪

Some parts of it are hard to understand, because it's adding lots of very specific checks in different places. Eg can_manage_line_items_in_orders_only?

I can't quite get all around it in my head to suggest a better arrangement though. I have several other comments:

@@ -159,6 +159,11 @@ def distributor_allows_order_editing?(order)
spree_current_user.can_manage_line_items_in_orders_only?
end

def display_value_for_producer(order, value)
return value unless distributor_allows_order_editing?(order)
Copy link
Member

@dacook dacook Mar 4, 2025

Choose a reason for hiding this comment

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

I think the question here is not if distributor_allows_order_editing?, but if "user is distributor?"

If the current user is not an authorised manager of the distributor, then they should not have access to customer details until permitted. It should be easy to check that I think.

In this case, it works, but could be confusing and if the logic changes in the future it might cause a problem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's addressed here: 8c73f36

- we are using OR between two queries here: https://github.com/openfoodfoundation/openfoodnetwork/blob/53ec6621bc30aa86f64440c9b1f9f9357da9a1b1/app/services/search_orders.rb#L31-L32
- so to make it compatible with this, had to revert

Throws following error:
Relation passed to #or must be structurally compatible. Incompatible values: [:left_outer_joins]
@chahmedejaz
Copy link
Collaborator Author

Hi @dacook - I've addressed your comments, please review. Thanks

@chahmedejaz chahmedejaz requested a review from dacook March 5, 2025 00:43
@chahmedejaz
Copy link
Collaborator Author

Some parts of it are hard to understand, because it's adding lots of very specific checks in different places. Eg can_manage_line_items_in_orders_only?
I can't quite get all around it in my head to suggest a better arrangement though. I have several other comments

Yes, I can understand it's confusing a bit 😓 sorry for that.
It's just representing if the user has only the ability to manage line_items in the orders then no other unrelated action should be either viewed or performed in that case.
We are only assigning this ability to the producer who is allowed to edit orders for now.

Please let me know if you have any questions, would love to address. Thanks for digging into this one and your detailed analysis, It's really worth it @dacook ❤️

- this before block was causing multiple nevigation to the index
  - one from the spec itself, one from here.
@dacook dacook force-pushed the task/13031-allow-producers-to-edit-orders branch from 89cf454 to b3877be Compare March 5, 2025 00:56
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Hi Ahmed, thanks for the explanations and follow-up. I really appreciate you addressing all my questions and concerns.

It's exciting to see the new feature!

As a few things have changed, it would be good to have a second review before testing. But Gaetan is sick and I'm not sure it's practical for Maikel to review the whole thing. So I suggest it's ok to move to testing in this case. What do you think?

@chahmedejaz
Copy link
Collaborator Author

Sounds good, @dacook. Moving this to test ready. Thanks.

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.

Thanks for adding all the specs !

end


def expect_product_change(product, action, expected_qty = 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice one 👍 It makes the specs so much easier to understand

@sigmundpetersen sigmundpetersen added the user facing changes Thes pull requests affect the user experience label Mar 19, 2025
@filipefurtad0 filipefurtad0 self-assigned this Mar 20, 2025
@filipefurtad0 filipefurtad0 added pr-staged-fr staging.coopcircuits.fr pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-fr staging.coopcircuits.fr pr-staged-au staging.openfoodnetwork.org.au labels Mar 20, 2025
@filipefurtad0
Copy link
Contributor

Hey @chahmedejaz ,

Nice, this is quite a chunk of work 💪

Going through different scenarios:

  1. Verified that the option to allow producers to edit orders is visible on the enterprise settings

image

Tooltip is visible:
image

2.a) Before enabling this option, as the producer, visiting /admin/orders or /admin/bulk_order_management triggers a 401 Unauthorized error, as before:

image

2.b) after enabling this option, the URLs /admin/orders and /admin/bulk_order_management are accessible by the producer. The following tests were performed, after logging as a producer supplying a hub and with access to order edition:

i) See you can see ONLY orders containing the producer's product in /admin/orders and BOM. Other orders from the hub should not be available. 🟢
ii) You can add, edit (change quantity and weight) and delete products. 🟢
iii) You can't do actions on an order or cancel an order -> it is still possible to ship an order, on the orders page 🔴

image

iv) You can't see other producer products in the add a product dropdown or on the order details page (unless you manage several producers). 🟢

image

v) check BOM is pre-filtered if only one producer available 🟢

image

iv) If customer names in report are disabled, customer names should be hidden in orders and BOM lists 🟢

This seems good to go, except for the fact that the ship button is still visible, in the producer view (test 2.b.iii)). Perhaps best to address this before shipping this feature. Moving back to in Progress.

@chahmedejaz
Copy link
Collaborator Author

Thanks @filipefurtad0 for detailed feedback, it's now fixed.

@openfoodfoundation/reviewers it's fixed here: e605229

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

👍

@filipefurtad0 filipefurtad0 added the pr-staged-fr staging.coopcircuits.fr label Mar 24, 2025
@filipefurtad0
Copy link
Contributor

filipefurtad0 commented Mar 24, 2025

Hey @chahmedejaz,

Thanks for hiding the order shipping option, for the producer, on the orders page 🟢

image

Apologies, but I have forgotten that we have optional columns on the Bulk Order Management page, for Name and Email:

image

Also, optional to display, is the customers' Phone too.

I'd argue these should be hidden as well, when the setting for Names in Customer Reports is disabled, for the managing hub. Ping @openfoodfoundation/train-drivers-product-owners.

Since this one is a privacy issue, I think it blocks releasing this feature for now. Moving to In Progress, and sorry again for the back-and-forth. This info was well hidden on my test hub ;-)

@filipefurtad0 filipefurtad0 removed the pr-staged-fr staging.coopcircuits.fr label Mar 24, 2025
@RachL
Copy link
Contributor

RachL commented Mar 24, 2025

argh yes, I forgot BOM too! So sorry @chahmedejaz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user facing changes Thes pull requests affect the user experience
Projects
Status: In Progress ⚙
Development

Successfully merging this pull request may close these issues.

Allow producer to edit their products on hubs' orders
6 participants