presseportale/app/Http/Controllers/Api/V1/LegalAcceptanceController.php
Kevin Adametz 62723b551a legal/web: Zustimmungsgate je Dokumentversion (aus bis AGB 0.7), OG-Variante mit eingebranntem Bildnachweis, Nachweis in Teasern (Bildkennzeichnung Blöcke G und H)
- legal_document_acceptances (insert-only), LegalAcceptanceGate, Pflicht-Schalter im Einreichungs-Modal über den gemeinsamen Trait; API: GET/POST /api/v1/legal/acceptances, submit antwortet 428 mit den geforderten Fassungen; LEGAL_ACCEPTANCE_GATE
- ImageService: og-Variante (1200×630) mit halbtransparentem Balken und Inter SemiBold, regenerateOgVariant() für Korrekturen und Bestand; Fokuspunkt/Letterbox getestet
- Uploader brennt den Nachweis beim Upload ein, ImageCorrectionService baut die OG-Variante nach einer Korrektur neu; Artikelseite nutzt og für og:image
- Teaser: Nachweis in alt/title (Feed, Hero, Kategorie, Newsroom), Unterschrift am Hero-Bild; PressRelease::cardImageCredit()

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-22 10:12:17 +00:00

67 lines
2.5 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Models\LegalDocument;
use App\Models\LegalDocumentAcceptance;
use App\Services\Legal\LegalAcceptanceGate;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
/**
* Zustimmungsgate per API (Block G, O2): einmal je Kontoinhaber und
* Dokumentversion. Ohne gültige Annahme antwortet POST …/submit mit 428
* und den geforderten Fassungen.
*/
class LegalAcceptanceController extends Controller
{
public function __construct(private readonly LegalAcceptanceGate $gate) {}
public function index(Request $request): JsonResponse
{
$required = $this->gate->requiredFor($request->user())->map(fn (LegalDocument $d) => $this->gate->describe($d))->values();
return response()->json([
'gate_enabled' => $this->gate->isEnabled(),
'required' => $required,
'accepted' => LegalDocumentAcceptance::query()
->where('user_id', $request->user()->getKey())
->orderByDesc('id')
->limit(20)
->get(['type', 'version', 'context', 'accepted_at'])
->map(fn (LegalDocumentAcceptance $a) => ['type' => $a->type, 'version' => $a->version, 'context' => $a->context, 'accepted_at' => $a->accepted_at->toIso8601String()])
->values(),
]);
}
public function store(Request $request): JsonResponse
{
abort_unless($request->user()->tokenCan('press-releases:write'), 403);
$validated = $request->validate([
'documents' => ['required', 'array', 'min:1'],
'documents.*.type' => ['required', Rule::in(LegalAcceptanceGate::TYPES)],
'documents.*.version' => ['required', 'string', 'max:10'],
]);
$documents = [];
foreach ($validated['documents'] as $item) {
$current = LegalDocument::current($item['type']);
if ($current === null || $current->version !== $item['version']) {
return response()->json([
'message' => sprintf('Version %s of %s is not the current one (current: %s).', $item['version'], $item['type'], $current !== null ? $current->version : 'none'),
], 422);
}
$documents[] = $current;
}
$this->gate->accept($request->user(), $documents, LegalDocumentAcceptance::CONTEXT_API, $request->ip(), $request->userAgent());
return $this->index($request)->setStatusCode(201);
}
}