Skip to content

Commit 64ded3f

Browse files
J7FJ7F
authored andcommitted
PES-2876: permissions update
1 parent f6f0738 commit 64ded3f

File tree

8 files changed

+446
-39
lines changed

8 files changed

+446
-39
lines changed

packetery/controllers/admin/PacketeryCarrierGridController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Packetery\Carrier\CarrierTools;
77
use Packetery\Module\VersionChecker;
88
use Packetery\Tools\MessageManager;
9+
use Packetery\Tools\PermissionHelper;
910

1011
class PacketeryCarrierGridController extends ModuleAdminController
1112
{
@@ -44,6 +45,11 @@ public function __construct()
4445
// for $this->translator not being null, in PS 1.6
4546
parent::__construct();
4647

48+
if (!PermissionHelper::canViewCarriers()) {
49+
$this->errors[] = 'You do not have permission to access Packeta carriers. Access denied.';
50+
return;
51+
}
52+
4753
$module = $this->getModule();
4854

4955
/** @var ApiCarrierRepository $apiCarrierRepository */
@@ -173,6 +179,11 @@ public function initToolbar()
173179
{
174180
parent::initToolbar();
175181
unset($this->toolbar_btn['new']);
182+
183+
// Hide action buttons if user doesn't have edit permissions
184+
if (!PermissionHelper::canEditCarriers()) {
185+
unset($this->toolbar_btn['bulk_action']);
186+
}
176187
}
177188

178189
/**

packetery/controllers/admin/PacketeryLogGridController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Packetery\Log\LogRepository;
4+
use Packetery\Tools\PermissionHelper;
45

56
class PacketeryLogGridController extends ModuleAdminController
67
{
@@ -38,6 +39,11 @@ public function __construct()
3839

3940
parent::__construct();
4041

42+
if (!PermissionHelper::canViewLogs()) {
43+
$this->errors[] = 'You do not have permission to access Packeta logs. Access denied.';
44+
return;
45+
}
46+
4147
$this->logRepository = $this->getModule()->diContainer->get(LogRepository::class);
4248

4349
$this->fields_list = [

packetery/controllers/admin/PacketeryOrderGridController.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Packetery\Order\Tracking;
3737
use Packetery\PacketTracking\PacketStatusFactory;
3838
use Packetery\Tools\ConfigHelper;
39+
use Packetery\Tools\PermissionHelper;
3940

4041
class PacketeryOrderGridController extends ModuleAdminController
4142
{
@@ -109,6 +110,11 @@ public function __construct()
109110
// for $this->translator not being null, in PS 1.6
110111
parent::__construct();
111112

113+
if (!PermissionHelper::canViewOrders()) {
114+
$this->errors[] = 'You do not have permission to access Packeta orders. Access denied.';
115+
return;
116+
}
117+
112118
$this->fields_list = [
113119
'id_order' => [
114120
'title' => $this->l('ID', 'packeteryordergridcontroller'),
@@ -234,6 +240,11 @@ private function createPackets(array $ids)
234240

235241
public function processBulkCreatePacket()
236242
{
243+
if (!PermissionHelper::canEditOrders()) {
244+
$this->errors[] = 'You do not have permission to submit shipment.';
245+
return;
246+
}
247+
237248
$ids = $this->boxes;
238249
if (!$ids) {
239250
$this->informations = $this->l('No orders were selected.', 'packeteryordergridcontroller');
@@ -244,6 +255,11 @@ public function processBulkCreatePacket()
244255

245256
public function processSubmit()
246257
{
258+
if (!PermissionHelper::canEditOrders()) {
259+
$this->errors[] = 'You do not have permission to submit shipment.';
260+
return;
261+
}
262+
247263
$this->createPackets([Tools::getValue('id_order')]);
248264
}
249265

@@ -339,6 +355,11 @@ private function prepareLabels(array $packetNumbers, $type, $packetsEnhanced = n
339355
*/
340356
public function processBulkLabelPdf()
341357
{
358+
if (!PermissionHelper::canEditOrders()) {
359+
$this->errors[] = 'You do not have permission to print labels.';
360+
return;
361+
}
362+
342363
if (Tools::isSubmit('submitPrepareLabels')) {
343364
$packetNumbers = $this->prepareOnlyInternalPacketNumbers($this->boxes);
344365
if ($packetNumbers) {
@@ -358,6 +379,11 @@ public function processBulkLabelPdf()
358379
*/
359380
public function processBulkCarrierLabelPdf()
360381
{
382+
if (!PermissionHelper::canEditOrders()) {
383+
$this->errors[] = 'You do not have permission to print carrier labels.';
384+
return;
385+
}
386+
361387
if (Tools::isSubmit('submitPrepareLabels')) {
362388
$packetNumbers = $this->prepareOnlyCarrierPacketNumbers($this->boxes);
363389
if ($packetNumbers) {
@@ -384,6 +410,11 @@ public function processBulkCarrierLabelPdf()
384410
*/
385411
public function processPrint()
386412
{
413+
if (!PermissionHelper::canEditOrders()) {
414+
$this->errors[] = 'You do not have permission to print label.';
415+
return;
416+
}
417+
387418
/** @var OrderRepository $orderRepo */
388419
$orderRepository = $this->getModule()->diContainer->get(OrderRepository::class);
389420
$orderData = $orderRepository->getById((int)Tools::getValue('id_order'));
@@ -410,6 +441,11 @@ public function processPrint()
410441

411442
public function processBulkCsvExport()
412443
{
444+
if (!PermissionHelper::canViewOrders()) {
445+
$this->errors[] = 'You do not have permission to access Packeta orders. Access denied.';
446+
return;
447+
}
448+
413449
if ((int)Tools::getValue('submitFilterorders') === 1) {
414450
return;
415451
}
@@ -511,6 +547,11 @@ public function postProcess()
511547
$orderRepo = $this->getModule()->diContainer->get(OrderRepository::class);
512548
foreach ($_POST as $key => $value) {
513549
if (preg_match('/^weight_(\d+)$/', $key, $matches)) {
550+
if (!PermissionHelper::canEditOrders()) {
551+
$this->errors[] = 'You do not have permission to modify weight.';
552+
continue;
553+
}
554+
514555
$orderId = (int)$matches[1];
515556
if ($value === '') {
516557
$value = null;
@@ -623,7 +664,10 @@ public function getWeightEditable($weight, array $row)
623664
$smarty = new Smarty();
624665
$smarty->assign('weight', $weight);
625666
$smarty->assign('orderId', $row['id_order']);
626-
$smarty->assign('disabled', $row['tracking_number']);
667+
668+
// Disable weight editing if user doesn't have edit permissions or if order has tracking number
669+
$disabled = !PermissionHelper::canEditOrders() || $row['tracking_number'];
670+
$smarty->assign('disabled', $disabled);
627671

628672
return $smarty->fetch(__DIR__ . '/../../views/templates/admin/grid/weightEditable.tpl');
629673
}

packetery/controllers/admin/PacketerySettingController.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
<?php
22

3+
use Packetery\Tools\PermissionHelper;
4+
35
class PacketerySettingController extends ModuleAdminController
46
{
7+
public function __construct()
8+
{
9+
$this->bootstrap = true;
10+
$this->context = Context::getContext();
11+
12+
parent::__construct();
13+
}
14+
515
public function initContent()
616
{
17+
if (!PermissionHelper::canViewConfig()) {
18+
$this->errors[] = 'You do not have permission to configure the Packeta module. Access denied.';
19+
return;
20+
}
21+
722
Tools::redirectAdmin(
823
$this->module->getAdminLink('AdminModules', ['configure' => $this->module->name, 'tab_module' => $this->module->tab, 'module_name' => $this->module->name])
924
);

packetery/libs/AbstractFormService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Packetery\Exceptions\FormDataPersistException;
1212
use Packetery\Module\Options;
1313
use Packetery\Tools\ConfigHelper;
14+
use Packetery\Tools\PermissionHelper;
1415
use Packetery\Tools\Tools;
1516

1617
abstract class AbstractFormService
@@ -28,6 +29,10 @@ public function __construct(Options $options)
2829
*/
2930
public function handleSubmit()
3031
{
32+
if (!PermissionHelper::canEditConfig()) {
33+
throw new FormDataPersistException('You do not have permission to save configuration.');
34+
}
35+
3136
$formFields = $this->getConfigurationFormFields();
3237
foreach ($formFields as $fieldName => $fieldConfig) {
3338
$this->handleConfigOption($fieldName, $fieldConfig);

0 commit comments

Comments
 (0)