Skip to content

Commit c4e702f

Browse files
committed
fix: able to select root permission easier
1 parent e91939a commit c4e702f

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

app/Livewire/Security/ApiTokens.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class ApiTokens extends Component
1515

1616
public bool $readOnly = true;
1717

18+
public bool $rootAccess = false;
19+
1820
public array $permissions = ['read-only'];
1921

2022
public $isApiEnabled;
@@ -35,24 +37,42 @@ public function updatedViewSensitiveData()
3537
if ($this->viewSensitiveData) {
3638
$this->permissions[] = 'view:sensitive';
3739
$this->permissions = array_diff($this->permissions, ['*']);
40+
$this->rootAccess = false;
3841
} else {
3942
$this->permissions = array_diff($this->permissions, ['view:sensitive']);
4043
}
41-
if (count($this->permissions) == 0) {
42-
$this->permissions = ['*'];
43-
}
44+
$this->makeSureOneIsSelected();
4445
}
4546

4647
public function updatedReadOnly()
4748
{
4849
if ($this->readOnly) {
4950
$this->permissions[] = 'read-only';
5051
$this->permissions = array_diff($this->permissions, ['*']);
52+
$this->rootAccess = false;
5153
} else {
5254
$this->permissions = array_diff($this->permissions, ['read-only']);
5355
}
54-
if (count($this->permissions) == 0) {
56+
$this->makeSureOneIsSelected();
57+
}
58+
59+
public function updatedRootAccess()
60+
{
61+
if ($this->rootAccess) {
5562
$this->permissions = ['*'];
63+
$this->readOnly = false;
64+
$this->viewSensitiveData = false;
65+
} else {
66+
$this->readOnly = true;
67+
$this->permissions = ['read-only'];
68+
}
69+
}
70+
71+
public function makeSureOneIsSelected()
72+
{
73+
if (count($this->permissions) == 0) {
74+
$this->permissions = ['read-only'];
75+
$this->readOnly = true;
5676
}
5777
}
5878

@@ -62,12 +82,6 @@ public function addNewToken()
6282
$this->validate([
6383
'description' => 'required|min:3|max:255',
6484
]);
65-
// if ($this->viewSensitiveData) {
66-
// $this->permissions[] = 'view:sensitive';
67-
// }
68-
// if ($this->readOnly) {
69-
// $this->permissions[] = 'read-only';
70-
// }
7185
$token = auth()->user()->createToken($this->description, $this->permissions);
7286
$this->tokens = auth()->user()->tokens;
7387
session()->flash('token', $token->plainTextToken);

resources/views/livewire/security/api-tokens.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
<div class="pb-4">
77
<h2>API Tokens</h2>
88
@if (!$isApiEnabled)
9-
<div>API is disabled. If you want to use the API, please enable it in the <a href="{{ route('settings.index') }}" class="underline dark:text-white">Settings</a> menu.</div>
9+
<div>API is disabled. If you want to use the API, please enable it in the <a
10+
href="{{ route('settings.index') }}" class="underline dark:text-white">Settings</a> menu.</div>
1011
@else
1112
<div>Tokens are created with the current team as scope. You will only have access to this team's resources.
1213
</div>
@@ -25,7 +26,7 @@ class="pr-1">:</span>
2526
@if ($permissions)
2627
@foreach ($permissions as $permission)
2728
@if ($permission === '*')
28-
<div>All (root/admin access), be careful!</div>
29+
<div>Root access, be careful!</div>
2930
@else
3031
<div>{{ $permission }}</div>
3132
@endif
@@ -35,6 +36,7 @@ class="pr-1">:</span>
3536
</div>
3637
<h4>Token Permissions</h4>
3738
<div class="w-64">
39+
<x-forms.checkbox label="Root Access" wire:model.live="rootAccess"></x-forms.checkbox>
3840
<x-forms.checkbox label="Read-only" wire:model.live="readOnly"></x-forms.checkbox>
3941
<x-forms.checkbox label="View Sensitive Data" wire:model.live="viewSensitiveData"></x-forms.checkbox>
4042
</div>

0 commit comments

Comments
 (0)