diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 7284277e8..9c39b3a03 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -59,7 +59,7 @@ public function dashboard() public function settings() { - if (auth()->user()->isInstanceAdmin()) { + if (is_instance_admin()) { $settings = InstanceSettings::get(); $database = StandalonePostgresql::whereName('coolify-db')->first(); if ($database) { diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index dc98fc258..e7f9feb57 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -12,7 +12,7 @@ class ServerController extends Controller public function new_server() { - if (!is_cloud()) { + if (!is_cloud() || is_instance_admin()) { return view('server.create', [ 'limit_reached' => false, 'private_keys' => PrivateKey::ownedByCurrentTeam()->get(), diff --git a/app/Http/Middleware/SubscriptionValid.php b/app/Http/Middleware/SubscriptionValid.php index 7d6cd5cfa..4c9d7b940 100644 --- a/app/Http/Middleware/SubscriptionValid.php +++ b/app/Http/Middleware/SubscriptionValid.php @@ -10,16 +10,20 @@ class SubscriptionValid { public function handle(Request $request, Closure $next): Response { - $is_instance_admin = auth()->user()?->isInstanceAdmin(); if (!auth()->user() || !is_cloud()) { - if ($request->path() === 'subscription' && !$is_instance_admin) { + if ($request->path() === 'subscription') { return redirect('/'); } else { return $next($request); } } - if (is_subscription_active() && $request->path() === 'subscription' && !$is_instance_admin) { + $is_instance_admin = is_instance_admin(); + if ($is_instance_admin) { + return $next($request); + } + + if (is_subscription_active() && $request->path() === 'subscription') { return redirect('/'); } if (is_subscription_in_grace_period()) { diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index e6a8eed91..14b6ed75a 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -29,6 +29,11 @@ function generate_readme_file(string $name, string $updated_at): string return "Resource name: $name\nLatest Deployment Date: $updated_at"; } +function is_instance_admin() +{ + return auth()->user()?->isInstanceAdmin(); +} + function general_error_handler(Throwable|null $err = null, $that = null, $isJson = false, $customErrorMessage = null): mixed { try { diff --git a/bootstrap/helpers/subscriptions.php b/bootstrap/helpers/subscriptions.php index d362591b7..90d0947ad 100644 --- a/bootstrap/helpers/subscriptions.php +++ b/bootstrap/helpers/subscriptions.php @@ -46,19 +46,21 @@ function getEndDate() function is_subscription_active() { $team = auth()->user()?->currentTeam(); + if (!$team) { return false; } + if (is_instance_admin()) { + return true; + } $subscription = $team?->subscription; + if (!$subscription) { return false; } - $is_active = $subscription->lemon_status === 'active'; - $is_instance_admin = auth()->user()->isInstanceAdmin(); - ray($is_instance_admin); - return $is_active || $is_instance_admin; + return $is_active; } function is_subscription_in_grace_period() { @@ -66,13 +68,15 @@ function is_subscription_in_grace_period() if (!$team) { return false; } + if (is_instance_admin()) { + return true; + } $subscription = $team?->subscription; if (!$subscription) { return false; } - $is_instance_admin = auth()->user()->isInstanceAdmin(); $is_still_grace_period = $subscription->lemon_ends_at && Carbon::parse($subscription->lemon_ends_at) > Carbon::now(); - return $is_still_grace_period || $is_instance_admin; + return $is_still_grace_period; } diff --git a/resources/views/components/layout-subscription.blade.php b/resources/views/components/layout-subscription.blade.php index b2b8f67de..b479b29e2 100644 --- a/resources/views/components/layout-subscription.blade.php +++ b/resources/views/components/layout-subscription.blade.php @@ -25,7 +25,7 @@ @livewireScripts - @if (auth()->user()->isInstanceAdmin() || is_subscription_in_grace_period()) + @if (is_instance_admin() || is_subscription_in_grace_period())
diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index e0fd6e22e..11c297ecd 100644 --- a/resources/views/components/navbar.blade.php +++ b/resources/views/components/navbar.blade.php @@ -51,7 +51,7 @@ class="{{ request()->is('command-center') ? 'text-warning icon' : 'icon' }}" vie
- @if (auth()->user()->isInstanceAdmin()) + @if (is_instance_admin()) @endif
  • @@ -79,7 +79,7 @@ class="{{ request()->is('command-center') ? 'text-warning icon' : 'icon' }}" vie
  • - @if (auth()->user()->isInstanceAdmin()) + @if (is_instance_admin())
  • is('settings')) href="/settings" @endif> Save - @if (auth()->user()->isInstanceAdmin()) + @if (is_instance_admin()) Copy from Instance Settings diff --git a/resources/views/team/members.blade.php b/resources/views/team/members.blade.php index 011614194..9cb8fa2e8 100644 --- a/resources/views/team/members.blade.php +++ b/resources/views/team/members.blade.php @@ -26,7 +26,7 @@

    Invite a new member

    @else

    Invite a new member

    - @if (auth()->user()->isInstanceAdmin()) + @if (is_instance_admin())