diff --git a/app/Http/Controllers/TrainingDash.php b/app/Http/Controllers/TrainingDash.php index 0e4457cb..dbd6e42a 100644 --- a/app/Http/Controllers/TrainingDash.php +++ b/app/Http/Controllers/TrainingDash.php @@ -303,19 +303,22 @@ public function editTicket($id) { public function deleteTicket($id) { $ticket = TrainingTicket::find($id); - if (Auth::user()->isAbleTo('snrStaff')) { + $draft = $ticket->draft; + if (Auth::user()->isAbleTo('snrStaff') || (Auth::id() == $ticket->trainer_id && $draft)) { $controller_id = $ticket->controller_id; $ticket->delete(); - $audit = new Audit; - $audit->cid = Auth::id(); - $audit->ip = $_SERVER['REMOTE_ADDR']; - $audit->what = Auth::user()->full_name . ' deleted a training ticket for ' . User::find($controller_id)->full_name . '.'; - $audit->save(); + if (! $draft) { + $audit = new Audit; + $audit->cid = Auth::id(); + $audit->ip = $_SERVER['REMOTE_ADDR']; + $audit->what = Auth::user()->full_name . ' deleted a training ticket for ' . User::find($controller_id)->full_name . '.'; + $audit->save(); + } return redirect('/dashboard/training/tickets?id=' . $controller_id)->with('success', 'The ticket has been deleted successfully.'); } else { - return redirect()->back()->with('error', 'Only the TA can delete training tickets.'); + return redirect()->back()->with('error', 'Only the TA can delete non-draft training tickets.'); } } diff --git a/resources/views/dashboard/training/edit_ticket.blade.php b/resources/views/dashboard/training/edit_ticket.blade.php index 1691f439..ee16c587 100644 --- a/resources/views/dashboard/training/edit_ticket.blade.php +++ b/resources/views/dashboard/training/edit_ticket.blade.php @@ -153,6 +153,9 @@
Last autosaved at: Not yet saved
+ @if(Auth::id() == $ticket->trainer_id || Auth::user()->isAbleTo('snrStaff')) + Delete Ticket + @endif @else @endif