magento2
magento2 copied to clipboard
B2B Magento_Company Exception "You are not authorized to access this resource."
Preconditions and environment
- Magento enterprise 2.4.5-p4
- extension-b2b: 1.3.4-p4
Steps to reproduce
- Create a company with a customer
- Set option 'Enable Purchase Orders' value to 'Yes'
- Login as customer
- Add product and checkout the order
Expected result
Order is placed successfully
Actual result
401 result on request /rest/.../V1/carts/mine/payment-information Which then redirects to login page which redirects to account page.
Additional information
It found that the result is trigger by the following plugin on vendor/magento/module-company/Plugin/AsyncOrder/Model/PermissionCheckPlugin.php
$customerId = (int)$this->userContext->getCustomer()->getId() ?: 0;
if ($customerId) {
$company = $this->companyManagement->getByCustomerId($customerId);
if ($company !== null && $company->getExtensionAttributes()->getIsPurchaseOrderEnabled()) {
throw new AuthorizationException(__(
'You are not authorized to access this resource.'
));
}
}
It seems to me that the if statement should only throw the exception when purchaseOrder is not authorized?
$customerId = (int)$this->userContext->getCustomer()->getId() ?: 0;
if ($customerId) {
$company = $this->companyManagement->getByCustomerId($customerId);
if ($company !== null && !$company->getExtensionAttributes()->getIsPurchaseOrderEnabled()) {
throw new AuthorizationException(__(
'You are not authorized to access this resource.'
));
}
}
Release note
No response
Triage and priority
- [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Hi @iwanzijderveld. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
-
@magento give me 2.4-develop instance
- upcoming 2.4.x release - For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this
- To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
- [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
- [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
- [ ] 3. Add
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-develop
branchDetails
- Add the comment@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! - [ ] 5. Add label
Issue: Confirmed
once verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hi @iwanzijderveld,
Thank you for reporting and collaboration.
Verified the issue on Magento 2.4-develop instance with EE edition and the issue is not reproducible.
Steps to reproduce
- Create a company with a customer
- Set option 'Enable Purchase Orders' value to 'Yes'
- Login as customer
- Add product and checkout the order
We are able to place the order successfully.
Kindly recheck the issue in Latest Magento 2.4-develop instance with EE edition and elaborate the steps to reproduce if the issue is still reproducible.
Thanks.
Hi @engcom-Bravo,
I assume the magento/extension-b2b has been installed.
I can still reproduce this issue with the steps below on a fresh installation.
Steps to reproduce
- Create a company under menu item customer -> companies.
- Fill in required values
- Set option 'Enable Purchase Orders' value to 'Yes'
- Login as customer (When creating a company a customer should be created)
- Add product and checkout the order
Hopefully the following video underneath makes it all clear. Screencast from 12-02-24 14:15:35.webm As you can see in the video after clicking 'Place Order' I go to the account page with no order being placed.
Hi @iwanzijderveld
Thank you for reporting and collaboration.
Verified the issue on magneto 2.4 dev b2b instance but the issue is not reproducible.
We are able to place the order successfully.
Please refer the screen recording below.
https://github.com/magento/magento2/assets/60198592/ed5b6fe4-7141-4a6f-af65-4c2f4d647d12
Please check let us know if we missed anything.
Hi @engcom-Dash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
-
- Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
-
- Verify that issue has a meaningful description and provides enough information to reproduce the issue.
-
- Add
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.
- Add
-
- Verify that the issue is reproducible on
2.4-develop
branchDetails
- Add the comment@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
- Verify that the issue is reproducible on
- Join Magento Community Engineering Slack and ask your questions in #github channel.
Hi @engcom-Dash,
Thank you for attaching the screen recording. It appears my instructions were unclear.
So additionally I have to mention that the Setting I'm referring to is not in the shop configuration page. As the description under the setting in your video mentions:
Purchase Order are enabled at the Company level. Turn on 'Enable Purchase Orders' at Customer -> Companies -> Company Name -> Edit -> Advanced Settings for each company that supports Purchase Orders.
So here are the updated steps to reproduce, hope the issue can now be confirmed and solved :smiley:
Steps to reproduce
- Create a company under menu item customer -> companies.
- Fill in required values
- Set option 'Enable Purchase Orders' value to 'Yes' for the company
- Login as customer (When creating a company a customer should be created)
- Add product and checkout the order
Got a patch if anyone suffers from this like I did:
--- a/vendor/magento/module-company/Plugin/AsyncOrder/Model/PermissionCheckPlugin.php
+++ b/vendor/magento/module-company/Plugin/AsyncOrder/Model/PermissionCheckPlugin.php
@@ -66,12 +66,13 @@
$customerId = (int)$this->userContext->getCustomer()->getId() ?: 0;
if ($customerId) {
$company = $this->companyManagement->getByCustomerId($customerId);
- if ($company !== null && $company->getExtensionAttributes()->getIsPurchaseOrderEnabled()) {
+ if ($company !== null && !$company->getExtensionAttributes()->getIsPurchaseOrderEnabled()) {
throw new AuthorizationException(__(
'You are not authorized to access this resource.'
));
}
}
+
return null;
}
}
Is there any update on this ticket yet?
Hi @iwanzijderveld
Thanks for reporting and collaboration.
Verified the issue again in magento 2.4 dev b2b instance but the issue is not reproducable.
Please refer the attached screenrecording
Steps to reproduce:
1.Create a company with a customer 2.Set option 'Enable Purchase Orders' value to 'Yes' 3.Login as customer 4.Add product and checkout the order
We are able to place an order successfully.
Please verify the issue in latest magento instance and let us know if you are still facing the issue.
https://github.com/magento/magento2/assets/60198592/9ff82c5a-28dc-4285-a579-4b70ba41c372
Hi @iwanzijderveld
We have noticed that this issue has not been updated since long time. Hence we assume that this issue is fixed now, so we are closing it. Please feel to raise a fresh ticket or reopen this ticket if you need more assistance on this.
Thanks
Hi @engcom-Dash,
This is still an issue and I don't know what kind of behavior is correct. So this right now works because the setting stores configuration -> general -> b2b features -> order approval configuration -> Enable purchase orders, with path 'btob/website_configuration/purchaseorder_enabled' has been enabled.
When you disable this but leave on the 'enable purhcase orders' option for a specific company. When you do this you go to the regular checkout and not the purchase order checkout.
Hi @iwanzijderveld
Verified the issue on magneto 2.4 b2b instance.
When we disable 'enable purchase orders' option the setting stores configuration -> general -> b2b features -> order approval configuration -> Enable purchase orders and enable 'enable purchase orders' option for a specific company we are still able to place the order successfully.
Please refer the attached screenshots.