- Crowd Types + Persons CRUD (73 tests) - Festival Sections + Time Slots + Shifts CRUD met assign/claim flow (84 tests) - Invite Flow + Member Management met InvitationService (109 tests) - Schema v1.6 migraties volledig uitgevoerd - DevSeeder bijgewerkt met crowd types voor testorganisatie
63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\Event;
|
|
use App\Models\Location;
|
|
use App\Models\User;
|
|
|
|
final class LocationPolicy
|
|
{
|
|
public function viewAny(User $user, Event $event): bool
|
|
{
|
|
return $user->hasRole('super_admin')
|
|
|| $event->organisation->users()->where('user_id', $user->id)->exists();
|
|
}
|
|
|
|
public function create(User $user, Event $event): bool
|
|
{
|
|
return $this->canManageEvent($user, $event);
|
|
}
|
|
|
|
public function update(User $user, Location $location, Event $event): bool
|
|
{
|
|
if ($location->event_id !== $event->id) {
|
|
return false;
|
|
}
|
|
|
|
return $this->canManageEvent($user, $event);
|
|
}
|
|
|
|
public function delete(User $user, Location $location, Event $event): bool
|
|
{
|
|
if ($location->event_id !== $event->id) {
|
|
return false;
|
|
}
|
|
|
|
return $this->canManageEvent($user, $event);
|
|
}
|
|
|
|
private function canManageEvent(User $user, Event $event): bool
|
|
{
|
|
if ($user->hasRole('super_admin')) {
|
|
return true;
|
|
}
|
|
|
|
$isOrgAdmin = $event->organisation->users()
|
|
->where('user_id', $user->id)
|
|
->wherePivot('role', 'org_admin')
|
|
->exists();
|
|
|
|
if ($isOrgAdmin) {
|
|
return true;
|
|
}
|
|
|
|
return $event->users()
|
|
->where('user_id', $user->id)
|
|
->wherePivot('role', 'event_manager')
|
|
->exists();
|
|
}
|
|
}
|