Skip to content

Commit d639e91

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-99591' into 2.3-develop-pr26
2 parents b5c81ad + 951ff65 commit d639e91

File tree

12 files changed

+603
-34
lines changed

12 files changed

+603
-34
lines changed

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Review\Block\Adminhtml;
77

88
/**
9-
* Review edit form
9+
* Review edit form.
1010
*/
1111
class Edit extends \Magento\Backend\Block\Widget\Form\Container
1212
{
@@ -77,7 +77,13 @@ protected function _construct()
7777
'previous',
7878
[
7979
'label' => __('Previous'),
80-
'onclick' => 'setLocation(\'' . $this->getUrl('review/*/*', ['id' => $prevId]) . '\')'
80+
'onclick' => 'setLocation(\'' . $this->getUrl(
81+
'review/*/*',
82+
[
83+
'id' => $prevId,
84+
'ret' => $this->getRequest()->getParam('ret'),
85+
]
86+
) . '\')'
8187
],
8288
3,
8389
10
@@ -93,7 +99,10 @@ protected function _construct()
9399
'button' => [
94100
'event' => 'save',
95101
'target' => '#edit_form',
96-
'eventData' => ['action' => ['args' => ['next_item' => $prevId]]],
102+
'eventData' => ['action' => ['args' => [
103+
'next_item' => $prevId,
104+
'ret' => $this->getRequest()->getParam('ret'),
105+
]]],
97106
],
98107
],
99108
]
@@ -113,7 +122,10 @@ protected function _construct()
113122
'button' => [
114123
'event' => 'save',
115124
'target' => '#edit_form',
116-
'eventData' => ['action' => ['args' => ['next_item' => $nextId]]],
125+
'eventData' => ['action' => ['args' => [
126+
'next_item' => $nextId,
127+
'ret' => $this->getRequest()->getParam('ret'),
128+
]]],
117129
],
118130
],
119131
]
@@ -126,7 +138,13 @@ protected function _construct()
126138
'next',
127139
[
128140
'label' => __('Next'),
129-
'onclick' => 'setLocation(\'' . $this->getUrl('review/*/*', ['id' => $nextId]) . '\')'
141+
'onclick' => 'setLocation(\'' . $this->getUrl(
142+
'review/*/*',
143+
[
144+
'id' => $nextId,
145+
'ret' => $this->getRequest()->getParam('ret'),
146+
]
147+
) . '\')'
130148
],
131149
3,
132150
105
@@ -168,7 +186,7 @@ protected function _construct()
168186
) . '\', ' . '\'' . $this->getUrl(
169187
'*/*/delete',
170188
[$this->_objectId => $this->getRequest()->getParam($this->_objectId), 'ret' => 'pending']
171-
) . '\'' . ')'
189+
) . '\', {data: {}})'
172190
);
173191
$this->_coreRegistry->register('ret', 'pending');
174192
}

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
use Magento\Review\Model\RatingFactory;
1313

1414
/**
15-
* Reviews admin controller
15+
* Reviews admin controller.
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,19 +66,4 @@ public function __construct(
6166
$this->ratingFactory = $ratingFactory;
6267
parent::__construct($context);
6368
}
64-
65-
/**
66-
* @return bool
67-
*/
68-
protected function _isAllowed()
69-
{
70-
switch ($this->getRequest()->getActionName()) {
71-
case 'pending':
72-
return $this->_authorization->isAllowed('Magento_Review::pending');
73-
break;
74-
default:
75-
return $this->_authorization->isAllowed('Magento_Review::reviews_all');
76-
break;
77-
}
78-
}
7969
}

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

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55
*/
66
namespace Magento\Review\Controller\Adminhtml\Product;
77

8+
use Magento\Framework\App\Action\HttpPostActionInterface;
89
use Magento\Review\Controller\Adminhtml\Product as ProductController;
910
use Magento\Framework\Controller\ResultFactory;
11+
use Magento\Review\Model\Review;
1012

11-
class Delete extends ProductController
13+
/**
14+
* Delete action.
15+
*/
16+
class Delete extends ProductController implements HttpPostActionInterface
1217
{
1318
/**
19+
* @var Review
20+
*/
21+
private $model;
22+
23+
/**
24+
* Execute action.
25+
*
1426
* @return \Magento\Backend\Model\View\Result\Redirect
1527
*/
1628
public function execute()
@@ -19,7 +31,7 @@ public function execute()
1931
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
2032
$reviewId = $this->getRequest()->getParam('id', false);
2133
try {
22-
$this->reviewFactory->create()->setId($reviewId)->aggregate()->delete();
34+
$this->getModel()->aggregate()->delete();
2335

2436
$this->messageManager->addSuccess(__('The review has been deleted.'));
2537
if ($this->getRequest()->getParam('ret') == 'pending') {
@@ -36,4 +48,46 @@ public function execute()
3648

3749
return $resultRedirect->setPath('review/*/edit/', ['id' => $reviewId]);
3850
}
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
protected function _isAllowed()
56+
{
57+
if (parent::_isAllowed()) {
58+
return true;
59+
}
60+
61+
if (!$this->_authorization->isAllowed('Magento_Review::pending')) {
62+
return false;
63+
}
64+
65+
if ($this->getModel()->getStatusId() != Review::STATUS_PENDING) {
66+
$this->messageManager->addErrorMessage(
67+
__(
68+
'You don’t have permission to perform this operation.'
69+
. ' The selected review must be in Pending Status.'
70+
)
71+
);
72+
73+
return false;
74+
}
75+
76+
return true;
77+
}
78+
79+
/**
80+
* Returns requested model.
81+
*
82+
* @return Review
83+
*/
84+
private function getModel(): Review
85+
{
86+
if ($this->model === null) {
87+
$this->model = $this->reviewFactory->create()
88+
->load($this->getRequest()->getParam('id', false));
89+
}
90+
91+
return $this->model;
92+
}
3993
}

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@
88
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
99
use Magento\Review\Controller\Adminhtml\Product as ProductController;
1010
use Magento\Framework\Controller\ResultFactory;
11+
use Magento\Review\Model\Review;
1112

13+
/**
14+
* Edit action.
15+
*/
1216
class Edit extends ProductController implements HttpGetActionInterface
1317
{
1418
/**
19+
* @var Review
20+
*/
21+
private $review;
22+
23+
/**
24+
* Execute action.
25+
*
1526
* @return \Magento\Backend\Model\View\Result\Page
1627
*/
1728
public function execute()
@@ -24,4 +35,46 @@ public function execute()
2435
$resultPage->addContent($resultPage->getLayout()->createBlock(\Magento\Review\Block\Adminhtml\Edit::class));
2536
return $resultPage;
2637
}
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
protected function _isAllowed()
43+
{
44+
if (parent::_isAllowed()) {
45+
return true;
46+
}
47+
48+
if (!$this->_authorization->isAllowed('Magento_Review::pending')) {
49+
return false;
50+
}
51+
52+
if ($this->getModel()->getStatusId() != Review::STATUS_PENDING) {
53+
$this->messageManager->addErrorMessage(
54+
__(
55+
'You don’t have permission to perform this operation.'
56+
. ' The selected review must be in Pending Status.'
57+
)
58+
);
59+
60+
return false;
61+
}
62+
63+
return true;
64+
}
65+
66+
/**
67+
* Returns requested model.
68+
*
69+
* @return Review
70+
*/
71+
private function getModel(): Review
72+
{
73+
if ($this->review === null) {
74+
$this->review = $this->reviewFactory->create()
75+
->load($this->getRequest()->getParam('id', false));
76+
}
77+
78+
return $this->review;
79+
}
2780
}

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

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,54 @@
55
*/
66
namespace Magento\Review\Controller\Adminhtml\Product;
77

8+
use Magento\Backend\App\Action\Context;
9+
use Magento\Framework\Registry;
810
use Magento\Review\Controller\Adminhtml\Product as ProductController;
911
use Magento\Framework\Exception\LocalizedException;
1012
use Magento\Framework\Controller\ResultFactory;
13+
use Magento\Review\Model\RatingFactory;
14+
use Magento\Review\Model\Review;
15+
use Magento\Review\Model\ResourceModel\Review\Collection;
16+
use Magento\Review\Model\ResourceModel\Review\CollectionFactory;
17+
use Magento\Review\Model\ReviewFactory;
18+
use Magento\Framework\App\Action\HttpPostActionInterface;
1119

12-
class MassDelete extends ProductController
20+
/**
21+
* Mass Delete action.
22+
*/
23+
class MassDelete extends ProductController implements HttpPostActionInterface
1324
{
1425
/**
26+
* @var Collection
27+
*/
28+
private $collection;
29+
30+
/**
31+
* @var CollectionFactory
32+
*/
33+
private $collectionFactory;
34+
35+
/**
36+
* @param Context $context
37+
* @param Registry $coreRegistry
38+
* @param ReviewFactory $reviewFactory
39+
* @param RatingFactory $ratingFactory
40+
* @param CollectionFactory $collectionFactory
41+
*/
42+
public function __construct(
43+
Context $context,
44+
Registry $coreRegistry,
45+
ReviewFactory $reviewFactory,
46+
RatingFactory $ratingFactory,
47+
CollectionFactory $collectionFactory
48+
) {
49+
parent::__construct($context, $coreRegistry, $reviewFactory, $ratingFactory);
50+
$this->collectionFactory = $collectionFactory;
51+
}
52+
53+
/**
54+
* Execute action.
55+
*
1556
* @return \Magento\Backend\Model\View\Result\Redirect
1657
*/
1758
public function execute()
@@ -21,8 +62,7 @@ public function execute()
2162
$this->messageManager->addError(__('Please select review(s).'));
2263
} else {
2364
try {
24-
foreach ($reviewsIds as $reviewId) {
25-
$model = $this->reviewFactory->create()->load($reviewId);
65+
foreach ($this->getCollection() as $model) {
2666
$model->delete();
2767
}
2868
$this->messageManager->addSuccess(
@@ -39,4 +79,54 @@ public function execute()
3979
$resultRedirect->setPath('review/*/' . $this->getRequest()->getParam('ret', 'index'));
4080
return $resultRedirect;
4181
}
82+
83+
/**
84+
* @inheritdoc
85+
*/
86+
protected function _isAllowed()
87+
{
88+
if (parent::_isAllowed()) {
89+
return true;
90+
}
91+
92+
if (!$this->_authorization->isAllowed('Magento_Review::pending')) {
93+
return false;
94+
}
95+
96+
foreach ($this->getCollection() as $model) {
97+
if ($model->getStatusId() != Review::STATUS_PENDING) {
98+
$this->messageManager->addErrorMessage(
99+
__(
100+
'You don’t have permission to perform this operation.'
101+
. ' Selected reviews must be in Pending Status only.'
102+
)
103+
);
104+
105+
return false;
106+
}
107+
}
108+
109+
return true;
110+
}
111+
112+
/**
113+
* Returns requested collection.
114+
*
115+
* @return Collection
116+
*/
117+
private function getCollection(): Collection
118+
{
119+
if ($this->collection === null) {
120+
$collection = $this->collectionFactory->create();
121+
$collection->addFieldToFilter(
122+
'main_table.' . $collection->getResource()
123+
->getIdFieldName(),
124+
$this->getRequest()->getParam('reviews')
125+
);
126+
127+
$this->collection = $collection;
128+
}
129+
130+
return $this->collection;
131+
}
42132
}

0 commit comments

Comments
 (0)