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>
63 lines
2.1 KiB
PHP
63 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Api\V1\Traits\VerifiesOrganisationEvent;
|
|
use App\Http\Requests\Api\V1\StoreLocationRequest;
|
|
use App\Http\Requests\Api\V1\UpdateLocationRequest;
|
|
use App\Http\Resources\Api\V1\LocationResource;
|
|
use App\Models\Event;
|
|
use App\Models\Location;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
final class LocationController extends Controller
|
|
{
|
|
use VerifiesOrganisationEvent;
|
|
|
|
public function index(Organisation $organisation, Event $event): AnonymousResourceCollection
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('viewAny', [Location::class, $event]);
|
|
|
|
$locations = $event->locations()->orderBy('name')->get();
|
|
|
|
return LocationResource::collection($locations);
|
|
}
|
|
|
|
public function store(StoreLocationRequest $request, Organisation $organisation, Event $event): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('create', [Location::class, $event]);
|
|
|
|
$location = $event->locations()->create($request->validated());
|
|
|
|
return $this->created(new LocationResource($location));
|
|
}
|
|
|
|
public function update(UpdateLocationRequest $request, Organisation $organisation, Event $event, Location $location): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('update', [$location, $event]);
|
|
|
|
$location->update($request->validated());
|
|
|
|
return $this->success(new LocationResource($location->fresh()));
|
|
}
|
|
|
|
public function destroy(Organisation $organisation, Event $event, Location $location): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('delete', [$location, $event]);
|
|
|
|
$location->delete();
|
|
|
|
return response()->json(null, 204);
|
|
}
|
|
}
|