diff --git a/app/Http/Controllers/Api/Client/Servers/SettingsController.php b/app/Http/Controllers/Api/Client/Servers/SettingsController.php index 7f1946a21..d1377d67a 100644 --- a/app/Http/Controllers/Api/Client/Servers/SettingsController.php +++ b/app/Http/Controllers/Api/Client/Servers/SettingsController.php @@ -36,6 +36,7 @@ class SettingsController extends ClientApiController { $this->repository->update($server->id, [ 'name' => $request->input('name'), + 'description' => $request->input('description') ?? '', ]); if ($server->name !== $request->input('name')) { diff --git a/app/Http/Requests/Api/Client/Servers/Settings/RenameServerRequest.php b/app/Http/Requests/Api/Client/Servers/Settings/RenameServerRequest.php index 8cb5efa35..4a74f0a0e 100644 --- a/app/Http/Requests/Api/Client/Servers/Settings/RenameServerRequest.php +++ b/app/Http/Requests/Api/Client/Servers/Settings/RenameServerRequest.php @@ -11,7 +11,7 @@ class RenameServerRequest extends ClientApiRequest implements ClientPermissionsR { /** * Returns the permissions string indicating which permission should be used to - * validate that the authenticated user has permission to perform this action aganist + * validate that the authenticated user has permission to perform this action against * the given resource (server). */ public function permission(): string @@ -26,6 +26,7 @@ class RenameServerRequest extends ClientApiRequest implements ClientPermissionsR { return [ 'name' => Server::getRules()['name'], + 'description' => 'string|nullable', ]; } } diff --git a/app/Models/Permission.php b/app/Models/Permission.php index 6d27a90d3..b2e00070e 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -195,7 +195,7 @@ class Permission extends Model 'settings' => [ 'description' => 'Permissions that control a user\'s access to the settings for this server.', 'keys' => [ - 'rename' => 'Allows a user to rename this server.', + 'rename' => 'Allows a user to rename this server and change the description of it.', 'reinstall' => 'Allows a user to trigger a reinstall of this server.', ], ], diff --git a/resources/lang/en/activity.php b/resources/lang/en/activity.php index afa655806..501a1dcde 100644 --- a/resources/lang/en/activity.php +++ b/resources/lang/en/activity.php @@ -115,6 +115,7 @@ return [ ], 'settings' => [ 'rename' => 'Renamed the server from :old to :new', + 'description' => 'Changed the server description from :old to :new', ], 'startup' => [ 'edit' => 'Changed the :variable variable from ":old" to ":new"', diff --git a/resources/scripts/api/server/renameServer.ts b/resources/scripts/api/server/renameServer.ts index a4a95141e..4622f9d4d 100644 --- a/resources/scripts/api/server/renameServer.ts +++ b/resources/scripts/api/server/renameServer.ts @@ -1,8 +1,8 @@ import http from '@/api/http'; -export default (uuid: string, name: string): Promise => { +export default (uuid: string, name: string, description?: string): Promise => { return new Promise((resolve, reject) => { - http.post(`/api/client/servers/${uuid}/settings/rename`, { name }) + http.post(`/api/client/servers/${uuid}/settings/rename`, { name, description }) .then(() => resolve()) .catch(reject); }); diff --git a/resources/scripts/components/server/settings/RenameServerBox.tsx b/resources/scripts/components/server/settings/RenameServerBox.tsx index 98be2ef9f..9cb290a1a 100644 --- a/resources/scripts/components/server/settings/RenameServerBox.tsx +++ b/resources/scripts/components/server/settings/RenameServerBox.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { ServerContext } from '@/state/server'; import TitledGreyBox from '@/components/elements/TitledGreyBox'; -import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; +import { Field as FormikField, Form, Formik, FormikHelpers, useFormikContext } from 'formik'; import { Actions, useStoreActions } from 'easy-peasy'; import renameServer from '@/api/server/renameServer'; import Field from '@/components/elements/Field'; @@ -11,19 +11,29 @@ import { ApplicationStore } from '@/state'; import { httpErrorToHuman } from '@/api/http'; import { Button } from '@/components/elements/button/index'; import tw from 'twin.macro'; +import Label from '@/components/elements/Label'; +import FormikFieldWrapper from '@/components/elements/FormikFieldWrapper'; +import { Textarea } from '@/components/elements/Input'; interface Values { name: string; + description: string; } const RenameServerBox = () => { const { isSubmitting } = useFormikContext(); return ( - +
+
+ + + + +
@@ -37,10 +47,10 @@ export default () => { const setServer = ServerContext.useStoreActions((actions) => actions.server.setServer); const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); - const submit = ({ name }: Values, { setSubmitting }: FormikHelpers) => { + const submit = ({ name, description }: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('settings'); - renameServer(server.uuid, name) - .then(() => setServer({ ...server, name })) + renameServer(server.uuid, name, description) + .then(() => setServer({ ...server, name, description })) .catch((error) => { console.error(error); addError({ key: 'settings', message: httpErrorToHuman(error) }); @@ -53,9 +63,11 @@ export default () => { onSubmit={submit} initialValues={{ name: server.name, + description: server.description, }} validationSchema={object().shape({ name: string().required().min(1), + description: string().nullable(), })} > diff --git a/tests/Integration/Api/Client/Server/SettingsControllerTest.php b/tests/Integration/Api/Client/Server/SettingsControllerTest.php index c92754cfa..882314bea 100644 --- a/tests/Integration/Api/Client/Server/SettingsControllerTest.php +++ b/tests/Integration/Api/Client/Server/SettingsControllerTest.php @@ -21,9 +21,11 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase /** @var \Pterodactyl\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); @@ -31,15 +33,18 @@ 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); } /**