-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
base: master
Are you sure you want to change the base?
Allow producer to edit their products on hubs' orders #13113
Conversation
764ea78
to
ae86821
Compare
2e12ce7
to
a747c88
Compare
d9f0454
to
e4ef890
Compare
|
||
# 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) |
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.
Adding the same user method names here for the sake of writing ability specs to better show the assigned abilities
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.
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.
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 |
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.
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) } |
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 might as well improve the spec here by using instance_double
instead 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/
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.
Sure, will look into this improvement. 👍🏻
Thanks @rioug for the feedback. Let me incorporate and get back to you. |
206acdd
to
361e7da
Compare
5858014
to
53ec662
Compare
Ferrum::BrowserError: Argument should belong to the same JavaScript world as target object
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 |
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.
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) |
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 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.
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's addressed here: 8c73f36
…aptured in the scoper queries
- 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]
Hi @dacook - I've addressed your comments, please review. Thanks |
Yes, I can understand it's confusing a bit 😓 sorry for that. 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.
89cf454
to
b3877be
Compare
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.
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?
Sounds good, @dacook. Moving this to test ready. Thanks. |
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 adding all the specs !
end | ||
|
||
|
||
def expect_product_change(product, action, expected_qty = 0) |
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.
Nice one 👍 It makes the specs so much easier to understand
Hey @chahmedejaz , Nice, this is quite a chunk of work 💪 Going through different scenarios:
2.a) Before enabling this option, as the producer, visiting 2.b) after enabling this option, the URLs 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. 🟢 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). 🟢 v) check BOM is pre-filtered if only one producer available 🟢 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. |
Thanks @filipefurtad0 for detailed feedback, it's now fixed. @openfoodfoundation/reviewers it's fixed here: e605229 |
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.
👍
Hey @chahmedejaz, Thanks for hiding the order shipping option, for the producer, on the orders page 🟢 Apologies, but I have forgotten that we have optional columns on the Bulk Order Management page, for Also, optional to display, is the customers' 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 ;-) |
argh yes, I forgot BOM too! So sorry @chahmedejaz |
What? Why?
What should we test?
Release notes
Changelog Category (reviewers may add a label for the release notes):