Skip to content

Commit 431d1bb

Browse files
ENGCOM-8351: Fixed Issue #14633 Sub-admin role related issue in order view page in magento 2 admin #30001
- Merge Pull Request #30001 from hws47a/magento2:2.4-develop-issue-14633 - Merged commits: 1. 96bef4c 2. e845244 3. 27ae51e 4. 963ff74 5. 6fa9f6b 6. 9db8711 7. 1a908c1 8. 85f4b81
2 parents d4f3adf + 85f4b81 commit 431d1bb

File tree

4 files changed

+193
-31
lines changed

4 files changed

+193
-31
lines changed

app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/Creditmemos.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,67 @@
55
*/
66
namespace Magento\Sales\Block\Adminhtml\Order\View\Tab;
77

8+
use Magento\Backend\Block\Widget\Tab\TabInterface;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\AuthorizationInterface;
11+
use Magento\Framework\View\Element\Context;
12+
use Magento\Framework\View\Element\Text\ListText;
13+
814
/**
915
* Order Credit Memos grid
1016
*
1117
* @api
1218
* @since 100.0.2
1319
*/
14-
class Creditmemos extends \Magento\Framework\View\Element\Text\ListText implements
15-
\Magento\Backend\Block\Widget\Tab\TabInterface
20+
class Creditmemos extends ListText implements TabInterface
1621
{
1722
/**
18-
* {@inheritdoc}
23+
* @var AuthorizationInterface
24+
*/
25+
private $authorization;
26+
27+
/**
28+
* Creditmemos constructor.
29+
*
30+
* @param Context $context
31+
* @param array $data
32+
* @param AuthorizationInterface|null $authorization
33+
*/
34+
public function __construct(
35+
Context $context,
36+
array $data = [],
37+
?AuthorizationInterface $authorization = null
38+
) {
39+
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
40+
parent::__construct($context, $data);
41+
}
42+
43+
/**
44+
* @inheritdoc
1945
*/
2046
public function getTabLabel()
2147
{
2248
return __('Credit Memos');
2349
}
2450

2551
/**
26-
* {@inheritdoc}
52+
* @inheritdoc
2753
*/
2854
public function getTabTitle()
2955
{
3056
return __('Order Credit Memos');
3157
}
3258

3359
/**
34-
* {@inheritdoc}
60+
* @inheritdoc
3561
*/
3662
public function canShowTab()
3763
{
38-
return true;
64+
return $this->authorization->isAllowed('Magento_Sales::sales_creditmemo');
3965
}
4066

4167
/**
42-
* {@inheritdoc}
68+
* @inheritdoc
4369
*/
4470
public function isHidden()
4571
{

app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/Invoices.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,67 @@
55
*/
66
namespace Magento\Sales\Block\Adminhtml\Order\View\Tab;
77

8+
use Magento\Backend\Block\Widget\Tab\TabInterface;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\AuthorizationInterface;
11+
use Magento\Framework\View\Element\Context;
12+
use Magento\Framework\View\Element\Text\ListText;
13+
814
/**
915
* Order Invoices grid
1016
*
1117
* @api
1218
* @since 100.0.2
1319
*/
14-
class Invoices extends \Magento\Framework\View\Element\Text\ListText implements
15-
\Magento\Backend\Block\Widget\Tab\TabInterface
20+
class Invoices extends ListText implements TabInterface
1621
{
1722
/**
18-
* {@inheritdoc}
23+
* @var AuthorizationInterface
24+
*/
25+
private $authorization;
26+
27+
/**
28+
* Invoices constructor.
29+
*
30+
* @param Context $context
31+
* @param array $data
32+
* @param AuthorizationInterface|null $authorization
33+
*/
34+
public function __construct(
35+
Context $context,
36+
array $data = [],
37+
?AuthorizationInterface $authorization = null
38+
) {
39+
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
40+
parent::__construct($context, $data);
41+
}
42+
43+
/**
44+
* @inheritdoc
1945
*/
2046
public function getTabLabel()
2147
{
2248
return __('Invoices');
2349
}
2450

2551
/**
26-
* {@inheritdoc}
52+
* @inheritdoc
2753
*/
2854
public function getTabTitle()
2955
{
3056
return __('Order Invoices');
3157
}
3258

3359
/**
34-
* {@inheritdoc}
60+
* @inheritdoc
3561
*/
3662
public function canShowTab()
3763
{
38-
return true;
64+
return $this->authorization->isAllowed('Magento_Sales::sales_invoice');
3965
}
4066

4167
/**
42-
* {@inheritdoc}
68+
* @inheritdoc
4369
*/
4470
public function isHidden()
4571
{

app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/Shipments.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,89 @@
55
*/
66
namespace Magento\Sales\Block\Adminhtml\Order\View\Tab;
77

8+
use Magento\Backend\Block\Widget\Tab\TabInterface;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\AuthorizationInterface;
11+
use Magento\Framework\Registry;
12+
use Magento\Framework\View\Element\Context;
13+
use Magento\Framework\View\Element\Text\ListText;
14+
use Magento\Sales\Model\Order;
15+
816
/**
917
* Order Shipments grid
1018
*
1119
* @api
1220
* @since 100.0.2
1321
*/
14-
class Shipments extends \Magento\Framework\View\Element\Text\ListText implements
15-
\Magento\Backend\Block\Widget\Tab\TabInterface
22+
class Shipments extends ListText implements TabInterface
1623
{
1724
/**
1825
* Core registry
1926
*
20-
* @var \Magento\Framework\Registry
27+
* @var Registry
2128
*/
2229
protected $_coreRegistry = null;
2330

31+
/**
32+
* @var AuthorizationInterface
33+
*/
34+
private $authorization;
35+
2436
/**
2537
* Collection factory
2638
*
27-
* @param \Magento\Framework\View\Element\Context $context
28-
* @param \Magento\Framework\Registry $coreRegistry
39+
* @param Context $context
40+
* @param Registry $coreRegistry
2941
* @param array $data
42+
* @param AuthorizationInterface|null $authorization
3043
*/
3144
public function __construct(
32-
\Magento\Framework\View\Element\Context $context,
33-
\Magento\Framework\Registry $coreRegistry,
34-
array $data = []
45+
Context $context,
46+
Registry $coreRegistry,
47+
array $data = [],
48+
?AuthorizationInterface $authorization = null
3549
) {
3650
$this->_coreRegistry = $coreRegistry;
51+
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
3752
parent::__construct($context, $data);
3853
}
3954

4055
/**
4156
* Retrieve order model instance
4257
*
43-
* @return \Magento\Sales\Model\Order
58+
* @return Order
4459
*/
4560
public function getOrder()
4661
{
4762
return $this->_coreRegistry->registry('current_order');
4863
}
4964

5065
/**
51-
* {@inheritdoc}
66+
* @inheritdoc
5267
*/
5368
public function getTabLabel()
5469
{
5570
return __('Shipments');
5671
}
5772

5873
/**
59-
* {@inheritdoc}
74+
* @inheritdoc
6075
*/
6176
public function getTabTitle()
6277
{
6378
return __('Order Shipments');
6479
}
6580

6681
/**
67-
* {@inheritdoc}
82+
* @inheritdoc
6883
*/
6984
public function canShowTab()
7085
{
71-
if ($this->getOrder()->getIsVirtual()) {
72-
return false;
73-
}
74-
return true;
86+
return $this->authorization->isAllowed('Magento_Sales::shipment') && !$this->getOrder()->getIsVirtual();
7587
}
7688

7789
/**
78-
* {@inheritdoc}
90+
* @inheritdoc
7991
*/
8092
public function isHidden()
8193
{
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminViewOrderUserWithRestrictedAccessTest">
11+
<annotations>
12+
<stories value="Open order with restricted access"/>
13+
<title value="Admin opens order with restricted access"/>
14+
<description value="Admin opens order with restricted access"/>
15+
<severity value="MAJOR"/>
16+
<group value="Sales"/>
17+
</annotations>
18+
<before>
19+
<createData entity="SimpleProduct2" stepKey="Product"/>
20+
<createData entity="Simple_US_Customer" stepKey="Customer"/>
21+
22+
<!--Create order-->
23+
<createData entity="CustomerCart" stepKey="CustomerCart">
24+
<requiredEntity createDataKey="Customer"/>
25+
</createData>
26+
<createData entity="CustomerCartItem" stepKey="addCartItem">
27+
<requiredEntity createDataKey="CustomerCart"/>
28+
<requiredEntity createDataKey="Product"/>
29+
</createData>
30+
<createData entity="CustomerAddressInformation" stepKey="addCustomerOrderAddress">
31+
<requiredEntity createDataKey="CustomerCart"/>
32+
</createData>
33+
<updateData createDataKey="CustomerCart" entity="CustomerOrderPaymentMethod" stepKey="sendCustomerPaymentInformation">
34+
<requiredEntity createDataKey="CustomerCart"/>
35+
</updateData>
36+
37+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
38+
</before>
39+
<after>
40+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutAsSecondRoleUser"/>
41+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
42+
43+
<actionGroup ref="AdminUserOpenAdminRolesPageActionGroup" stepKey="navigateToUserRoleGrid"/>
44+
<actionGroup ref="AdminDeleteRoleActionGroup" stepKey="deleteUserRole">
45+
<argument name="role" value="adminRole"/>
46+
</actionGroup>
47+
<actionGroup ref="AdminOpenAdminUsersPageActionGroup" stepKey="goToAllUsersPage"/>
48+
<actionGroup ref="AdminDeleteNewUserActionGroup" stepKey="deleteUser">
49+
<argument name="userName" value="{{admin2.username}}"/>
50+
</actionGroup>
51+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
52+
53+
<deleteData createDataKey="Product" stepKey="deleteProduct"/>
54+
<deleteData createDataKey="Customer" stepKey="deleteCustomer"/>
55+
</after>
56+
57+
<!--Create user role-->
58+
<actionGroup ref="AdminFillUserRoleRequiredDataActionGroup" stepKey="fillUserRoleRequiredData">
59+
<argument name="User" value="adminRole"/>
60+
<argument name="restrictedRole" value="Dashboard"/>
61+
</actionGroup>
62+
<actionGroup ref="AdminUserClickRoleResourceTabActionGroup" stepKey="goToRoleResourcesTab"/>
63+
<actionGroup ref="AdminAddRestrictedRoleActionGroup" stepKey="addRestrictedRole">
64+
<argument name="User" value="adminRole"/>
65+
<argument name="restrictedRole" value="Orders"/>
66+
</actionGroup>
67+
<actionGroup ref="AdminRevokeRoleResourceActionGroup" stepKey="revokeInvoiceAccess">
68+
<argument name="resourceName" value="Invoice"/>
69+
</actionGroup>
70+
<actionGroup ref="AdminRevokeRoleResourceActionGroup" stepKey="revokeCreditMemosAccess">
71+
<argument name="resourceName" value="Credit Memos"/>
72+
</actionGroup>
73+
<actionGroup ref="AdminUserSaveRoleActionGroup" stepKey="saveUserRole" />
74+
75+
<!--Create New User-->
76+
<actionGroup ref="AdminCreateUserActionGroup" stepKey="createAdminUser">
77+
<argument name="role" value="adminRole"/>
78+
<argument name="User" value="admin2"/>
79+
</actionGroup>
80+
81+
<!--Login as new User-->
82+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutOfAdmin"/>
83+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsNewUser">
84+
<argument name="username" value="{{admin2.username}}"/>
85+
<argument name="password" value="{{admin2.password}}"/>
86+
</actionGroup>
87+
88+
<!--Open created order-->
89+
<actionGroup ref="SearchAdminDataGridByKeywordActionGroup" stepKey="searchOrderGridByNameKeyword">
90+
<argument name="keyword" value="BillingAddressTX.fullname"/>
91+
</actionGroup>
92+
<actionGroup ref="AdminOrderGridClickFirstRowActionGroup" stepKey="clickOrderRow"/>
93+
94+
<!--Assert that error not appears-->
95+
<wait time="3" stepKey="waitToBeSureErrorWillNotAppears"/>
96+
<dontSeeElement selector="{{AdminConfirmationModalSection.title}}" stepKey="errorMessageShouldNotAppears"/>
97+
</test>
98+
</tests>

0 commit comments

Comments
 (0)