refactor is_instance_admin

This commit is contained in:
Andras Bacsai 2023-08-14 16:56:13 +02:00
parent f8506f9d20
commit 952d335789
9 changed files with 29 additions and 16 deletions

View File

@ -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) {

View File

@ -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(),

View File

@ -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()) {

View File

@ -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 {

View File

@ -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;
}

View File

@ -25,7 +25,7 @@
<body>
@livewireScripts
<x-toaster-hub />
@if (auth()->user()->isInstanceAdmin() || is_subscription_in_grace_period())
@if (is_instance_admin() || is_subscription_in_grace_period())
<div class="fixed top-3 left-4" id="vue">
<magic-bar></magic-bar>
</div>

View File

@ -51,7 +51,7 @@ class="{{ request()->is('command-center') ? 'text-warning icon' : 'icon' }}" vie
</a>
</li>
<div class="flex-1"></div>
@if (auth()->user()->isInstanceAdmin())
@if (is_instance_admin())
<livewire:upgrade />
@endif
<li title="Profile">
@ -79,7 +79,7 @@ class="{{ request()->is('command-center') ? 'text-warning icon' : 'icon' }}" vie
</svg>
</a>
</li>
@if (auth()->user()->isInstanceAdmin())
@if (is_instance_admin())
<li title="Settings" class="mt-auto">
<a class="hover:bg-transparent" @if (!request()->is('settings')) href="/settings" @endif>
<svg xmlns="http://www.w3.org/2000/svg"

View File

@ -16,7 +16,7 @@
<x-forms.button type="submit">
Save
</x-forms.button>
@if (auth()->user()->isInstanceAdmin())
@if (is_instance_admin())
<x-forms.button wire:click='copyFromInstanceSettings'>
Copy from Instance Settings
</x-forms.button>

View File

@ -26,7 +26,7 @@
<h3 class="pb-4">Invite a new member</h3>
@else
<h3>Invite a new member</h3>
@if (auth()->user()->isInstanceAdmin())
@if (is_instance_admin())
<div class="pb-4 text-xs text-warning">You need to configure <a href="/settings/emails"
class="underline text-warning">Transactional
Emails</a>