images: Datenmodell, Textarchiv, Herkunftsprüfung und gemeinsamer Uploader für Formular v2 (Bildkennzeichnung Block A)
- press_release_images: Kundenangabe/Portalkennzeichnung getrennt, Herkunftsbefund, Beweisoriginal, Snapshot-Pfade, published_ever_at, rules_version, Fokus/Letterbox; Bestand unangetastet - legal_texts (insert-only) mit img-confirm-v1 (alter Wortlaut), v2 (AGB 0.6), v3 (AGB 0.7, noch ohne Datum); image-rights:backfill-confirmations - image_rights_confirmations polymorph, insert-only, IP als versionierter HMAC; Löschung nur für nie veröffentlichte Uploads - ImageProvenanceInspector (Imagick/exif): IPTC, XMP, EXIF; algorithmicallyEnhanced nur Vermerk; unlesbare Datei = error - PressReleaseImageUploader: Original vor Derivaten, Hash-Bindung, Titelbild-Regel unter Sperre, Dateien bei Fehlern zurückgerollt; Admin-Upload ohne Bestätigung - ImageService: kein Rückfall auf die Quelldatei, og-Variante, Fokuspunkt und no_crop Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
b624f80d7f
commit
e9bdff3ad3
36 changed files with 2631 additions and 30 deletions
128
app/Models/ImageRightsConfirmation.php
Normal file
128
app/Models/ImageRightsConfirmation.php
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ConfirmationChannel;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
/**
|
||||
* Protokollierte Rechtebestätigung zu einem Bild (Bildkennzeichnung A.2).
|
||||
*
|
||||
* Insert-only: `ImageRightsConfirmationObserver` wirft bei Update und
|
||||
* Delete. Die einzige zulässige Löschung ist die Sofortlöschung eines nie
|
||||
* veröffentlichten Uploads (Decision-Update E4) über purgeForUnpublished().
|
||||
*
|
||||
* `user_id` ist der Kontoinhaber und damit der Vertragspartner (E1);
|
||||
* `company_id` ist nur die Zuordnung zum Firmenprofil. `text_snapshot` hält
|
||||
* den gerenderten Wortlaut mit aufgelöster AGB-Fassung fest, damit die
|
||||
* Bestätigung auch dann rekonstruierbar bleibt, wenn `legal_texts` und
|
||||
* `legal_documents` weiterwachsen.
|
||||
*/
|
||||
class ImageRightsConfirmation extends Model
|
||||
{
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
/**
|
||||
* Vom Observer geprüfter Freischein für die Sofortlöschung nie
|
||||
* veröffentlichter Uploads (E.3). Nie von außen setzen.
|
||||
*/
|
||||
public bool $purgingUnpublished = false;
|
||||
|
||||
protected $fillable = [
|
||||
'subject_type',
|
||||
'subject_id',
|
||||
'press_release_id',
|
||||
'company_id',
|
||||
'user_id',
|
||||
'personal_access_token_id',
|
||||
'channel',
|
||||
'legal_text_id',
|
||||
'legal_text_key',
|
||||
'text_snapshot',
|
||||
'agb_version',
|
||||
'locale',
|
||||
'file_sha256',
|
||||
'declaration_snapshot',
|
||||
'ip_hmac',
|
||||
'user_agent',
|
||||
'confirmed_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'channel' => ConfirmationChannel::class,
|
||||
'declaration_snapshot' => 'array',
|
||||
'confirmed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pseudonymisierte IP-Ableitung: HMAC mit eigenem Schlüssel und
|
||||
* Versionspräfix (Decision-Update 3.7). Kein reiner Hash — ohne den
|
||||
* Schlüssel lässt sich keine Adresse zuordnen.
|
||||
*/
|
||||
public static function hashIp(?string $ip): ?string
|
||||
{
|
||||
if (blank($ip)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$key = (string) config('images.confirmation_ip_key');
|
||||
$version = (string) config('images.confirmation_ip_hash_version', 'v1');
|
||||
|
||||
return $version.':'.hash_hmac('sha256', $ip, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sofortlöschung eines nie veröffentlichten Uploads (E.3). Nur hier
|
||||
* darf eine Bestätigung verschwinden — der Observer prüft das Flag.
|
||||
*/
|
||||
public function purgeForUnpublished(): void
|
||||
{
|
||||
$this->purgingUnpublished = true;
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphTo<Model, $this>
|
||||
*/
|
||||
public function subject(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<PressRelease, $this>
|
||||
*/
|
||||
public function pressRelease(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PressRelease::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Company, $this>
|
||||
*/
|
||||
public function company(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<LegalText, $this>
|
||||
*/
|
||||
public function legalText(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(LegalText::class);
|
||||
}
|
||||
}
|
||||
113
app/Models/LegalText.php
Normal file
113
app/Models/LegalText.php
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* Unveränderliche Fassung eines Bestätigungstextes (Bildkennzeichnung A.3).
|
||||
*
|
||||
* Zeilen werden nie geändert oder gelöscht. Eine Kennung (`key`) gehört zu
|
||||
* genau einem Wortlaut; ein neuer Wortlaut bekommt eine neue Kennung. Der
|
||||
* Text ist an die AGB-Fassung gebunden, deren Paragrafen er nennt
|
||||
* (Decision-Update 3.3): Solange AGB 0.6 gilt, ist `img-confirm-v2` aktiv,
|
||||
* mit AGB 0.7 wird `img-confirm-v3` wirksam.
|
||||
*/
|
||||
class LegalText extends Model
|
||||
{
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
public const TYPE_IMAGE_RIGHTS_CONFIRMATION = 'image_rights_confirmation';
|
||||
|
||||
protected $fillable = [
|
||||
'key',
|
||||
'type',
|
||||
'locale',
|
||||
'title',
|
||||
'body',
|
||||
'short_body',
|
||||
'bound_agb_version',
|
||||
'body_sha256',
|
||||
'effective_from',
|
||||
'note',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'effective_from' => 'date',
|
||||
];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $text): void {
|
||||
$text->body_sha256 = hash('sha256', $text->body);
|
||||
});
|
||||
|
||||
static::updating(fn () => throw new \LogicException('legal_texts ist unveränderlich — neue Fassung als neue Zeile anlegen.'));
|
||||
static::deleting(fn () => throw new \LogicException('legal_texts ist unveränderlich — Fassungen werden nie gelöscht.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Die heute gültige Fassung eines Typs für die gegebene AGB-Fassung.
|
||||
* Fällt auf die jüngste gültige Fassung ohne AGB-Bindung zurück, damit
|
||||
* ein Text ohne Paragrafenverweis für jede AGB-Fassung taugt.
|
||||
*/
|
||||
public static function currentFor(string $type, ?string $agbVersion, string $locale = 'de'): ?self
|
||||
{
|
||||
$query = static::query()
|
||||
->where('type', $type)
|
||||
->where('locale', $locale)
|
||||
->whereNotNull('effective_from')
|
||||
->where('effective_from', '<=', today())
|
||||
->orderByDesc('effective_from')
|
||||
->orderByDesc('id');
|
||||
|
||||
if ($agbVersion !== null) {
|
||||
$bound = (clone $query)->where('bound_agb_version', $agbVersion)->first();
|
||||
|
||||
if ($bound !== null) {
|
||||
return $bound;
|
||||
}
|
||||
}
|
||||
|
||||
return (clone $query)->whereNull('bound_agb_version')->first();
|
||||
}
|
||||
|
||||
public static function findByKey(string $key): ?self
|
||||
{
|
||||
return static::query()->where('key', $key)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ob eine Kennung heute abgegeben werden darf (aktive Fassung des Typs).
|
||||
*/
|
||||
public function isCurrentFor(?string $agbVersion, string $locale = 'de'): bool
|
||||
{
|
||||
return static::currentFor($this->type, $agbVersion, $locale)?->is($this) === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Platzhalter im Wortlaut auflösen. Der gerenderte Text wird mit der
|
||||
* Bestätigung gespeichert, der Rohtext bleibt hier unverändert.
|
||||
*
|
||||
* @param array<string, string> $variables
|
||||
*/
|
||||
public function render(array $variables, bool $short = false): string
|
||||
{
|
||||
$template = $short ? ($this->short_body ?? $this->body) : $this->body;
|
||||
|
||||
return strtr($template, collect($variables)
|
||||
->mapWithKeys(fn (string $value, string $name): array => ['{'.$name.'}' => $value])
|
||||
->all());
|
||||
}
|
||||
|
||||
public function effectiveFromFormatted(): ?string
|
||||
{
|
||||
return $this->effective_from
|
||||
? Carbon::parse($this->effective_from)->locale('de')->isoFormat('D. MMMM YYYY')
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,15 +2,33 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\AiDeclarationSource;
|
||||
use App\Enums\AiImageDeclaration;
|
||||
use App\Enums\CreditSource;
|
||||
use App\Enums\ImageLicenseType;
|
||||
use App\Enums\ImageProvenanceStatus;
|
||||
use Database\Factories\PressReleaseImageFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
/**
|
||||
* Bild einer Pressemitteilung. Seit Formular v2 (Bildkennzeichnung,
|
||||
* 22.09.2026) gilt: `ai_declaration` ist die öffentliche Portalkennzeichnung,
|
||||
* `ai_declaration_user` die Angabe des Einreichers, `ai_declaration_source`
|
||||
* sagt, woher die Portalkennzeichnung stammt. `rules_version` NULL markiert
|
||||
* den Bestand vor der Umstellung; solche Bilder haben kein Beweisoriginal
|
||||
* und kein Bestätigungsprotokoll.
|
||||
*/
|
||||
class PressReleaseImage extends Model
|
||||
{
|
||||
/** @use HasFactory<PressReleaseImageFactory> */
|
||||
use HasFactory;
|
||||
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
|
|
@ -33,6 +51,25 @@ class PressReleaseImage extends Model
|
|||
'rights_confirmed_at',
|
||||
'is_ai_generated',
|
||||
'ai_declaration',
|
||||
'ai_declaration_user',
|
||||
'ai_declaration_source',
|
||||
'ai_declaration_locked',
|
||||
'credit_source',
|
||||
'provenance_status',
|
||||
'provenance',
|
||||
'provenance_checked_at',
|
||||
'provenance_tool_version',
|
||||
'original_disk',
|
||||
'original_path',
|
||||
'original_sha256',
|
||||
'published_snapshot_path',
|
||||
'published_snapshot_sha256',
|
||||
'published_ever_at',
|
||||
'customer_confirmation_requested_at',
|
||||
'rules_version',
|
||||
'focus_x',
|
||||
'focus_y',
|
||||
'no_crop',
|
||||
'is_preview',
|
||||
'sort_order',
|
||||
'width',
|
||||
|
|
@ -51,6 +88,18 @@ class PressReleaseImage extends Model
|
|||
'rights_confirmed_at' => 'datetime',
|
||||
'is_ai_generated' => 'boolean',
|
||||
'ai_declaration' => AiImageDeclaration::class,
|
||||
'ai_declaration_user' => AiImageDeclaration::class,
|
||||
'ai_declaration_source' => AiDeclarationSource::class,
|
||||
'ai_declaration_locked' => 'boolean',
|
||||
'credit_source' => CreditSource::class,
|
||||
'provenance_status' => ImageProvenanceStatus::class,
|
||||
'provenance' => 'array',
|
||||
'provenance_checked_at' => 'datetime',
|
||||
'published_ever_at' => 'datetime',
|
||||
'customer_confirmation_requested_at' => 'datetime',
|
||||
'focus_x' => 'integer',
|
||||
'focus_y' => 'integer',
|
||||
'no_crop' => 'boolean',
|
||||
'is_preview' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
'width' => 'integer',
|
||||
|
|
@ -67,6 +116,60 @@ class PressReleaseImage extends Model
|
|||
return $this->belongsTo(PressRelease::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphMany<ImageRightsConfirmation, $this>
|
||||
*/
|
||||
public function rightsConfirmations(): MorphMany
|
||||
{
|
||||
return $this->morphMany(ImageRightsConfirmation::class, 'subject');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphOne<ImageRightsConfirmation, $this>
|
||||
*/
|
||||
public function latestRightsConfirmation(): MorphOne
|
||||
{
|
||||
return $this->morphOne(ImageRightsConfirmation::class, 'subject')->latestOfMany('confirmed_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestand vor Formular v2: kein Beweisoriginal, kein Protokoll. Nach der
|
||||
* Legacy-Bereinigung (E.5) sind das nur noch Bilder veröffentlichter PMs.
|
||||
*/
|
||||
public function isLegacyRules(): bool
|
||||
{
|
||||
return $this->rules_version === null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Bestätigung zählt nur, wenn sie zur aktuellen Datei gehört
|
||||
* (Feedback F09): Bildtausch verlangt eine neue Bestätigung.
|
||||
*/
|
||||
public function hasValidRightsConfirmation(): bool
|
||||
{
|
||||
$confirmation = $this->relationLoaded('latestRightsConfirmation')
|
||||
? $this->latestRightsConfirmation
|
||||
: $this->latestRightsConfirmation()->first();
|
||||
|
||||
return $confirmation !== null
|
||||
&& $this->original_sha256 !== null
|
||||
&& hash_equals($this->original_sha256, (string) $confirmation->file_sha256);
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin-Upload, dessen Kundenbestätigung per Magic-Link noch aussteht
|
||||
* (Decision-Update E10). Blockiert die Veröffentlichung (E.1).
|
||||
*/
|
||||
public function awaitsCustomerConfirmation(): bool
|
||||
{
|
||||
return $this->customer_confirmation_requested_at !== null && ! $this->hasValidRightsConfirmation();
|
||||
}
|
||||
|
||||
public function wasEverPublished(): bool
|
||||
{
|
||||
return $this->published_ever_at !== null;
|
||||
}
|
||||
|
||||
public function url(bool $signed = false): ?string
|
||||
{
|
||||
if (blank($this->path)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue