3636use Packetery \Order \Tracking ;
3737use Packetery \PacketTracking \PacketStatusFactory ;
3838use Packetery \Tools \ConfigHelper ;
39+ use Packetery \Tools \PermissionHelper ;
3940
4041class 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 }
0 commit comments