@@ -160,7 +160,7 @@ public function ticketadd(Request $request)
160160
161161 $ customerEmail = $ params ['email ' ] = $ request ->request ->get ('from ' );
162162 $ customer = $ em ->getRepository ('UVDeskCoreFrameworkBundle:User ' )->findOneBy (array ('email ' => $ customerEmail ));
163- $ params ['flag ' ] = (!$ customer ) ? 1 : 0 ;$ request -> getSession ()-> getFlashBag ()-> set ( ' success ' , $ this -> translator -> trans ( ' Success ! Ticket has been created successfully. ' ));
163+ $ params ['flag ' ] = (!$ customer ) ? 1 : 0 ;
164164
165165 $ data ['firstName ' ] = current ($ nameDetails = explode (' ' , $ request ->request ->get ('name ' )));
166166 $ data ['fullname ' ] = $ request ->request ->get ('name ' );
@@ -197,7 +197,7 @@ public function ticketadd(Request $request)
197197 if ($ request ->request ->get ('customFields ' ) || $ request ->files ->get ('customFields ' )) {
198198 $ this ->get ('ticket.service ' )->addTicketCustomFields ($ ticket , $ request ->request ->get ('customFields ' ), $ request ->files ->get ('customFields ' ));
199199 }
200- $ request -> getSession ()-> getFlashBag ()-> set ( 'success ' , sprintf ('Success ! Ticket #%s has been created successfully. ' , $ ticket -> getId () ));
200+ $ this -> addFlash ( 'success ' , $ this -> translator -> trans ('Success ! Ticket has been created successfully. ' ));
201201 } else {
202202 $ this ->addFlash ('warning ' , $ this ->translator ->trans ('Warning ! Can not create ticket, invalid details. ' ));
203203 }
@@ -275,6 +275,14 @@ public function saveReply(int $id, Request $request)
275275 $ this ->isWebsiteActive ();
276276 $ data = $ request ->request ->all ();
277277 $ ticket = $ this ->getDoctrine ()->getRepository ('UVDeskCoreFrameworkBundle:Ticket ' )->find ($ id );
278+ $ user = $ this ->userService ->getSessionUser ();
279+
280+ // process only if access for the resource.
281+ if (empty ($ ticket ) || ( (!empty ($ user )) && $ user ->getId () != $ ticket ->getCustomer ()->getId ()) ) {
282+ if (!$ this ->isCollaborator ($ ticket , $ user )) {
283+ throw new \Exception ('Access Denied ' , 403 );
284+ }
285+ }
278286
279287 if ($ _POST ) {
280288 if (str_replace (' ' ,'' ,str_replace (' ' ,'' ,trim (strip_tags ($ data ['message ' ], '<img> ' )))) != "" ) {
@@ -293,7 +301,7 @@ public function saveReply(int $id, Request $request)
293301 }
294302
295303 // @TODO: Refactor -> Why are we filtering only these two characters?
296- $ data ['message ' ] = str_replace (['<script> ' , '</script> ' ], '' , $ data ['message ' ]);
304+ $ data ['message ' ] = str_replace (['<script> ' , '</script> ' ], '' , htmlspecialchars ( $ data ['message ' ]) );
297305
298306 $ userDetail = $ this ->userService ->getCustomerPartialDetailById ($ data ['user ' ]->getId ());
299307 $ data ['fullname ' ] = $ userDetail ['name ' ];
@@ -318,10 +326,12 @@ public function saveReply(int $id, Request $request)
318326 if ($ thread ->getcreatedBy () == 'customer ' ) {
319327 $ event = new GenericEvent (CoreWorkflowEvents \Ticket \CustomerReply::getId (), [
320328 'entity ' => $ ticket ,
329+ 'thread ' => $ thread
321330 ]);
322331 } else {
323332 $ event = new GenericEvent (CoreWorkflowEvents \Ticket \CollaboratorReply::getId (), [
324333 'entity ' => $ ticket ,
334+ 'thread ' => $ thread
325335 ]);
326336 }
327337
@@ -504,6 +514,16 @@ public function downloadAttachmentZip(Request $request)
504514 $ this ->noResultFound ();
505515 }
506516
517+ $ ticket = $ attachment ->getThread ()->getTicket ();
518+ $ user = $ this ->userService ->getSessionUser ();
519+
520+ // process only if access for the resource.
521+ if (empty ($ ticket ) || ( (!empty ($ user )) && $ user ->getId () != $ ticket ->getCustomer ()->getId ()) ) {
522+ if (!$ this ->isCollaborator ($ ticket , $ user )) {
523+ throw new \Exception ('Access Denied ' , 403 );
524+ }
525+ }
526+
507527 $ zipname = 'attachments/ ' .$ threadId .'.zip ' ;
508528 $ zip = new \ZipArchive ;
509529
@@ -535,6 +555,12 @@ public function downloadAttachment(Request $request)
535555 $ this ->noResultFound ();
536556 }
537557
558+ $ ticket = $ attachment ->getThread ()->getTicket ();
559+ // Proceed only if user has access to the resource
560+ if (false == $ this ->ticketService ->isTicketAccessGranted ($ ticket , $ user )) {
561+ throw new \Exception ('Access Denied ' , 403 );
562+ }
563+
538564 $ path = $ this ->get ('kernel ' )->getProjectDir () . "/public/ " . $ attachment ->getPath ();
539565
540566 $ response = new Response ();
@@ -555,6 +581,14 @@ public function ticketCollaboratorXhr(Request $request)
555581 $ content = json_decode ($ request ->getContent (), true );
556582 $ em = $ this ->getDoctrine ()->getManager ();
557583 $ ticket = $ em ->getRepository ('UVDeskCoreFrameworkBundle:Ticket ' )->find ($ content ['ticketId ' ]);
584+ $ user = $ this ->userService ->getSessionUser ();
585+
586+ // process only if access for the resource.
587+ if (empty ($ ticket ) || ( (!empty ($ user )) && $ user ->getId () != $ ticket ->getCustomer ()->getId ()) ) {
588+ if (!$ this ->isCollaborator ($ ticket , $ user )) {
589+ throw new \Exception ('Access Denied ' , 403 );
590+ }
591+ }
558592
559593 if ($ request ->getMethod () == "POST " ) {
560594 if ($ content ['email ' ] == $ ticket ->getCustomer ()->getEmail ()) {
@@ -580,7 +614,6 @@ public function ticketCollaboratorXhr(Request $request)
580614 $ ticket ->lastCollaborator = $ collaborator ;
581615 $ collaborator = $ em ->getRepository ('UVDeskCoreFrameworkBundle:User ' )->find ($ collaborator ->getId ());
582616
583-
584617 $ json ['collaborator ' ] = $ this ->userService ->getCustomerPartialDetailById ($ collaborator ->getId ());
585618 $ json ['alertClass ' ] = 'success ' ;
586619 $ json ['alertMessage ' ] = $ this ->translator ->trans ('Success ! Collaborator added successfully. ' );
@@ -609,4 +642,4 @@ public function ticketCollaboratorXhr(Request $request)
609642 $ response ->headers ->set ('Content-Type ' , 'application/json ' );
610643 return $ response ;
611644 }
612- }
645+ }
0 commit comments