9A — Gelb geht direkt live (Entscheidung 12.06.2026): - routeByClassification(): Gelb durchlaeuft denselben Auto-Publish-Pfad wie Gruen (autoPublishApproved); nur Rot wird abgelehnt - Scheduler publiziert faellige gelbe + gruene PMs; unklassifizierte bleiben als Fallback in der manuellen Queue 9B — Slot-Verbrauch bei Veroeffentlichung (Decision-Update 3.2): - Increment aus submitForReview() entfernt; publish() und changeStatusFromAdmin() zaehlen idempotent beim ersten published-Uebergang (Pruefung ueber Status-Logs); Rot kostet nichts - Submit-Guard: Einreichen erfordert freien Slot (QuotaExceededException, API 422) 9C — Submit-Gate vorbereitet (Decision-Update 5.1): - User::hasActiveBooking()-Stub hinter config/billing.php (enforce_booking, Default aus); Tarif-Modul ersetzt nur den Rumpf - Einreichungs-Modal zeigt ohne Buchung einen Buchungs-Hinweis; Server-Guard (BookingRequiredException), API antwortet 402 - Fix: Customer-Create legte PMs bei "Zur Pruefung senden" direkt mit Status review an (vorbei an Blacklist/Quota/KI/Status-Log) — laeuft jetzt immer ueber submitForReview() Suite: 451 passed, 4 skipped (9 neue Tests). Pint clean. Plan: docs/PHASE-9-FLOW-UND-TARIFE-PLAN.md (Block 2 nach Review-Stopp). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
208 lines
5.4 KiB
PHP
208 lines
5.4 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);
|
|
}
|
|
|
|
/**
|
|
* Submit-Gate aus dem Decision-Update §5.1: Einreichen zur Prüfung
|
|
* erfordert eine aktive Buchung.
|
|
*
|
|
* Stub bis zum Tarif-Modul (Phase 9D/9E): solange
|
|
* `billing.enforce_booking` deaktiviert ist (Default), gilt jede:r als
|
|
* gebucht. Das Tarif-Modul ersetzt den Rumpf durch die echte
|
|
* Subscription-/Einzelkauf-Prüfung — die Schnittstelle bleibt stabil.
|
|
*/
|
|
public function hasActiveBooking(): bool
|
|
{
|
|
if (! config('billing.enforce_booking')) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 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']);
|
|
}
|
|
}
|