mirror of
https://github.com/pelican-dev/panel.git
synced 2025-12-08 18:30:15 +01:00
Delete ssh keys shouldn't be a POST & Cleanup routes (#1934)
This commit is contained in:
parent
78ab098d02
commit
d0af45a0c7
@ -55,23 +55,19 @@ class SSHKeyController extends ClientApiController
|
|||||||
*
|
*
|
||||||
* Deletes an SSH key from the user's account.
|
* Deletes an SSH key from the user's account.
|
||||||
*/
|
*/
|
||||||
public function delete(ClientApiRequest $request): JsonResponse
|
public function delete(ClientApiRequest $request, string $fingerprint): JsonResponse
|
||||||
{
|
{
|
||||||
$request->validate(['fingerprint' => ['required', 'string']]);
|
/** @var UserSSHKey $key */
|
||||||
|
|
||||||
/** @var ?UserSSHKey $key */
|
|
||||||
$key = $request->user()->sshKeys()
|
$key = $request->user()->sshKeys()
|
||||||
->where('fingerprint', $request->input('fingerprint'))
|
->where('fingerprint', $fingerprint)
|
||||||
->first();
|
->firstOrFail();
|
||||||
|
|
||||||
if (!is_null($key)) {
|
|
||||||
$key->delete();
|
|
||||||
|
|
||||||
Activity::event('user:ssh-key.delete')
|
Activity::event('user:ssh-key.delete')
|
||||||
->subject($key)
|
->subject($key)
|
||||||
->property('fingerprint', $key->fingerprint)
|
->property('fingerprint', $key->fingerprint)
|
||||||
->log();
|
->log();
|
||||||
}
|
|
||||||
|
$key->delete();
|
||||||
|
|
||||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,14 +27,16 @@ Route::prefix('/account')->middleware(AccountSubject::class)->group(function ()
|
|||||||
|
|
||||||
Route::get('/activity', Client\ActivityLogController::class)->name('api:client.account.activity');
|
Route::get('/activity', Client\ActivityLogController::class)->name('api:client.account.activity');
|
||||||
|
|
||||||
Route::get('/api-keys', [Client\ApiKeyController::class, 'index']);
|
Route::prefix('/api-keys')->group(function () {
|
||||||
Route::post('/api-keys', [Client\ApiKeyController::class, 'store']);
|
Route::get('/', [Client\ApiKeyController::class, 'index']);
|
||||||
Route::delete('/api-keys/{identifier}', [Client\ApiKeyController::class, 'delete']);
|
Route::post('/', [Client\ApiKeyController::class, 'store']);
|
||||||
|
Route::delete('/{identifier}', [Client\ApiKeyController::class, 'delete']);
|
||||||
|
});
|
||||||
|
|
||||||
Route::prefix('/ssh-keys')->group(function () {
|
Route::prefix('/ssh-keys')->group(function () {
|
||||||
Route::get('/', [Client\SSHKeyController::class, 'index']);
|
Route::get('/', [Client\SSHKeyController::class, 'index']);
|
||||||
Route::post('/', [Client\SSHKeyController::class, 'store']);
|
Route::post('/', [Client\SSHKeyController::class, 'store']);
|
||||||
Route::post('/remove', [Client\SSHKeyController::class, 'delete']);
|
Route::delete('/{fingerprint}', [Client\SSHKeyController::class, 'delete']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -91,12 +93,12 @@ Route::prefix('/servers/{server:uuid}')->middleware([ServerSubject::class, Authe
|
|||||||
Route::delete('/{schedule}/tasks/{task}', [Client\Servers\ScheduleTaskController::class, 'delete']);
|
Route::delete('/{schedule}/tasks/{task}', [Client\Servers\ScheduleTaskController::class, 'delete']);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('/network')->group(function () {
|
Route::prefix('/network/allocations')->group(function () {
|
||||||
Route::get('/allocations', [Client\Servers\NetworkAllocationController::class, 'index']);
|
Route::get('/', [Client\Servers\NetworkAllocationController::class, 'index']);
|
||||||
Route::post('/allocations', [Client\Servers\NetworkAllocationController::class, 'store']);
|
Route::post('/', [Client\Servers\NetworkAllocationController::class, 'store']);
|
||||||
Route::post('/allocations/{allocation}', [Client\Servers\NetworkAllocationController::class, 'update']);
|
Route::post('/{allocation}', [Client\Servers\NetworkAllocationController::class, 'update']);
|
||||||
Route::post('/allocations/{allocation}/primary', [Client\Servers\NetworkAllocationController::class, 'setPrimary']);
|
Route::post('/{allocation}/primary', [Client\Servers\NetworkAllocationController::class, 'setPrimary']);
|
||||||
Route::delete('/allocations/{allocation}', [Client\Servers\NetworkAllocationController::class, 'delete']);
|
Route::delete('/{allocation}', [Client\Servers\NetworkAllocationController::class, 'delete']);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('/users')->group(function () {
|
Route::prefix('/users')->group(function () {
|
||||||
|
|||||||
@ -40,20 +40,13 @@ class SSHKeyControllerTest extends ClientApiIntegrationTestCase
|
|||||||
$key = UserSSHKey::factory()->for($user)->create();
|
$key = UserSSHKey::factory()->for($user)->create();
|
||||||
$key2 = UserSSHKey::factory()->for($user2)->create();
|
$key2 = UserSSHKey::factory()->for($user2)->create();
|
||||||
|
|
||||||
$endpoint = '/api/client/account/ssh-keys/remove';
|
|
||||||
|
|
||||||
$this->actingAs($user);
|
$this->actingAs($user);
|
||||||
$this->postJson($endpoint)
|
$this->delete('/api/client/account/ssh-keys/' . $key->fingerprint)->assertNoContent();
|
||||||
->assertUnprocessable()
|
|
||||||
->assertJsonPath('errors.0.meta', ['source_field' => 'fingerprint', 'rule' => 'required']);
|
|
||||||
|
|
||||||
$this->postJson($endpoint, ['fingerprint' => $key->fingerprint])->assertNoContent();
|
|
||||||
|
|
||||||
$this->assertSoftDeleted($key);
|
$this->assertSoftDeleted($key);
|
||||||
$this->assertNotSoftDeleted($key2);
|
$this->assertNotSoftDeleted($key2);
|
||||||
|
|
||||||
$this->postJson($endpoint, ['fingerprint' => $key->fingerprint])->assertNoContent();
|
$this->delete('/api/client/account/ssh-keys/' . $key2->fingerprint)->assertNotFound();
|
||||||
$this->postJson($endpoint, ['fingerprint' => $key2->fingerprint])->assertNoContent();
|
|
||||||
|
|
||||||
$this->assertNotSoftDeleted($key2);
|
$this->assertNotSoftDeleted($key2);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user