security: A01-13 — nest all event routes under organisation prefix
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>
This commit is contained in:
@@ -7,10 +7,12 @@ namespace App\Http\Controllers\Api\V1;
|
||||
use App\Enums\PersonStatus;
|
||||
use App\Enums\ShiftAssignmentStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Api\V1\Traits\VerifiesOrganisationEvent;
|
||||
use App\Http\Requests\Api\V1\BulkApproveShiftAssignmentRequest;
|
||||
use App\Http\Requests\Api\V1\RejectShiftAssignmentRequest;
|
||||
use App\Http\Resources\Api\V1\ShiftAssignmentResource;
|
||||
use App\Models\Event;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\Person;
|
||||
use App\Models\Shift;
|
||||
use App\Models\ShiftAssignment;
|
||||
@@ -24,12 +26,15 @@ use Illuminate\Support\Facades\Gate;
|
||||
|
||||
final class ShiftAssignmentController extends Controller
|
||||
{
|
||||
use VerifiesOrganisationEvent;
|
||||
|
||||
public function __construct(
|
||||
private readonly ShiftAssignmentService $service,
|
||||
) {}
|
||||
|
||||
public function index(Request $request, Event $event): AnonymousResourceCollection
|
||||
public function index(Request $request, Organisation $organisation, Event $event): AnonymousResourceCollection
|
||||
{
|
||||
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
||||
Gate::authorize('viewAny', [ShiftAssignment::class, $event]);
|
||||
|
||||
$query = ShiftAssignment::query()
|
||||
@@ -60,8 +65,9 @@ final class ShiftAssignmentController extends Controller
|
||||
return ShiftAssignmentResource::collection($assignments);
|
||||
}
|
||||
|
||||
public function approve(Event $event, ShiftAssignment $shiftAssignment): JsonResponse
|
||||
public function approve(Organisation $organisation, Event $event, ShiftAssignment $shiftAssignment): JsonResponse
|
||||
{
|
||||
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
||||
Gate::authorize('approve', [$shiftAssignment, $event]);
|
||||
|
||||
$shiftAssignment = $this->service->approve($shiftAssignment, request()->user());
|
||||
@@ -69,8 +75,9 @@ final class ShiftAssignmentController extends Controller
|
||||
return $this->success(new ShiftAssignmentResource($shiftAssignment->load(['person', 'shift.festivalSection', 'shift.timeSlot'])));
|
||||
}
|
||||
|
||||
public function reject(RejectShiftAssignmentRequest $request, Event $event, ShiftAssignment $shiftAssignment): JsonResponse
|
||||
public function reject(RejectShiftAssignmentRequest $request, Organisation $organisation, Event $event, ShiftAssignment $shiftAssignment): JsonResponse
|
||||
{
|
||||
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
||||
Gate::authorize('reject', [$shiftAssignment, $event]);
|
||||
|
||||
$shiftAssignment = $this->service->reject(
|
||||
@@ -82,8 +89,9 @@ final class ShiftAssignmentController extends Controller
|
||||
return $this->success(new ShiftAssignmentResource($shiftAssignment->load(['person', 'shift.festivalSection', 'shift.timeSlot'])));
|
||||
}
|
||||
|
||||
public function cancel(Event $event, ShiftAssignment $shiftAssignment): JsonResponse
|
||||
public function cancel(Organisation $organisation, Event $event, ShiftAssignment $shiftAssignment): JsonResponse
|
||||
{
|
||||
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
||||
Gate::authorize('cancel', [$shiftAssignment, $event]);
|
||||
|
||||
$shiftAssignment = $this->service->cancel($shiftAssignment, request()->user());
|
||||
@@ -91,8 +99,9 @@ final class ShiftAssignmentController extends Controller
|
||||
return $this->success(new ShiftAssignmentResource($shiftAssignment->load(['person', 'shift.festivalSection', 'shift.timeSlot'])));
|
||||
}
|
||||
|
||||
public function bulkApprove(BulkApproveShiftAssignmentRequest $request, Event $event): JsonResponse
|
||||
public function bulkApprove(BulkApproveShiftAssignmentRequest $request, Organisation $organisation, Event $event): JsonResponse
|
||||
{
|
||||
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
||||
Gate::authorize('bulkApprove', [ShiftAssignment::class, $event]);
|
||||
|
||||
$assignments = ShiftAssignment::whereIn('id', $request->validated('assignment_ids'))
|
||||
@@ -105,8 +114,9 @@ final class ShiftAssignmentController extends Controller
|
||||
return $this->success($results);
|
||||
}
|
||||
|
||||
public function assignablePersons(Event $event, Shift $shift): JsonResponse
|
||||
public function assignablePersons(Organisation $organisation, Event $event, Shift $shift): JsonResponse
|
||||
{
|
||||
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
||||
Gate::authorize('viewAny', [ShiftAssignment::class, $event]);
|
||||
|
||||
$shift->load(['festivalSection', 'timeSlot']);
|
||||
|
||||
Reference in New Issue
Block a user