feat: local sections in sub-events can use festival-level time slots

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-10 11:16:32 +02:00
parent 37fecf7181
commit 03ca1a50a7
7 changed files with 164 additions and 37 deletions

View File

@@ -22,6 +22,22 @@ final class TimeSlotController extends Controller
$timeSlots = $event->timeSlots()->orderBy('date')->orderBy('start_time')->get();
if ($event->isSubEvent() && request()->boolean('include_parent') && $event->parent_event_id) {
$parentTimeSlots = TimeSlot::where('event_id', $event->parent_event_id)
->with('event')
->orderBy('date')
->orderBy('start_time')
->get();
$timeSlots->load('event');
$timeSlots->each(fn (TimeSlot $ts) => $ts->setAttribute('source', 'sub_event'));
$parentTimeSlots->each(fn (TimeSlot $ts) => $ts->setAttribute('source', 'festival'));
$timeSlots = $timeSlots->merge($parentTimeSlots)
->sortBy([['date', 'asc'], ['start_time', 'asc']])
->values();
}
return TimeSlotResource::collection($timeSlots);
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Http\Requests\Api\V1;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
final class StoreShiftRequest extends FormRequest
{
@@ -17,7 +18,16 @@ final class StoreShiftRequest extends FormRequest
public function rules(): array
{
return [
'time_slot_id' => ['required', 'ulid', 'exists:time_slots,id'],
'time_slot_id' => ['required', 'ulid', Rule::exists('time_slots', 'id')->where(function ($query) {
$event = $this->route('event');
$eventIds = [$event->id];
if ($event->isSubEvent() && $event->parent_event_id) {
$eventIds[] = $event->parent_event_id;
}
$query->whereIn('event_id', $eventIds);
})],
'location_id' => ['nullable', 'ulid', 'exists:locations,id'],
'title' => ['nullable', 'string', 'max:255'],
'description' => ['nullable', 'string'],
@@ -28,8 +38,10 @@ final class StoreShiftRequest extends FormRequest
'report_time' => ['nullable', 'date_format:H:i'],
'actual_start_time' => ['nullable', 'date_format:H:i'],
'actual_end_time' => ['nullable', 'date_format:H:i'],
'end_date' => ['nullable', 'date'],
'is_lead_role' => ['nullable', 'boolean'],
'allow_overlap' => ['nullable', 'boolean'],
'events_during_shift' => ['nullable', 'array'],
'status' => ['nullable', 'in:draft,open,full,in_progress,completed,cancelled'],
];
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Http\Requests\Api\V1;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
final class UpdateShiftRequest extends FormRequest
{
@@ -17,7 +18,16 @@ final class UpdateShiftRequest extends FormRequest
public function rules(): array
{
return [
'time_slot_id' => ['sometimes', 'ulid', 'exists:time_slots,id'],
'time_slot_id' => ['sometimes', 'ulid', Rule::exists('time_slots', 'id')->where(function ($query) {
$event = $this->route('event');
$eventIds = [$event->id];
if ($event->isSubEvent() && $event->parent_event_id) {
$eventIds[] = $event->parent_event_id;
}
$query->whereIn('event_id', $eventIds);
})],
'location_id' => ['nullable', 'ulid', 'exists:locations,id'],
'title' => ['nullable', 'string', 'max:255'],
'description' => ['nullable', 'string'],
@@ -28,8 +38,10 @@ final class UpdateShiftRequest extends FormRequest
'report_time' => ['nullable', 'date_format:H:i'],
'actual_start_time' => ['nullable', 'date_format:H:i'],
'actual_end_time' => ['nullable', 'date_format:H:i'],
'end_date' => ['nullable', 'date'],
'is_lead_role' => ['nullable', 'boolean'],
'allow_overlap' => ['nullable', 'boolean'],
'events_during_shift' => ['nullable', 'array'],
'status' => ['sometimes', 'in:draft,open,full,in_progress,completed,cancelled'],
];
}

View File

@@ -6,6 +6,7 @@ namespace App\Http\Resources\Api\V1;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;
final class TimeSlotResource extends JsonResource
{
@@ -17,9 +18,11 @@ final class TimeSlotResource extends JsonResource
'name' => $this->name,
'person_type' => $this->person_type,
'date' => $this->date->toDateString(),
'start_time' => $this->start_time,
'end_time' => $this->end_time,
'start_time' => Carbon::parse($this->start_time)->format('H:i'),
'end_time' => Carbon::parse($this->end_time)->format('H:i'),
'duration_hours' => $this->duration_hours,
'source' => $this->resource->getAttribute('source'),
'event_name' => $this->whenLoaded('event', fn () => $this->event->name),
'created_at' => $this->created_at->toIso8601String(),
];
}

View File

@@ -126,6 +126,30 @@ class TimeSlotTest extends TestCase
->assertJson(['data' => ['name' => 'Vrijdag Avond Updated']]);
}
public function test_update_cross_org_returns_403(): void
{
$timeSlot = TimeSlot::factory()->create(['event_id' => $this->event->id]);
Sanctum::actingAs($this->outsider);
$response = $this->putJson("/api/v1/events/{$this->event->id}/time-slots/{$timeSlot->id}", [
'name' => 'Hacked',
]);
$response->assertForbidden();
}
public function test_destroy_cross_org_returns_403(): void
{
$timeSlot = TimeSlot::factory()->create(['event_id' => $this->event->id]);
Sanctum::actingAs($this->outsider);
$response = $this->deleteJson("/api/v1/events/{$this->event->id}/time-slots/{$timeSlot->id}");
$response->assertForbidden();
}
public function test_destroy_deletes_time_slot(): void
{
$timeSlot = TimeSlot::factory()->create(['event_id' => $this->event->id]);