denialReason($user) === null; } /** * Csak a környezeti feltételek (1-2. réteg), felhasználó nélkül. * * Ezt hívja a csomagoló service is: így akkor sem fut le, ha valaki a felületet * megkerülve (konzolról, jobból) indítaná el egy szerveren. */ public function environmentDenialReason(): ?string { if (! config('deployment.enabled')) { return 'A deployment csomagoló ki van kapcsolva (DEPLOYMENT_PACKAGE_ENABLED).'; } /** @var array $stages */ $stages = (array) config('deployment.stages', []); if (! in_array((string) config('app.stage'), $stages, true)) { return sprintf( 'A deployment csomagoló csak fejlesztői környezetben használható (engedélyezett stage: %s, jelenlegi: %s).', implode(', ', $stages), (string) config('app.stage'), ); } return null; } /** * Az első nem teljesülő feltétel magyarázata, vagy null, ha minden rendben. */ public function denialReason(?User $user = null): ?string { if ($reason = $this->environmentDenialReason()) { return $reason; } if (! $user) { return 'Bejelentkezés szükséges.'; } if (! $user->hasRole((string) config('deployment.role'))) { return 'A deployment csomagoló csak fejlesztői szerepkörrel érhető el.'; } if (! Feature::for($user)->active((string) config('deployment.feature_flag'))) { return 'A deployment csomagoló feature flag nincs bekapcsolva erre a felhasználóra.'; } return null; } public function ensureAllowed(?User $user = null): void { if ($reason = $this->denialReason($user)) { abort(403, $reason); } } public function ensureEnvironmentAllowed(): void { if ($reason = $this->environmentDenialReason()) { throw new RuntimeException($reason); } } }