Skip to content

Commit 5173f1f

Browse files
committed
Don't allow editing read only values; closes pterodactyl#2252
1 parent 92929c4 commit 5173f1f

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ public function update(UpdateStartupVariableRequest $request, Server $server)
5555
/** @var \Pterodactyl\Models\EggVariable $variable */
5656
$variable = $server->variables()->where('env_variable', $request->input('key'))->first();
5757

58-
if (is_null($variable) || !$variable->user_viewable || !$variable->user_editable) {
58+
if (is_null($variable) || !$variable->user_viewable) {
5959
throw new BadRequestHttpException(
60-
"The environment variable you are trying to edit [\"{$request->input('key')}\"] does not exist."
60+
"The environment variable you are trying to edit does not exist."
61+
);
62+
} else if (! $variable->user_editable) {
63+
throw new BadRequestHttpException(
64+
"The environment variable you are trying to edit is read-only."
6165
);
6266
}
6367

resources/scripts/components/server/startup/VariableBox.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,25 @@ const VariableBox = ({ variable }: Props) => {
4343
}, 500);
4444

4545
return (
46-
<TitledGreyBox title={variable.name}>
46+
<TitledGreyBox
47+
title={
48+
<p css={tw`text-sm uppercase`}>
49+
{!variable.isEditable &&
50+
<span css={tw`bg-neutral-700 text-xs py-1 px-2 rounded-full mr-2`}>Read Only</span>
51+
}
52+
{variable.name}
53+
</p>
54+
}
55+
>
4756
<FlashMessageRender byKey={FLASH_KEY} css={tw`mb-4`}/>
4857
<InputSpinner visible={loading}>
4958
<Input
50-
onKeyUp={e => setVariableValue(e.currentTarget.value)}
51-
readOnly={!canEdit}
59+
onKeyUp={e => {
60+
if (canEdit && variable.isEditable) {
61+
setVariableValue(e.currentTarget.value);
62+
}
63+
}}
64+
readOnly={!canEdit || !variable.isEditable}
5265
name={variable.envVariable}
5366
defaultValue={variable.serverValue}
5467
placeholder={variable.defaultValue}

0 commit comments

Comments
 (0)