Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat(horizon): read allowed emails from config and allow root user by id

peaklabs-dev5da6c5e11822
diff --git a/app/Providers/HorizonServiceProvider.php b/app/Providers/HorizonServiceProvider.php
index 1978ea0cb4..9fe33b2cdd 100644
--- a/app/Providers/HorizonServiceProvider.php
+++ b/app/Providers/HorizonServiceProvider.php
@@ -75,21 +75,16 @@ class HorizonServiceProvider extends HorizonApplicationServiceProvider
protected function gate(): void
{
- Gate::define('viewHorizon', function ($user) {
- $root_user = User::find(0);
-
- // Get additional allowed emails from environment variable
- $allowedEmails = array_filter(
- array_map('trim', explode(',', env('HORIZON_ALLOWED_EMAILS', '')))
- );
-
- // Merge root user email with additional allowed emails
- $authorizedEmails = array_merge(
- [$root_user->email],
- $allowedEmails
- );
+ Gate::define('viewHorizon', function (User $user) {
+ if ($user->id === 0) {
+ return true;
+ }
- return in_array($user->email, $authorizedEmails);
+ return str(config()->string('horizon.allowed_emails'))
+ ->lower()
+ ->explode(',')
+ ->map(fn (string $email) => trim($email))
+ ->contains($user->email);
});
}
}
diff --git a/config/horizon.php b/config/horizon.php
index d178038496..d86c52affe 100644
--- a/config/horizon.php
+++ b/config/horizon.php
@@ -30,6 +30,18 @@ return [
'path' => env('HORIZON_PATH', 'horizon'),
+ /*
+ |--------------------------------------------------------------------------
+ | Horizon Allowed Emails
+ |--------------------------------------------------------------------------
+ |
+ | A comma-separated list of email addresses that may access the Horizon
+ | dashboard in addition to the root user.
+ |
+ */
+
+ 'allowed_emails' => env('HORIZON_ALLOWED_EMAILS', ''),
+
/*
|--------------------------------------------------------------------------
| Horizon Redis Connection