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
|
public function description(DescriptionServerRequest $request, Server $server): JsonResponse
|
||||||
{
|
{
|
||||||
$description = $request->has('description') ? $request->input('description') : $server->description;
|
if (config('panel.editable_server_descriptions')) {
|
||||||
|
return new JsonResponse([], Response::HTTP_FORBIDDEN);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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);
|
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,11 +21,9 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||||||
/** @var \App\Models\Server $server */
|
/** @var \App\Models\Server $server */
|
||||||
[$user, $server] = $this->generateTestAccount($permissions);
|
[$user, $server] = $this->generateTestAccount($permissions);
|
||||||
$originalName = $server->name;
|
$originalName = $server->name;
|
||||||
$originalDescription = $server->description;
|
|
||||||
|
|
||||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'description' => '',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
|
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||||
@ -33,18 +31,15 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||||||
|
|
||||||
$server = $server->refresh();
|
$server = $server->refresh();
|
||||||
$this->assertSame($originalName, $server->name);
|
$this->assertSame($originalName, $server->name);
|
||||||
$this->assertSame($originalDescription, $server->description);
|
|
||||||
|
|
||||||
$this->actingAs($user)
|
$this->actingAs($user)
|
||||||
->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
||||||
'name' => 'Test Server Name',
|
'name' => 'Test Server Name',
|
||||||
'description' => 'This is a test server.',
|
|
||||||
])
|
])
|
||||||
->assertStatus(Response::HTTP_NO_CONTENT);
|
->assertStatus(Response::HTTP_NO_CONTENT);
|
||||||
|
|
||||||
$server = $server->refresh();
|
$server = $server->refresh();
|
||||||
$this->assertSame('Test Server Name', $server->name);
|
$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