Skip to content

Commit f2095e8

Browse files
authored
Allow users to change the server description (pterodactyl#4420)
1 parent b1abae8 commit f2095e8

File tree

7 files changed

+29
-9
lines changed

7 files changed

+29
-9
lines changed

app/Http/Controllers/Api/Client/Servers/SettingsController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function rename(RenameServerRequest $request, Server $server): JsonRespon
3636
{
3737
$this->repository->update($server->id, [
3838
'name' => $request->input('name'),
39+
'description' => $request->input('description') ?? '',
3940
]);
4041

4142
if ($server->name !== $request->input('name')) {

app/Http/Requests/Api/Client/Servers/Settings/RenameServerRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class RenameServerRequest extends ClientApiRequest implements ClientPermissionsR
1111
{
1212
/**
1313
* Returns the permissions string indicating which permission should be used to
14-
* validate that the authenticated user has permission to perform this action aganist
14+
* validate that the authenticated user has permission to perform this action against
1515
* the given resource (server).
1616
*/
1717
public function permission(): string
@@ -26,6 +26,7 @@ public function rules(): array
2626
{
2727
return [
2828
'name' => Server::getRules()['name'],
29+
'description' => 'string|nullable',
2930
];
3031
}
3132
}

app/Models/Permission.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class Permission extends Model
195195
'settings' => [
196196
'description' => 'Permissions that control a user\'s access to the settings for this server.',
197197
'keys' => [
198-
'rename' => 'Allows a user to rename this server.',
198+
'rename' => 'Allows a user to rename this server and change the description of it.',
199199
'reinstall' => 'Allows a user to trigger a reinstall of this server.',
200200
],
201201
],

resources/lang/en/activity.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
],
116116
'settings' => [
117117
'rename' => 'Renamed the server from :old to :new',
118+
'description' => 'Changed the server description from :old to :new',
118119
],
119120
'startup' => [
120121
'edit' => 'Changed the :variable variable from ":old" to ":new"',

resources/scripts/api/server/renameServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import http from '@/api/http';
22

3-
export default (uuid: string, name: string): Promise<void> => {
3+
export default (uuid: string, name: string, description?: string): Promise<void> => {
44
return new Promise((resolve, reject) => {
5-
http.post(`/api/client/servers/${uuid}/settings/rename`, { name })
5+
http.post(`/api/client/servers/${uuid}/settings/rename`, { name, description })
66
.then(() => resolve())
77
.catch(reject);
88
});

resources/scripts/components/server/settings/RenameServerBox.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { ServerContext } from '@/state/server';
33
import TitledGreyBox from '@/components/elements/TitledGreyBox';
4-
import { Form, Formik, FormikHelpers, useFormikContext } from 'formik';
4+
import { Field as FormikField, Form, Formik, FormikHelpers, useFormikContext } from 'formik';
55
import { Actions, useStoreActions } from 'easy-peasy';
66
import renameServer from '@/api/server/renameServer';
77
import Field from '@/components/elements/Field';
@@ -11,19 +11,29 @@ import { ApplicationStore } from '@/state';
1111
import { httpErrorToHuman } from '@/api/http';
1212
import { Button } from '@/components/elements/button/index';
1313
import tw from 'twin.macro';
14+
import Label from '@/components/elements/Label';
15+
import FormikFieldWrapper from '@/components/elements/FormikFieldWrapper';
16+
import { Textarea } from '@/components/elements/Input';
1417

1518
interface Values {
1619
name: string;
20+
description: string;
1721
}
1822

1923
const RenameServerBox = () => {
2024
const { isSubmitting } = useFormikContext<Values>();
2125

2226
return (
23-
<TitledGreyBox title={'Change Server Name'} css={tw`relative`}>
27+
<TitledGreyBox title={'Change Server Details'} css={tw`relative`}>
2428
<SpinnerOverlay visible={isSubmitting} />
2529
<Form css={tw`mb-0`}>
2630
<Field id={'name'} name={'name'} label={'Server Name'} type={'text'} />
31+
<div css={tw`mt-6`}>
32+
<Label>Server Description</Label>
33+
<FormikFieldWrapper name={'description'}>
34+
<FormikField as={Textarea} name={'description'} rows={3} />
35+
</FormikFieldWrapper>
36+
</div>
2737
<div css={tw`mt-6 text-right`}>
2838
<Button type={'submit'}>Save</Button>
2939
</div>
@@ -37,10 +47,10 @@ export default () => {
3747
const setServer = ServerContext.useStoreActions((actions) => actions.server.setServer);
3848
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
3949

40-
const submit = ({ name }: Values, { setSubmitting }: FormikHelpers<Values>) => {
50+
const submit = ({ name, description }: Values, { setSubmitting }: FormikHelpers<Values>) => {
4151
clearFlashes('settings');
42-
renameServer(server.uuid, name)
43-
.then(() => setServer({ ...server, name }))
52+
renameServer(server.uuid, name, description)
53+
.then(() => setServer({ ...server, name, description }))
4454
.catch((error) => {
4555
console.error(error);
4656
addError({ key: 'settings', message: httpErrorToHuman(error) });
@@ -53,9 +63,11 @@ export default () => {
5363
onSubmit={submit}
5464
initialValues={{
5565
name: server.name,
66+
description: server.description,
5667
}}
5768
validationSchema={object().shape({
5869
name: string().required().min(1),
70+
description: string().nullable(),
5971
})}
6072
>
6173
<RenameServerBox />

tests/Integration/Api/Client/Server/SettingsControllerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,30 @@ public function testServerNameCanBeChanged(array $permissions)
2121
/** @var \Pterodactyl\Models\Server $server */
2222
[$user, $server] = $this->generateTestAccount($permissions);
2323
$originalName = $server->name;
24+
$originalDescription = $server->description;
2425

2526
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/settings/rename", [
2627
'name' => '',
28+
'description' => '',
2729
]);
2830

2931
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
3032
$response->assertJsonPath('errors.0.meta.rule', 'required');
3133

3234
$server = $server->refresh();
3335
$this->assertSame($originalName, $server->name);
36+
$this->assertSame($originalDescription, $server->description);
3437

3538
$this->actingAs($user)
3639
->postJson("/api/client/servers/$server->uuid/settings/rename", [
3740
'name' => 'Test Server Name',
41+
'description' => 'This is a test server.',
3842
])
3943
->assertStatus(Response::HTTP_NO_CONTENT);
4044

4145
$server = $server->refresh();
4246
$this->assertSame('Test Server Name', $server->name);
47+
$this->assertSame('This is a test server.', $server->description);
4348
}
4449

4550
/**

0 commit comments

Comments
 (0)