mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 10:54:46 +02:00
update controller & tests
This commit is contained in:
parent
aaabfe43c0
commit
1d19ef2e08
@ -52,15 +52,17 @@ class SettingsController extends ClientApiController
|
||||
*/
|
||||
public function description(DescriptionServerRequest $request, Server $server): JsonResponse
|
||||
{
|
||||
$description = $request->has('description') ? $request->input('description') : $server->description;
|
||||
|
||||
if ($server->description !== $description && config('panel.editable_server_descriptions')) {
|
||||
$server->update(['description' => $description]);
|
||||
Activity::event('server:settings.description')
|
||||
->property(['old' => $server->description, 'new' => $description])
|
||||
->log();
|
||||
if (config('panel.editable_server_descriptions')) {
|
||||
return new JsonResponse([], Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
$description = $request->input('description');
|
||||
$server->update(['description' => $description ?? '']);
|
||||
|
||||
Activity::event('server:settings.description')
|
||||
->property(['old' => $server->getOriginal('description'), 'new' => $description])
|
||||
->log();
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,9 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
||||
/** @var \App\Models\Server $server */
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
$originalName = $server->name;
|
||||
$originalDescription = $server->description;
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
||||
'name' => '',
|
||||
'description' => '',
|
||||
]);
|
||||
|
||||
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
@ -33,18 +31,15 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
||||
|
||||
$server = $server->refresh();
|
||||
$this->assertSame($originalName, $server->name);
|
||||
$this->assertSame($originalDescription, $server->description);
|
||||
|
||||
$this->actingAs($user)
|
||||
->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
||||
'name' => 'Test Server Name',
|
||||
'description' => 'This is a test server.',
|
||||
])
|
||||
->assertStatus(Response::HTTP_NO_CONTENT);
|
||||
|
||||
$server = $server->refresh();
|
||||
$this->assertSame('Test Server Name', $server->name);
|
||||
$this->assertSame('This is a test server.', $server->description);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user