From 0f546ac593aa8b78b169f1d7addfe9c44424c66b Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 16 Feb 2018 16:02:16 +0800 Subject: [PATCH] Add assignor locking for job order assigning #7 --- config/routes/job_order.yaml | 6 +- src/Controller/JobOrderController.php | 63 ++++++++- templates/job-order/list.assigning.html.twig | 129 ++++++++++++++++++ templates/job-order/list.processing.html.twig | 125 +++++++++++++++++ 4 files changed, 313 insertions(+), 10 deletions(-) create mode 100644 templates/job-order/list.assigning.html.twig create mode 100644 templates/job-order/list.processing.html.twig diff --git a/config/routes/job_order.yaml b/config/routes/job_order.yaml index b1ac7872..78a6204d 100644 --- a/config/routes/job_order.yaml +++ b/config/routes/job_order.yaml @@ -34,10 +34,8 @@ jo_proc_submit: jo_assign: path: /job-order/assigning - controller: App\Controller\JobOrderController::listRows + controller: App\Controller\JobOrderController::listAssigning methods: [GET] - defaults: - tier: "assign" jo_assign_rows: path: /job-order/assigning-rows @@ -59,4 +57,4 @@ jo_assign_submit: jo_gen_invoice: path: /job-order/generate-invoice controller: App\Controller\JobOrderController::generateInvoice - methods: [POST] \ No newline at end of file + methods: [POST] diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 2254037a..e8394928 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -210,6 +210,13 @@ class JobOrderController extends BaseController ]; } + public function listAssigning() + { + $params = $this->initParameters('jo_assign'); + + return $this->render('job-order/list.assigning.html.twig', $params); + } + public function listRows($tier) { // check which job order tier is being called for and confirm access @@ -300,6 +307,12 @@ class JobOrderController extends BaseController else $row['processor'] = $orow->getProcessedBy()->getFullName(); + $assignor = $orow->getAssignedBy(); + if ($assignor == null) + $row['assignor'] = ''; + else + $row['assignor'] = $orow->getAssignedBy()->getFullName(); + // add crud urls $row['meta']['update_url'] = $this->generateUrl($tier_params['edit_route'], ['id' => $row['id']]); @@ -319,6 +332,7 @@ class JobOrderController extends BaseController $em = $this->getDoctrine()->getManager(); + // manual transaction since we're locking $em->getConnection()->beginTransaction(); try @@ -508,16 +522,53 @@ class JobOrderController extends BaseController { $this->denyAccessUnlessGranted('jo_assign.list', null, 'No access.'); + $em = $this->getDoctrine()->getManager(); + + // manual transaction since we're locking + $em->getConnection()->beginTransaction(); + $params = $this->initParameters('jo_assign'); $params['mode'] = 'update-assigning'; - // get row data - $em = $this->getDoctrine()->getManager(); - $obj = $em->getRepository(JobOrder::class)->find($id); + try + { + // get row data + $obj = $em->getRepository(JobOrder::class)->find($id); - // make sure this row exists - if (empty($obj)) - throw $this->createNotFoundException('The item does not exist'); + // make sure this row exists + if (empty($obj)) + { + $em->getConnection()->rollback(); + throw $this->createNotFoundException('The job order does not exist'); + } + + // check status + if ($obj->getStatus() != JOStatus::RIDER_ASSIGN) + { + $em->getConnection()->rollback(); + throw $this->createNotFoundException('The job order does not have an assigning status'); + } + + // check if we are the assignor + $assignor = $obj->getAssignedBy(); + $user = $this->getUser(); + + 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(); + } + catch (PessimisticLockException $e) + { + throw $this->createAccessDeniedException('Not the assignor'); + } // get parent associations $params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll(); diff --git a/templates/job-order/list.assigning.html.twig b/templates/job-order/list.assigning.html.twig new file mode 100644 index 00000000..e43ebc23 --- /dev/null +++ b/templates/job-order/list.assigning.html.twig @@ -0,0 +1,129 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Job Orders (Assigning) +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/job-order/list.processing.html.twig b/templates/job-order/list.processing.html.twig new file mode 100644 index 00000000..1743be1e --- /dev/null +++ b/templates/job-order/list.processing.html.twig @@ -0,0 +1,125 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Job Orders ({{ tier_name|capitalize }}) +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} -- 2.43.5