Add action reopen ticket
This commit is contained in:
parent
e8d3335cce
commit
19393ce307
5 changed files with 32 additions and 1 deletions
|
|
@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Enums\TicketStatus;
|
||||
use App\Enums\TicketType;
|
||||
use App\Events\NotifySubscriptions;
|
||||
use App\Events\TicketStatusChanged;
|
||||
use App\Http\Requests\ChangeTicketStatus;
|
||||
use App\Http\Requests\CreateMessage;
|
||||
use App\Http\Requests\SortTickets;
|
||||
|
|
@ -271,4 +273,16 @@ class TicketController extends Controller
|
|||
User::find(Auth::user()->id)->subscriptions()->toggle($ticket->id);
|
||||
return back();
|
||||
}
|
||||
|
||||
public function reopen(Ticket $ticket)
|
||||
{
|
||||
$message = "{$ticket->user->name} à réouvert le ticket n°{$ticket->id}";
|
||||
$oldStatus = $ticket->status;
|
||||
$ticket->status = TicketStatus::inprogress();
|
||||
$ticket->saveQuietly();
|
||||
event(new TicketStatusChanged($ticket, $oldStatus, null, $message));
|
||||
event(new NotifySubscriptions($ticket, $message, collect($ticket->user)));
|
||||
User::find(Auth::user()->id)->subscriptions()->toggle($ticket->id);
|
||||
return back()->with('warning', trans('Votre ticket à été réouvert.'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ abstract class UserRoleRules extends StaticRules
|
|||
return $user->role->equals(Role::developper());
|
||||
}
|
||||
|
||||
protected static function userIsClient(User $user)
|
||||
{
|
||||
return $user->role->equals(Role::client());
|
||||
}
|
||||
|
||||
protected static function allowEveryOne()
|
||||
{
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ class TicketPolicy extends RootPolicy
|
|||
SSR::make('userSitesHasTicket', $user, $model)
|
||||
]),
|
||||
'suscribeToTicket' => TicketStaticRules::make('ticketIsNotArchived', $model),
|
||||
'createMessage' => TicketStaticRules::make('ticketIsNotArchived', $model)
|
||||
'createMessage' => TicketStaticRules::make('ticketIsNotArchived', $model),
|
||||
'reopen' => URR::make('userIsClient', $user)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@
|
|||
</select>
|
||||
</form>
|
||||
@endcan
|
||||
@if($ticket->status->equals(TicketStatus::archived()))
|
||||
@can('reopen', $ticket)
|
||||
<form action="{{ route('ticket.reopen', $ticket) }}" method="POST" id="form_status" class="col">
|
||||
@csrf
|
||||
<button class="btn btn-danger" type="submit">{{ __('Réouvrir le ticket') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
|
|
|
|||
|
|
@ -57,6 +57,9 @@ Route::middleware(['auth'])->group(function () {
|
|||
Route::resource('sites.files', FileController::class);
|
||||
|
||||
Route::prefix('/ticket')->name('ticket.')->group(function () {
|
||||
Route::post('/{ticket}/reopen', [TicketController::class, 'reopen'])
|
||||
->middleware('can:reopen,ticket')
|
||||
->name('reopen');
|
||||
Route::post('/{ticket}/status', [TicketController::class, 'changeStatus'])
|
||||
->middleware('can:changeStatus,ticket')
|
||||
->name('changeStatus');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue