Phase 8 (Rest) + Umbauten vom 10./11.06.: - Ein Titelbild pro PM (Cover 1280x580), SVG-Platzhalter-Set + Picker, PressReleaseCoverImage-Resolver - Lizenz-/Rechteformular nach "Lizenztyp Bildupload" (7 Lizenztypen, Personen-/Sachrechte-Status, bedingte Pflichtfelder, Risikohinweise) - Veroeffentlichungs-Box vereinfacht (Embargo aus der Form-UI entfernt), geplante Termine in Europe/Berlin (Speicherung UTC, DISPLAY_TIMEZONE) - Quota-Stub (users.press_release_quota) + monatlicher Reset-Command - Einreichungs-Modal einheitlich in Show/Create/Edit; Ghost-Buttons auf filled; PM-Editor-Layout responsive entkoppelt (.pr-editor-layout) KI-Pruef-Pipeline (Phasen 1-5 des Entwicklungsplans): - API-Haertung: status nicht mehr per API setzbar, eigene Submit-Route durch denselben Funnel (Blacklist, Quota, Status-Log) - Klassifikation Rot/Gelb/Gruen asynchron (Queue classification, OpenAI-Treiber + deterministischer Fallback), ki_audits-Audit-Log - Routing: Rot -> rejected + Mail, Gelb -> Review-Queue, Gruen -> Auto-Publish; Scheduler publiziert nur gruene faellige PMs - Content-Score 0-100 -> Stufe (Standard/Geprueft/Hochwertig) inkl. Editor-Panel und Badges; Re-Klassifikation/-Score bei Aenderung - Admin: KI-Badge + Filter, On-Demand-Pruefung mit Anbieter-Override Suite: 442 passed, 4 skipped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
190 lines
4.8 KiB
PHP
190 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use App\Enums\Portal;
|
|
use App\Enums\RegistrationType;
|
|
use Database\Factories\UserFactory;
|
|
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 Illuminate\Support\Str;
|
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasApiTokens, HasFactory, HasRoles, Notifiable, SoftDeletes, TwoFactorAuthenticatable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'portal',
|
|
'registration_type',
|
|
'language',
|
|
'is_active',
|
|
'is_super_admin',
|
|
'last_login_at',
|
|
'last_login_ip',
|
|
'gdpr_consent_at',
|
|
'last_seen_at',
|
|
'legacy_portal',
|
|
'legacy_id',
|
|
'password',
|
|
'press_release_quota',
|
|
'press_release_quota_used_this_month',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'portal' => Portal::class,
|
|
'registration_type' => RegistrationType::class,
|
|
'is_active' => 'boolean',
|
|
'is_super_admin' => 'boolean',
|
|
'last_login_at' => 'datetime',
|
|
'gdpr_consent_at' => 'datetime',
|
|
'last_seen_at' => 'datetime',
|
|
'deleted_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'press_release_quota' => 'integer',
|
|
'press_release_quota_used_this_month' => 'integer',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Verbleibendes PM-Kontingent in diesem Monat.
|
|
*
|
|
* Temporärer Stub bis zum echten Tarif-/Credit-Modul. Die Schnittstelle
|
|
* (`pressReleaseQuotaRemaining()`) bleibt stabil, damit das
|
|
* Veröffentlichungs-Modal nicht neu gebaut werden muss.
|
|
*/
|
|
public function pressReleaseQuotaRemaining(): int
|
|
{
|
|
return max(0, (int) $this->press_release_quota - (int) $this->press_release_quota_used_this_month);
|
|
}
|
|
|
|
/**
|
|
* Get the user's initials
|
|
*/
|
|
public function initials(): string
|
|
{
|
|
return Str::of($this->name)
|
|
->explode(' ')
|
|
->map(fn (string $name) => Str::of($name)->substr(0, 1))
|
|
->implode('');
|
|
}
|
|
|
|
public function profile(): HasOne
|
|
{
|
|
return $this->hasOne(Profile::class);
|
|
}
|
|
|
|
public function magicLinks(): HasMany
|
|
{
|
|
return $this->hasMany(MagicLink::class);
|
|
}
|
|
|
|
public function ownedCompanies(): HasMany
|
|
{
|
|
return $this->hasMany(Company::class, 'owner_user_id');
|
|
}
|
|
|
|
public function companies(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Company::class)
|
|
->withPivot('role')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function contacts(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Contact::class)
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function pressReleases(): HasMany
|
|
{
|
|
return $this->hasMany(PressRelease::class);
|
|
}
|
|
|
|
public function newsletterSubscriptions(): HasMany
|
|
{
|
|
return $this->hasMany(NewsletterSubscription::class);
|
|
}
|
|
|
|
public function billingAddress(): HasOne
|
|
{
|
|
return $this->hasOne(BillingAddress::class);
|
|
}
|
|
|
|
public function userPaymentOptions(): HasMany
|
|
{
|
|
return $this->hasMany(UserPaymentOption::class);
|
|
}
|
|
|
|
public function invoices(): HasMany
|
|
{
|
|
return $this->hasMany(Invoice::class);
|
|
}
|
|
|
|
public function legacyInvoices(): HasMany
|
|
{
|
|
return $this->hasMany(LegacyInvoice::class);
|
|
}
|
|
|
|
public function filterPresets(): HasMany
|
|
{
|
|
return $this->hasMany(UserFilterPreset::class);
|
|
}
|
|
|
|
public function canAccessAdmin(): bool
|
|
{
|
|
if (! $this->is_active) {
|
|
return false;
|
|
}
|
|
|
|
if ($this->is_super_admin) {
|
|
return true;
|
|
}
|
|
|
|
return $this->hasAnyRole(['admin', 'editor']);
|
|
}
|
|
|
|
public function canAccessCustomer(): bool
|
|
{
|
|
if (! $this->is_active) {
|
|
return false;
|
|
}
|
|
|
|
return $this->hasAnyRole(['admin', 'editor', 'customer']);
|
|
}
|
|
}
|