Skip to content

Commit 94a63f7

Browse files
author
Mastiuhin Olexandr
committed
MAGETWO-99591: Restricted admin cannot edit reviews from pending reviews grid
1 parent 35242da commit 94a63f7

File tree

11 files changed

+31
-33
lines changed

11 files changed

+31
-33
lines changed

app/code/Magento/Review/Block/Adminhtml/Edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected function _construct()
186186
) . '\', ' . '\'' . $this->getUrl(
187187
'*/*/delete',
188188
[$this->_objectId => $this->getRequest()->getParam($this->_objectId), 'ret' => 'pending']
189-
) . '\'' . ')'
189+
) . '\', {data: {}})'
190190
);
191191
$this->_coreRegistry->register('ret', 'pending');
192192
}

app/code/Magento/Review/Controller/Adminhtml/Product.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
*/
1717
abstract class Product extends Action
1818
{
19+
/**
20+
* Authorization resource
21+
*/
22+
public const ADMIN_RESOURCE = 'Magento_Review::reviews_all';
23+
1924
/**
2025
* Array of actions which can be processed without secret key validation
2126
*
@@ -61,12 +66,4 @@ public function __construct(
6166
$this->ratingFactory = $ratingFactory;
6267
parent::__construct($context);
6368
}
64-
65-
/**
66-
* @inheritdoc
67-
*/
68-
protected function _isAllowed()
69-
{
70-
return $this->_authorization->isAllowed('Magento_Review::reviews_all');
71-
}
7269
}

app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
use Magento\Review\Controller\Adminhtml\Product as ProductController;
1010
use Magento\Framework\Controller\ResultFactory;
1111
use Magento\Review\Model\Review;
12-
use Magento\Framework\App\Action\HttpGetActionInterface;
1312

1413
/**
1514
* Delete action.
1615
*/
17-
class Delete extends ProductController implements HttpGetActionInterface, HttpPostActionInterface
16+
class Delete extends ProductController implements HttpPostActionInterface
1817
{
1918
/**
2019
* @var Review
@@ -55,7 +54,7 @@ public function execute()
5554
*/
5655
protected function _isAllowed()
5756
{
58-
if ($this->_authorization->isAllowed('Magento_Review::reviews_all')) {
57+
if (parent::_isAllowed()) {
5958
return true;
6059
}
6160

@@ -81,7 +80,7 @@ protected function _isAllowed()
8180
*/
8281
private function getModel(): Review
8382
{
84-
if (!$this->model) {
83+
if ($this->model === null) {
8584
$this->model = $this->reviewFactory->create()
8685
->load($this->getRequest()->getParam('id', false));
8786
}

app/code/Magento/Review/Controller/Adminhtml/Product/Edit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function execute()
4141
*/
4242
protected function _isAllowed()
4343
{
44-
if ($this->_authorization->isAllowed('Magento_Review::reviews_all')) {
44+
if (parent::_isAllowed()) {
4545
return true;
4646
}
4747

@@ -67,7 +67,7 @@ protected function _isAllowed()
6767
*/
6868
private function getModel(): Review
6969
{
70-
if (!$this->review) {
70+
if ($this->review === null) {
7171
$this->review = $this->reviewFactory->create()
7272
->load($this->getRequest()->getParam('id', false));
7373
}

app/code/Magento/Review/Controller/Adminhtml/Product/MassDelete.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function execute()
8585
*/
8686
protected function _isAllowed()
8787
{
88-
if ($this->_authorization->isAllowed('Magento_Review::reviews_all')) {
88+
if (parent::_isAllowed()) {
8989
return true;
9090
}
9191

@@ -116,7 +116,7 @@ protected function _isAllowed()
116116
*/
117117
private function getCollection(): Collection
118118
{
119-
if (!$this->collection) {
119+
if ($this->collection === null) {
120120
$collection = $this->collectionFactory->create();
121121
$collection->addFieldToFilter(
122122
'main_table.' . $collection->getResource()

app/code/Magento/Review/Controller/Adminhtml/Product/MassUpdateStatus.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ public function execute()
8989
*/
9090
protected function _isAllowed()
9191
{
92-
if (!$this->_authorization->isAllowed('Magento_Review::pending')) {
93-
return false;
92+
if (parent::_isAllowed()) {
93+
return true;
9494
}
9595

96-
if ($this->_authorization->isAllowed('Magento_Review::reviews_all')) {
97-
return true;
96+
if (!$this->_authorization->isAllowed('Magento_Review::pending')) {
97+
return false;
9898
}
9999

100100
foreach ($this->getCollection() as $model) {
101101
if ($model->getStatusId() != Review::STATUS_PENDING) {
102102
$this->messageManager->addErrorMessage(
103103
__(
104-
'Sorry, You have not permission to do this.'
105-
. ' One or more of the reviews are not in Pending Status.'
104+
'Sorry, You have not permission to do this. '
105+
. 'One or more of the reviews are not in Pending Status.'
106106
)
107107
);
108108

@@ -120,7 +120,7 @@ protected function _isAllowed()
120120
*/
121121
private function getCollection(): Collection
122122
{
123-
if (!$this->collection) {
123+
if ($this->collection === null) {
124124
$collection = $this->collectionFactory->create();
125125
$collection->addFieldToFilter(
126126
'main_table.' . $collection->getResource()

app/code/Magento/Review/Controller/Adminhtml/Product/Pending.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
use Magento\Review\Controller\Adminhtml\Product as ProductController;
99
use Magento\Framework\Controller\ResultFactory;
1010
use Magento\Framework\App\Action\HttpGetActionInterface;
11+
use Magento\Framework\App\Action\HttpPostActionInterface;
1112

1213
/**
1314
* Pending reviews grid.
1415
*/
15-
class Pending extends ProductController implements HttpGetActionInterface
16+
class Pending extends ProductController implements HttpGetActionInterface, HttpPostActionInterface
1617
{
1718
/**
1819
* Execute action.

app/code/Magento/Review/Controller/Adminhtml/Product/ReviewGrid.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
use Magento\Framework\Controller\ResultFactory;
1515
use Magento\Framework\App\Request\Http;
1616
use Magento\Framework\App\Action\HttpGetActionInterface;
17+
use Magento\Framework\App\Action\HttpPostActionInterface;
1718

1819
/**
1920
* Review grid.
2021
*/
21-
class ReviewGrid extends ProductController implements HttpGetActionInterface
22+
class ReviewGrid extends ProductController implements HttpGetActionInterface, HttpPostActionInterface
2223
{
2324
/**
2425
* @var \Magento\Framework\View\LayoutFactory

app/code/Magento/Review/Controller/Adminhtml/Product/Save.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ public function execute()
105105
*/
106106
protected function _isAllowed()
107107
{
108-
if (!$this->_authorization->isAllowed('Magento_Review::pending')) {
109-
return false;
108+
if (parent::_isAllowed()) {
109+
return true;
110110
}
111111

112-
if ($this->_authorization->isAllowed('Magento_Review::reviews_all')) {
113-
return true;
112+
if (!$this->_authorization->isAllowed('Magento_Review::pending')) {
113+
return false;
114114
}
115115

116116
if ($this->getModel()->getStatusId() != Review::STATUS_PENDING) {

dev/tests/integration/testsuite/Magento/Review/Controller/Adminhtml/Product/EditTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class EditTest extends AbstractBackendController
4242
private $collectionFactory;
4343

4444
/**
45-
* @inheritDoc
45+
* @inheritdoc
4646
*/
4747
protected function setUp()
4848
{
@@ -84,7 +84,7 @@ public function testAclNoAccess(): void
8484
{
8585
// Exclude resource from ACL.
8686
$this->resource = ['Magento_Review::reviews_all', 'Magento_Review::pending'];
87-
$this->uri = 'backend/review/product/edit/id/' . 'doesnt matter';
87+
$this->uri = 'backend/review/product/edit/id/' . 'doesn\'t matter';
8888

8989
parent::testAclNoAccess();
9090
}

0 commit comments

Comments
 (0)