Feat: If API is disabeled do not show API token creation stuff
This commit is contained in:
		| @@ -2,6 +2,7 @@ | |||||||
| 
 | 
 | ||||||
| namespace App\Livewire\Security; | namespace App\Livewire\Security; | ||||||
| 
 | 
 | ||||||
|  | use App\Models\InstanceSettings; | ||||||
| use Livewire\Component; | use Livewire\Component; | ||||||
| 
 | 
 | ||||||
| class ApiTokens extends Component | class ApiTokens extends Component | ||||||
| @@ -16,13 +17,18 @@ class ApiTokens extends Component | |||||||
| 
 | 
 | ||||||
|     public array $permissions = ['read-only']; |     public array $permissions = ['read-only']; | ||||||
| 
 | 
 | ||||||
|  |     public $instanceSettings; | ||||||
|  | 
 | ||||||
|     public function render() |     public function render() | ||||||
|     { |     { | ||||||
|         return view('livewire.security.api-tokens'); |         return view('livewire.security.api-tokens', [ | ||||||
|  |             'instanceSettings' => $this->instanceSettings, | ||||||
|  |         ]); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function mount() |     public function mount() | ||||||
|     { |     { | ||||||
|  |         $this->instanceSettings = InstanceSettings::get(); | ||||||
|         $this->tokens = auth()->user()->tokens->sortByDesc('created_at'); |         $this->tokens = auth()->user()->tokens->sortByDesc('created_at'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|   | |||||||
| @@ -5,6 +5,9 @@ | |||||||
|         <x-security.navbar /> |         <x-security.navbar /> | ||||||
|         <div class="pb-4 "> |         <div class="pb-4 "> | ||||||
|             <h2>API Tokens</h2> |             <h2>API Tokens</h2> | ||||||
|  |             @if (!$instanceSettings->is_api_enabled) | ||||||
|  |             <strong>API is disabled. If you want to use API, please enable it in the Instance Settings.</strong> | ||||||
|  |             @else | ||||||
|             <div>Tokens are created with the current team as scope. You will only have access to this team's resources. |             <div>Tokens are created with the current team as scope. You will only have access to this team's resources. | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
| @@ -15,8 +18,8 @@ | |||||||
|                 <x-forms.button type="submit">Create New Token</x-forms.button> |                 <x-forms.button type="submit">Create New Token</x-forms.button> | ||||||
|             </div> |             </div> | ||||||
|             <div class="flex"> |             <div class="flex"> | ||||||
|             Permissions <x-helper class="px-1" helper="These permissions will be granted to the token." /><span |                 Permissions | ||||||
|                 class="pr-1">:</span> |                 <x-helper class="px-1" helper="These permissions will be granted to the token." /><span class="pr-1">:</span> | ||||||
|                 <div class="flex gap-1 font-bold dark:text-white"> |                 <div class="flex gap-1 font-bold dark:text-white"> | ||||||
|                     @if ($permissions) |                     @if ($permissions) | ||||||
|                     @foreach ($permissions as $permission) |                     @foreach ($permissions as $permission) | ||||||
| @@ -56,18 +59,7 @@ | |||||||
|                     @endif |                     @endif | ||||||
|                 </div> |                 </div> | ||||||
| 
 | 
 | ||||||
|                 <x-modal-confirmation  |                 <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" /> | ||||||
|                     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" |  | ||||||
|                 /> |  | ||||||
|             </div> |             </div> | ||||||
|             @empty |             @empty | ||||||
|             <div> |             <div> | ||||||
| @@ -75,5 +67,5 @@ | |||||||
|             </div> |             </div> | ||||||
|             @endforelse |             @endforelse | ||||||
|         </div> |         </div> | ||||||
| 
 |         @endif | ||||||
| </div> | </div> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 peaklabs-dev
					peaklabs-dev