Move all authenticated organiser-facing event sub-resource routes from
/events/{event}/... to /organisations/{organisation}/events/{event}/...
to enforce multi-tenancy at the routing layer.
Changes:
- Routes: restructured api.php to nest all event sub-resources under
the existing organisation prefix group
- Controllers: added Organisation parameter and VerifiesOrganisationEvent
trait to all 12 affected controllers (sections, time-slots, shifts,
persons, crowd-lists, locations, shift-assignments, registration-fields,
availabilities, field-values, section-preferences, stats)
- Tests: updated all 20 feature test files with new route paths
- Frontend: updated 8 API composables and 20 Vue components/pages
- API.md: updated documentation to reflect new route structure
Portal routes, public routes (volunteer-register), and invitation routes
remain unchanged as they operate without organisation context.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
102 lines
4.0 KiB
PHP
102 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Enums\ShiftAssignmentStatus;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Api\V1\Traits\VerifiesOrganisationEvent;
|
|
use App\Http\Requests\Api\V1\AssignShiftRequest;
|
|
use App\Http\Requests\Api\V1\StoreShiftRequest;
|
|
use App\Http\Requests\Api\V1\UpdateShiftRequest;
|
|
use App\Http\Resources\Api\V1\ShiftAssignmentResource;
|
|
use App\Http\Resources\Api\V1\ShiftResource;
|
|
use App\Models\Event;
|
|
use App\Models\FestivalSection;
|
|
use App\Models\Organisation;
|
|
use App\Models\Person;
|
|
use App\Models\Shift;
|
|
use App\Services\ShiftAssignmentService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
final class ShiftController extends Controller
|
|
{
|
|
use VerifiesOrganisationEvent;
|
|
|
|
public function __construct(
|
|
private readonly ShiftAssignmentService $shiftAssignmentService,
|
|
) {}
|
|
|
|
public function index(Organisation $organisation, Event $event, FestivalSection $section): AnonymousResourceCollection
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('viewAny', [Shift::class, $event]);
|
|
|
|
$shifts = $section->shifts()
|
|
->with(['timeSlot', 'location'])
|
|
->withCount(['shiftAssignments as filled_slots' => fn ($q) => $q->where('status', ShiftAssignmentStatus::APPROVED)])
|
|
->get();
|
|
|
|
return ShiftResource::collection($shifts);
|
|
}
|
|
|
|
public function store(StoreShiftRequest $request, Organisation $organisation, Event $event, FestivalSection $section): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('create', [Shift::class, $event]);
|
|
|
|
$shift = $section->shifts()->create($request->validated());
|
|
$shift->load(['timeSlot', 'location']);
|
|
|
|
return $this->created(new ShiftResource($shift));
|
|
}
|
|
|
|
public function update(UpdateShiftRequest $request, Organisation $organisation, Event $event, FestivalSection $section, Shift $shift): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('update', [$shift, $event, $section]);
|
|
|
|
$shift->update($request->validated());
|
|
$shift->load(['timeSlot', 'location']);
|
|
|
|
return $this->success(new ShiftResource($shift->fresh()->load(['timeSlot', 'location'])));
|
|
}
|
|
|
|
public function destroy(Organisation $organisation, Event $event, FestivalSection $section, Shift $shift): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('delete', [$shift, $event, $section]);
|
|
|
|
$shift->delete();
|
|
|
|
return response()->json(null, 204);
|
|
}
|
|
|
|
public function assign(AssignShiftRequest $request, Organisation $organisation, Event $event, FestivalSection $section, Shift $shift): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('assign', [$shift, $event, $section]);
|
|
|
|
$festivalEventId = $event->parent_event_id ?? $event->id;
|
|
$person = Person::where('event_id', $festivalEventId)->findOrFail($request->validated('person_id'));
|
|
$assignment = $this->shiftAssignmentService->assign($shift, $person, $request->user());
|
|
|
|
return $this->created(new ShiftAssignmentResource($assignment));
|
|
}
|
|
|
|
public function claim(AssignShiftRequest $request, Organisation $organisation, Event $event, FestivalSection $section, Shift $shift): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('claim', [$shift, $event, $section]);
|
|
|
|
$festivalEventId = $event->parent_event_id ?? $event->id;
|
|
$person = Person::where('event_id', $festivalEventId)->findOrFail($request->validated('person_id'));
|
|
$assignment = $this->shiftAssignmentService->claim($shift, $person);
|
|
|
|
return $this->created(new ShiftAssignmentResource($assignment));
|
|
}
|
|
}
|