From c1d54ec62686b52190f636681994eafefcb560be Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 30 Apr 2021 08:45:18 +0000 Subject: [PATCH] Add logging when warranty is created via admin panel. #555 --- src/Controller/WarrantyController.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 2208ecb1..494e6524 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -12,8 +12,10 @@ use App\Entity\CustomerVehicle; use App\Ramcar\WarrantyClass; use App\Ramcar\WarrantyStatus; +use App\Ramcar\WarrantySource; use App\Service\WarrantyHandler; +use App\Service\WarrantyAPILogger; use Doctrine\ORM\Query; use Doctrine\ORM\EntityManagerInterface; @@ -149,7 +151,7 @@ class WarrantyController extends Controller return $this->render('warranty/form.html.twig', $params); } - public function addSubmit(Request $req, ValidatorInterface $validator) + public function addSubmit(Request $req, ValidatorInterface $validator, WarrantyAPILogger $logger) { $this->denyAccessUnlessGranted('warranty.add', null, 'No access.'); @@ -255,6 +257,28 @@ class WarrantyController extends Controller $em->persist($obj); $em->flush(); + // log warranty creation + $action = 'create'; + $user_id = $this->getUser()->getUsername(); + $source = WarrantySource::ADMIN_PANEL; + $log_data = [ + 'serial' => $req->request->get('serial'), + 'warranty_class' => $req->request->get('warranty_class'), + 'first_name' => $req->request->get('first_name'), + 'last_name' => $req->request->get('last_name'), + 'mobile_number' => $req->request->get('mobile_number'), + 'date_purchase' => $req->request->get('date_purchase'), + 'claim_from' => $req->request->get('claim_from'), + 'status' => $req->request->get('status'), + 'date_claim' => $req->request->get('date_claim'), + 'date_expire' => $req->request->get('date_expire'), + 'battery_model' => $req->request->get('battery_model'), + 'battery_size' => $req->request->get('battery_size'), + 'sap_battery' => $req->request->get('sap_battery'), + 'plate_number' => $req->request->get('plate_number'), + ]; + $logger->logWarrantyInfo($log_data, '', $user_id, $action, $source); + // return successful response return $this->json([ 'success' => 'Changes have been saved!' @@ -677,4 +701,5 @@ class WarrantyController extends Controller // remove spaces and make upper case return strtoupper(str_replace(' ', '', $plate)); } + }