Handle multiple projects on tickets
This commit is contained in:
parent
8f753cb349
commit
81ac71b9a9
4 changed files with 34 additions and 6 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Enums\TicketStatus;
|
||||
use App\Enums\TicketType;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
|
@ -15,6 +16,11 @@ class StoreTicket extends FormRequest
|
|||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (!auth()->user()->role->equals(Role::admin())) {
|
||||
$this->merge([
|
||||
'status' => TicketStatus::new()->value,
|
||||
]);
|
||||
}
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +32,18 @@ class StoreTicket extends FormRequest
|
|||
public function rules()
|
||||
{
|
||||
return [
|
||||
'project_id' => 'required|exists:projects,id',
|
||||
'project_id' => [
|
||||
'required',
|
||||
'exists:projects,id',
|
||||
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
function ($attribute, $value, $fail) {
|
||||
if (!in_array($value, auth()->user()->projects()->pluck('id')->all())) {
|
||||
$fail(__('Veuillez choisir entre :values', [
|
||||
'value' => auth()->user()->projects()->pluck('name')->implode(',')
|
||||
]));
|
||||
}
|
||||
}
|
||||
],
|
||||
'type' => [
|
||||
'required',
|
||||
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
|
|
|
|||
|
|
@ -9,6 +9,12 @@ class UpdateTicket extends StoreTicket
|
|||
{
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->check() and (auth()->user()->role->equals(Role::admin()));
|
||||
if (!auth()->user()->role->equals(Role::admin())) {
|
||||
$this->merge([
|
||||
'status' => $this->project->status->value,
|
||||
]);
|
||||
}
|
||||
return auth()->check() and (auth()->user()->role->equals(Role::admin()) or
|
||||
request()->route()->ticket->created_by === auth()->user()->id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
@include('modules.error-messages')
|
||||
@php
|
||||
$userPr = Auth::user()->projects;
|
||||
@endphp
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
<label for="project" class="col-form-label">{{ __('Projet') }}</label>
|
||||
<select class="form-select" name="project_id" id="project">
|
||||
@foreach($projects as $project)
|
||||
<option value="{{ $project->id }}" @if ($project->id == old('project_id') or (isset($ticket) and $ticket->project->id === $project->id))selected @endif>{{ $project->name }}</option>
|
||||
@if (Auth::user()->role->equals(Role::admin()))
|
||||
<option value="{{ $project->id }}" @if ($project->id == old('project_id') or (isset($ticket) and $ticket->project->id == $project->id))selected @endif>{{ $project->name }}</option>
|
||||
@elseif ($userPr->filter(function($pr) use($project) { return $pr->id === $project->id; })->count())
|
||||
<option value="{{ $project->id }}" selected>{{ $project->name }}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -16,16 +16,14 @@
|
|||
@endif
|
||||
<a href="{{ route('ticket.index', ['rst' => 1]) }}" class="btn btn-dark">{{ __('Réinitialiser le tri') }}</a>
|
||||
</div>
|
||||
@if(auth()->user()->role->equals(Role::admin()))
|
||||
<div class="float-end me-2">
|
||||
<select class="form-select" onchange="window.location='{{ route('ticket.index') }}?'+(this.value == -1 ? 'prs=-1' : 'pr='+this.value);">
|
||||
<option value="-1">{{ __('Tous') }}</option>
|
||||
@foreach($projects as $project)
|
||||
@foreach(auth()->user()->projects as $project)
|
||||
<option value="{{$project->id}}" @if(intval(session('tickets.pr')) == $project->id)selected="selected" @endif>{{$project->name}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue