Skip to content

Commit 8d02fb9

Browse files
committed
chore: Refactor API Tokens component to use isApiEnabled flag
1 parent c52fe57 commit 8d02fb9

File tree

2 files changed

+57
-50
lines changed

2 files changed

+57
-50
lines changed

app/Livewire/Security/ApiTokens.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ class ApiTokens extends Component
1717

1818
public array $permissions = ['read-only'];
1919

20-
public $instanceSettings;
20+
public $isApiEnabled;
2121

2222
public function render()
2323
{
24-
return view('livewire.security.api-tokens', [
25-
'instanceSettings' => $this->instanceSettings,
26-
]);
24+
return view('livewire.security.api-tokens');
2725
}
2826

2927
public function mount()
3028
{
31-
$this->instanceSettings = InstanceSettings::get();
29+
$this->isApiEnabled = InstanceSettings::get()->is_api_enabled;
3230
$this->tokens = auth()->user()->tokens->sortByDesc('created_at');
3331
}
3432

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,80 @@
11
<div>
22
<x-slot:title>
33
API Tokens | Coolify
4-
</x-slot>
5-
<x-security.navbar />
6-
<div class="pb-4 ">
7-
<h2>API Tokens</h2>
8-
@if (!$instanceSettings->is_api_enabled)
9-
<strong>API is disabled. If you want to use the API, please enable it in the Coolify Instance Settings.</strong>
10-
@else
4+
</x-slot>
5+
<x-security.navbar />
6+
<div class="pb-4">
7+
<h2>API Tokens</h2>
8+
@if (!$isApiEnabled)
9+
<div>API is disabled. If you want to use the API, please enable it in the Settings menu.</div>
10+
@else
1111
<div>Tokens are created with the current team as scope. You will only have access to this team's resources.
1212
</div>
13+
</div>
14+
<h3>New Token</h3>
15+
<form class="flex flex-col gap-2 pt-4" wire:submit='addNewToken'>
16+
<div class="flex gap-2 items-end">
17+
<x-forms.input required id="description" label="Description" />
18+
<x-forms.button type="submit">Create New Token</x-forms.button>
1319
</div>
14-
<h3>New Token</h3>
15-
<form class="flex flex-col gap-2 pt-4" wire:submit='addNewToken'>
16-
<div class="flex items-end gap-2">
17-
<x-forms.input required id="description" label="Description" />
18-
<x-forms.button type="submit">Create New Token</x-forms.button>
19-
</div>
20-
<div class="flex">
21-
Permissions
22-
<x-helper class="px-1" helper="These permissions will be granted to the token." /><span class="pr-1">:</span>
23-
<div class="flex gap-1 font-bold dark:text-white">
24-
@if ($permissions)
20+
<div class="flex">
21+
Permissions
22+
<x-helper class="px-1" helper="These permissions will be granted to the token." /><span
23+
class="pr-1">:</span>
24+
<div class="flex gap-1 font-bold dark:text-white">
25+
@if ($permissions)
2526
@foreach ($permissions as $permission)
26-
@if ($permission === '*')
27-
<div>All (root/admin access), be careful!</div>
28-
@else
29-
<div>{{ $permission }}</div>
30-
@endif
27+
@if ($permission === '*')
28+
<div>All (root/admin access), be careful!</div>
29+
@else
30+
<div>{{ $permission }}</div>
31+
@endif
3132
@endforeach
32-
@endif
33-
</div>
34-
</div>
35-
<h4>Token Permissions</h4>
36-
<div class="w-64">
37-
<x-forms.checkbox label="Read-only" wire:model.live="readOnly"></x-forms.checkbox>
38-
<x-forms.checkbox label="View Sensitive Data" wire:model.live="viewSensitiveData"></x-forms.checkbox>
33+
@endif
3934
</div>
40-
</form>
41-
@if (session()->has('token'))
35+
</div>
36+
<h4>Token Permissions</h4>
37+
<div class="w-64">
38+
<x-forms.checkbox label="Read-only" wire:model.live="readOnly"></x-forms.checkbox>
39+
<x-forms.checkbox label="View Sensitive Data" wire:model.live="viewSensitiveData"></x-forms.checkbox>
40+
</div>
41+
</form>
42+
@if (session()->has('token'))
4243
<div class="py-4 font-bold dark:text-warning">Please copy this token now. For your security, it won't be shown
4344
again.
4445
</div>
4546
<div class="pb-4 font-bold dark:text-white"> {{ session('token') }}</div>
46-
@endif
47-
<h3 class="py-4">Issued Tokens</h3>
48-
<div class="grid gap-2 lg:grid-cols-1">
49-
@forelse ($tokens as $token)
47+
@endif
48+
<h3 class="py-4">Issued Tokens</h3>
49+
<div class="grid gap-2 lg:grid-cols-1">
50+
@forelse ($tokens as $token)
5051
<div class="flex flex-col gap-1 p-2 border dark:border-coolgray-200 hover:no-underline">
5152
<div>Description: {{ $token->name }}</div>
5253
<div>Last used: {{ $token->last_used_at ? $token->last_used_at->diffForHumans() : 'Never' }}</div>
5354
<div class="flex gap-1">
5455
@if ($token->abilities)
55-
Abilities:
56-
@foreach ($token->abilities as $ability)
57-
<div class="font-bold dark:text-white">{{ $ability }}</div>
58-
@endforeach
56+
Abilities:
57+
@foreach ($token->abilities as $ability)
58+
<div class="font-bold dark:text-white">{{ $ability }}</div>
59+
@endforeach
5960
@endif
6061
</div>
6162

62-
<x-modal-confirmation title="Confirm API Token Revocation?" isErrorButton buttonTitle="Revoke token" submitAction="revoke({{ data_get($token, 'id') }})" :actions="['This API Token will be revoked and permanently deleted.', 'Any API call made with this token will fail.']" confirmationText="{{ $token->name }}" confirmationLabel="Please confirm the execution of the actions by entering the API Token Description below" shortConfirmationLabel="API Token Description" :confirmWithPassword="false" step2ButtonText="Revoke API Token" />
63+
<x-modal-confirmation title="Confirm API Token Revocation?" isErrorButton buttonTitle="Revoke token"
64+
submitAction="revoke({{ data_get($token, 'id') }})" :actions="[
65+
'This API Token will be revoked and permanently deleted.',
66+
'Any API call made with this token will fail.',
67+
]"
68+
confirmationText="{{ $token->name }}"
69+
confirmationLabel="Please confirm the execution of the actions by entering the API Token Description below"
70+
shortConfirmationLabel="API Token Description" :confirmWithPassword="false"
71+
step2ButtonText="Revoke API Token" />
6372
</div>
64-
@empty
73+
@empty
6574
<div>
6675
<div>No API tokens found.</div>
6776
</div>
68-
@endforelse
69-
</div>
70-
@endif
77+
@endforelse
78+
</div>
79+
@endif
7180
</div>

0 commit comments

Comments
 (0)