Skip to content

Commit

Permalink
#671 Allow deleting of draft training tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
iccowan committed Oct 26, 2024
1 parent 116043e commit 23cb5dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/Http/Controllers/TrainingDash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}

Expand Down
3 changes: 3 additions & 0 deletions resources/views/dashboard/training/edit_ticket.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
<p id="autosaveIndicator" class="font-italic">Last autosaved at: Not yet saved</p>
<button class="btn btn-primary" type="submit" name="action" value="draft">Save as Draft</button>
<button class="btn btn-success" type="submit" name="action" value="new">Finalize Ticket</button>
@if(Auth::id() == $ticket->trainer_id || Auth::user()->isAbleTo('snrStaff'))
<a class="btn btn-danger" href="/dashboard/training/tickets/delete/{{ $ticket->id }}">Delete Ticket</a>
@endif
@else
<button class="btn btn-success" type="submit" name="action" value="save">Update Ticket</button>
@endif
Expand Down

0 comments on commit 23cb5dd

Please sign in to comment.