Phase 4 of S1.
Models (app/Models/FormBuilder/): FormSchema, FormSchemaSection, FormField,
FormSubmission, FormValue, FormValueOption, FormTemplate, FormFieldLibrary,
FormSchemaWebhook, FormWebhookDelivery, FormSubmissionSectionStatus,
FormSubmissionDelegation. Plus UserProfile at app/Models/ (user-universal).
OrganisationScope applied on: FormSchema, FormTemplate, FormFieldLibrary.
FormSchemaWebhook documents inherited-scope discipline (OrganisationScope's
strategies — organisation_id/event_id/festival_section_id — don't cover
form_schema_id; direct queries would leak across orgs, so must go via
$schema->webhooks()).
User::profile()/getOrCreateProfile(), Event::formSchemas() (morphMany),
Person::formSubmissions() (morphMany).
Morph map enforced in AppServiceProvider with 28 keys covering every model
that appears as activitylog subject/causer. Also updated
OrganisationDashboardService (and its test) to query activitylog via
getMorphClass() instead of FQCN.
Activity log strategy: nuanced explicit calls (logSchemaChange on FormSchema,
logFieldChange on FormField) — no LogsActivity trait. Suppression for bulk
fixtures via App\Support\ActivityLog::suppressed(fn() => ...) which flips
config('activitylog.enabled') around a callback. Both our explicit calls
and spatie's trait on Organisation respect the flag via ActivityLogger::log().
FormValueObserver (app/Observers/FormBuilder/) populates value_indexed/
value_number/value_date/value_bool on save per field.value_storage_hint,
rebuilds form_value_options pivot on multi-value filterable fields, cleans
up on delete. Memoised field cache avoids N+1. Registered in AppServiceProvider.
9 lightweight event classes (app/Events/FormBuilder/) as SerializesModels
containers — submission lifecycle signatures lock in for S2 services, no
listeners yet.
Factories for all models with Dutch fake data (fake('nl_NL')). FormSchema
factory uses defaultSubmissionMode(); FormField factory uses
recommendedValueStorageHint().
Tests: 9 new observer tests (all pass); full suite 910/910 (up from 901).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
136 lines
3.2 KiB
PHP
136 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
final class User extends Authenticatable
|
|
{
|
|
use HasApiTokens;
|
|
use HasFactory;
|
|
use HasRoles;
|
|
use HasUlids;
|
|
use Notifiable;
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'first_name',
|
|
'last_name',
|
|
'date_of_birth',
|
|
'email',
|
|
'phone',
|
|
'password',
|
|
'timezone',
|
|
'locale',
|
|
'avatar',
|
|
'mfa_enabled',
|
|
'mfa_method',
|
|
'mfa_secret',
|
|
'mfa_confirmed_at',
|
|
'mfa_enforced',
|
|
];
|
|
|
|
public function getFullNameAttribute(): string
|
|
{
|
|
return trim("{$this->first_name} {$this->last_name}");
|
|
}
|
|
|
|
public function getNameAttribute(): string
|
|
{
|
|
return $this->full_name;
|
|
}
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
'mfa_secret',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'date_of_birth' => 'date',
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'mfa_enabled' => 'boolean',
|
|
'mfa_confirmed_at' => 'datetime',
|
|
'mfa_enforced' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function organisations(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Organisation::class, 'organisation_user')
|
|
->withPivot('role')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function events(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Event::class, 'event_user_roles')
|
|
->withPivot('role')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function invitations(): HasMany
|
|
{
|
|
return $this->hasMany(UserInvitation::class, 'invited_by_user_id');
|
|
}
|
|
|
|
public function profile(): HasOne
|
|
{
|
|
return $this->hasOne(UserProfile::class);
|
|
}
|
|
|
|
public function getOrCreateProfile(): UserProfile
|
|
{
|
|
return $this->profile()->firstOrCreate([]);
|
|
}
|
|
|
|
public function identityMatches(): HasMany
|
|
{
|
|
return $this->hasMany(PersonIdentityMatch::class, 'matched_user_id');
|
|
}
|
|
|
|
public function persons(): HasMany
|
|
{
|
|
return $this->hasMany(Person::class, 'user_id');
|
|
}
|
|
|
|
public function organisationTags(): HasMany
|
|
{
|
|
return $this->hasMany(UserOrganisationTag::class);
|
|
}
|
|
|
|
public function mfaBackupCodes(): HasMany
|
|
{
|
|
return $this->hasMany(MfaBackupCode::class);
|
|
}
|
|
|
|
public function mfaEmailCodes(): HasMany
|
|
{
|
|
return $this->hasMany(MfaEmailCode::class);
|
|
}
|
|
|
|
public function trustedDevices(): HasMany
|
|
{
|
|
return $this->hasMany(TrustedDevice::class);
|
|
}
|
|
|
|
public function tagsForOrganisation(string $organisationId): HasMany
|
|
{
|
|
return $this->organisationTags()->where('organisation_id', $organisationId);
|
|
}
|
|
}
|