From b5274be3b51fa6f85a72a3c34ff4b0ef8db1e3c0 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 27 Apr 2018 04:20:47 +0800 Subject: [PATCH] Allow super admin to do rider assignment even when locked to other user #106 --- src/Controller/JobOrderController.php | 42 ++++++++++++++++----------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index af7f134c..ce5ec2c4 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -1024,27 +1024,35 @@ class JobOrderController extends BaseController throw $this->createNotFoundException('The job order does not have an assigning status'); } - // check if hub is assigned to current user - $user_hubs = $this->getUser()->getHubs(); - if (!in_array($obj->getHub()->getID(), $user_hubs)) - { - $em->getConnection()->rollback(); - throw $this->createNotFoundException('The job order is not on a hub assigned to this user'); - } - - // check if we are the assignor - $assignor = $obj->getAssignedBy(); + // check if super user $user = $this->getUser(); - - if ($assignor != null && $assignor->getID() != $user->getID()) + if ($user->isSuperAdmin()) { - $em->getConnection()->rollback(); - throw $this->createAccessDeniedException('Not the assignor'); + // do nothing, just allow page to be accessed } + else + { + // check if hub is assigned to current user + $user_hubs = $this->getUser()->getHubs(); + if (!in_array($obj->getHub()->getID(), $user_hubs)) + { + $em->getConnection()->rollback(); + throw $this->createNotFoundException('The job order is not on a hub assigned to this user'); + } - // make this user be the assignor - $obj->setAssignedBy($user); - $em->flush(); + // check if we are the assignor + $assignor = $obj->getAssignedBy(); + + if ($assignor != null && $assignor->getID() != $user->getID()) + { + $em->getConnection()->rollback(); + throw $this->createAccessDeniedException('Not the assignor'); + } + + // make this user be the assignor + $obj->setAssignedBy($user); + $em->flush(); + } $em->getConnection()->commit(); }