update controller & tests

This commit is contained in:
Vehikl 2025-03-20 16:38:34 -04:00
parent aaabfe43c0
commit 1d19ef2e08
2 changed files with 9 additions and 12 deletions

View File

@ -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);
}

View File

@ -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);
}
/**