E4 (15.09.2026): Die Veröffentlichungsmail trägt den Hinweis am Ende, als Hinweis, nicht als Angebot. Auf der Newsroom-Seite eine Zeile unter dem Profil. Der Mail-Link ist mit src=mail_publish getaggt; die Claim-Seite reicht die Herkunft bis auf das Token durch, sodass die Leiter „aus der Mail beansprucht“ von „auf der Seite entdeckt“ unterscheidet. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
141 lines
5.1 KiB
PHP
141 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
use App\Enums\ConversionSource;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Company;
|
|
use App\Scopes\PortalScope;
|
|
use App\Services\Company\MergedNewsroomLookup;
|
|
use App\Services\Company\NewsroomClaimService;
|
|
use App\Support\WebPortalContext;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
/**
|
|
* Öffentliche Seite „Diesen Newsroom verwalten" (Roadmap 1b.2). Erreichbar
|
|
* für jede Firma mit Slug — auch ohne veröffentlichte Meldung, denn der
|
|
* Verwaltungszugang ist von der öffentlichen Sichtbarkeit unabhängig. Nur
|
|
* 410-entfernte Newsrooms bleiben Tombstone, aufgegangene führen zum
|
|
* Überlebenden.
|
|
*/
|
|
class NewsroomClaimController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly NewsroomClaimService $claims,
|
|
private readonly MergedNewsroomLookup $mergedNewsrooms,
|
|
) {}
|
|
|
|
public function show(string $edition, string $slug): View|Response|RedirectResponse
|
|
{
|
|
$context = WebPortalContext::fromRequest();
|
|
$company = $this->claims->findClaimable($context->portalValues, $slug);
|
|
|
|
if (! $company) {
|
|
return $this->resolveMissing($context, $edition, $slug);
|
|
}
|
|
|
|
return view('web.newsroom-claim', [
|
|
'company' => $company,
|
|
'recipients' => $this->claims->maskedRecipients($company),
|
|
]);
|
|
}
|
|
|
|
public function store(Request $request, string $edition, string $slug): RedirectResponse|Response
|
|
{
|
|
$context = WebPortalContext::fromRequest();
|
|
$company = $this->claims->findClaimable($context->portalValues, $slug);
|
|
|
|
if (! $company) {
|
|
return $this->resolveMissing($context, $edition, $slug);
|
|
}
|
|
|
|
// Bot: neutral abnicken, bewusst vor allem anderen.
|
|
if (filled($request->input('website'))) {
|
|
return back()->with('newsroom-claim-status', __('static.newsroom_claim.flash_sent'));
|
|
}
|
|
|
|
$this->ensureNotRateLimited($request, $company->getKey());
|
|
RateLimiter::hit($this->ipKey($request), 3600);
|
|
RateLimiter::hit($this->companyKey($company->getKey()), 86400);
|
|
|
|
if ($this->claims->recipients($company)->isEmpty()) {
|
|
return back()->with('newsroom-claim-none', true);
|
|
}
|
|
|
|
// Enumeration-sicher: dieselbe Meldung, ob ein Konto deaktiviert ist
|
|
// oder nicht — die Adresse ist ohnehin nur maskiert sichtbar.
|
|
$this->claims->request($company, $request->ip(), $this->sourceOf($request));
|
|
|
|
return back()->with('newsroom-claim-status', __('static.newsroom_claim.flash_sent'));
|
|
}
|
|
|
|
private function resolveMissing(WebPortalContext $context, string $edition, string $slug): Response|RedirectResponse
|
|
{
|
|
$survivor = $this->mergedNewsrooms->survivorFor($context->portalValues, $slug);
|
|
|
|
if ($survivor !== null && $survivor->gone_at === null) {
|
|
// Host aus dem Request wie bei den anderen 301-Weiterleitungen —
|
|
// route() allein trüge den konfigurierten Root-Host.
|
|
return redirect(
|
|
request()->getSchemeAndHttpHost().route('newsroom.claim', ['edition' => $edition, 'slug' => $survivor->slug], absolute: false),
|
|
301,
|
|
);
|
|
}
|
|
|
|
// 410-entfernt → Tombstone wie die Newsroom-Seite selbst; sonst 404.
|
|
$gone = Company::query()
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->whereIn('portal', $context->portalValues)
|
|
->where('slug', $slug)
|
|
->whereNotNull('gone_at')
|
|
->exists();
|
|
|
|
if ($gone) {
|
|
return response()->view('web.newsroom-tombstone', [], 410);
|
|
}
|
|
|
|
abort(404);
|
|
}
|
|
|
|
/**
|
|
* Kam der Besucher aus einer Mail (`src` aus dem Link, per Formular
|
|
* weitergereicht), trägt das Token diese Herkunft — sonst ist es der
|
|
* Hinweis auf der Newsroom-Seite.
|
|
*/
|
|
private function sourceOf(Request $request): ConversionSource
|
|
{
|
|
$source = ConversionSource::parse($request->filled('src') ? (string) $request->input('src') : null);
|
|
|
|
return in_array($source, [ConversionSource::MailPublish, ConversionSource::MailReject], true)
|
|
? $source
|
|
: ConversionSource::ProfileClaim;
|
|
}
|
|
|
|
private function ensureNotRateLimited(Request $request, int $companyId): void
|
|
{
|
|
$perDay = (int) config('newsroom.claim.links_per_day', 3);
|
|
|
|
if (RateLimiter::tooManyAttempts($this->companyKey($companyId), $perDay)) {
|
|
throw ValidationException::withMessages(['claim' => __('static.newsroom_claim.throttle_company')]);
|
|
}
|
|
|
|
if (RateLimiter::tooManyAttempts($this->ipKey($request), 15)) {
|
|
throw ValidationException::withMessages(['claim' => __('static.newsroom_claim.throttle_ip')]);
|
|
}
|
|
}
|
|
|
|
private function companyKey(int $companyId): string
|
|
{
|
|
return 'newsroom-claim|company|'.$companyId;
|
|
}
|
|
|
|
private function ipKey(Request $request): string
|
|
{
|
|
return 'newsroom-claim|ip|'.$request->ip();
|
|
}
|
|
}
|