Implement EAV system for dynamic event-specific registration fields with organisation-level templates, person section preferences with priority ranking, and TagSyncService for deferred tag_picker sync. New tables: registration_field_templates, registration_form_fields, person_field_values, person_section_preferences. New columns: persons.remarks, events.registration_show_section_preferences, events.registration_show_availability. 58 tests, 126 assertions — all 432 tests pass (zero regressions). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
2.0 KiB
PHP
85 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\Event;
|
|
use App\Models\RegistrationFormField;
|
|
use App\Models\User;
|
|
|
|
final class RegistrationFormFieldPolicy
|
|
{
|
|
public function viewAny(User $user, Event $event): bool
|
|
{
|
|
return $this->belongsToOrganisation($user, $event);
|
|
}
|
|
|
|
public function view(User $user, RegistrationFormField $field, Event $event): bool
|
|
{
|
|
if ($field->event_id !== $event->id) {
|
|
return false;
|
|
}
|
|
|
|
return $this->belongsToOrganisation($user, $event);
|
|
}
|
|
|
|
public function create(User $user, Event $event): bool
|
|
{
|
|
return $this->canManageEvent($user, $event);
|
|
}
|
|
|
|
public function update(User $user, RegistrationFormField $field, Event $event): bool
|
|
{
|
|
if ($field->event_id !== $event->id) {
|
|
return false;
|
|
}
|
|
|
|
return $this->canManageEvent($user, $event);
|
|
}
|
|
|
|
public function delete(User $user, RegistrationFormField $field, Event $event): bool
|
|
{
|
|
if ($field->event_id !== $event->id) {
|
|
return false;
|
|
}
|
|
|
|
return $this->canManageEvent($user, $event);
|
|
}
|
|
|
|
public function reorder(User $user, Event $event): bool
|
|
{
|
|
return $this->canManageEvent($user, $event);
|
|
}
|
|
|
|
private function belongsToOrganisation(User $user, Event $event): bool
|
|
{
|
|
if ($user->hasRole('super_admin')) {
|
|
return true;
|
|
}
|
|
|
|
return $event->organisation->users()->where('user_id', $user->id)->exists();
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|