- Fix policies and UI for client
This commit is contained in:
parent
f69f19b57c
commit
37b7ed8dab
7 changed files with 23 additions and 32 deletions
|
|
@ -141,7 +141,13 @@ class TicketController extends Controller
|
|||
|
||||
public function create()
|
||||
{
|
||||
$projects = Project::orderBy('name')->get();
|
||||
$user = Auth::user();
|
||||
if ($user->role === 1) {
|
||||
$projects = Project::orderBy('name')->get();
|
||||
} else {
|
||||
$projects = $user->projects;
|
||||
}
|
||||
|
||||
if (!count($projects)) {
|
||||
return redirect()->route('project.create')
|
||||
->with('warning', 'Vous devez tout d\'abord créer un projet pour y ajouter un ticket');
|
||||
|
|
@ -162,6 +168,10 @@ class TicketController extends Controller
|
|||
$ticket->file2 = Ticket::saveFile($project, $ticket, $ticket->type, $request->file_ticket2);
|
||||
}
|
||||
|
||||
if ($request->type === TicketType::evolution()) {
|
||||
$ticket->status = TicketStatus::estimateTodo();
|
||||
}
|
||||
|
||||
$ticket->user()->associate(auth()->user());
|
||||
$ticket->saveOrFail();
|
||||
/** @var \App\Models\User */
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class CreateMessage extends FormRequest
|
|||
'subscribe' => $this->subscribe ? true : false
|
||||
]);
|
||||
return auth()->check() and (auth()->user()->role->equals(Role::admin()) or
|
||||
$this->ticket->project->id === auth()->user()->project_id);
|
||||
auth()->user()->projects->contains(request()->route()->ticket->project_id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,12 +15,6 @@ class StoreTicket extends FormRequest
|
|||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (auth()->user()->project_id) {
|
||||
$this->merge([
|
||||
'project_id' => auth()->user()->project_id,
|
||||
'status' => TicketStatus::new()->value,
|
||||
]);
|
||||
}
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,13 +9,6 @@ class UpdateTicket extends StoreTicket
|
|||
{
|
||||
public function authorize()
|
||||
{
|
||||
if (auth()->user()->project_id) {
|
||||
$this->merge([
|
||||
'project_id' => auth()->user()->project_id,
|
||||
'status' => $this->project->status->value,
|
||||
]);
|
||||
}
|
||||
return auth()->check() and (auth()->user()->role->equals(Role::admin()) or
|
||||
request()->route()->ticket->created_by === auth()->user()->id);
|
||||
return auth()->check() and (auth()->user()->role->equals(Role::admin()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class TicketPolicy
|
|||
*/
|
||||
public function update(User $user, Ticket $ticket)
|
||||
{
|
||||
return Auth::user()->role->equals(Role::admin()) or $ticket->created_by == $user->id;
|
||||
return Auth::user()->role->equals(Role::admin()) or $user->projects->contains($ticket->project_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,7 +85,7 @@ class TicketPolicy
|
|||
*/
|
||||
public function restore(User $user, Ticket $ticket)
|
||||
{
|
||||
return Auth::user()->role->equals(Role::admin()) or $ticket->created_by == $user->id;
|
||||
return Auth::user()->role->equals(Role::admin()) or $user->projects->contains($ticket->project_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -117,14 +117,12 @@ class TicketPolicy
|
|||
{
|
||||
//can create if
|
||||
//role == 1
|
||||
// OR created_by == user->id
|
||||
// OR project_id == user->projetct_id
|
||||
// OR project_id IN user->projects
|
||||
|
||||
if (
|
||||
!(
|
||||
$user->role->equals(Role::admin())
|
||||
or $ticket->created_by === $user->id
|
||||
or $ticket->project_id === $user->project_id)
|
||||
or $user->projects->contains($ticket->project_id) )
|
||||
)
|
||||
{
|
||||
return Response::deny(trans('Vous ne pouvez modifier un ticket qui ne vous appartient pas.'));
|
||||
|
|
|
|||
|
|
@ -1,19 +1,13 @@
|
|||
@include('modules.error-messages')
|
||||
<div class="form-row">
|
||||
@can('changeStatus', App\Model\Ticket::class)
|
||||
<div class="form-group col">
|
||||
<label for="project" class="col-form-label">{{ __('Projet') }}</label>
|
||||
<select class="form-select" name="project_id" id="project" @if (!Auth::user()->role->equals(Role::admin())) disabled @endif>
|
||||
<select class="form-select" name="project_id" id="project">
|
||||
@foreach($projects as $project)
|
||||
@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 ($project->id === Auth::user()->project_id)
|
||||
<option value="{{ $project->id }}" selected>{{ $project->name }}</option>
|
||||
@endif
|
||||
<option value="{{ $project->id }}" @if ($project->id == old('project_id') or (isset($ticket) and $ticket->project->id === $project->id))selected @endif>{{ $project->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@endcan
|
||||
<div class="form-group col">
|
||||
<label for="type" class="col-form-label">{{ __('Type') }}</label>
|
||||
<select class="form-select" name="type" id="type">
|
||||
|
|
@ -31,6 +25,8 @@
|
|||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@else
|
||||
<input type="hidden" name="status" value="{{ \App\Enums\TicketStatus::new() }}" required>
|
||||
@endcan
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -141,9 +141,9 @@
|
|||
</td>
|
||||
<td>
|
||||
<a href="{{ route('ticket.show', $ticket->id) }}" class="btn btn-sm btn-outline-success">{{ __('Messages') }}</a>
|
||||
@can('update', $ticket)
|
||||
@if(auth()->user()->role->equals(Role::admin()))
|
||||
<a href="{{ route('ticket.edit', $ticket) }}" class="btn btn-sm btn-outline-primary">{{ __('Modifier') }}</a>
|
||||
@endcan
|
||||
@endif
|
||||
@can('delete', $ticket)
|
||||
@if(!$ticket->status->equals(TicketStatus::archived()))
|
||||
<form method="POST" action="{{ route('ticket.archive', $ticket) }}">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue