Merge pull request #1494 from MCSManager/absurd

feat: edit cmd settings
This commit is contained in:
Yumao 2025-02-14 16:30:17 +08:00 committed by GitHub
commit 1fcef8866d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 60 additions and 10 deletions

View File

@ -22,7 +22,8 @@ export const useAppStateStore = createGlobalState(() => {
canFileManager: false,
allowUsePreset: false,
businessMode: false,
businessId: ""
businessId: "",
allowChangeCmd: false
}
});

View File

@ -76,6 +76,7 @@ export interface Settings {
allowUsePreset: boolean;
businessMode: boolean;
businessId: string;
allowChangeCmd: boolean;
}
export interface ImageInfo {
@ -246,5 +247,6 @@ export interface PanelStatus {
allowUsePreset: boolean;
businessMode: boolean;
businessId: string;
allowChangeCmd: boolean;
};
}

View File

@ -387,6 +387,29 @@ onMounted(async () => {
</a-typography-text>
</a-typography-paragraph>
<a-form-item>
<a-typography-title :level="5">
{{ t("TXT_CODE_a583cae4") }}
</a-typography-title>
<a-typography-paragraph>
<a-typography-text type="secondary">
{{ t("TXT_CODE_bfbdf579") }}
</a-typography-text>
</a-typography-paragraph>
<a-select
v-model:value.prop="(formData as any).allowChangeCmd"
style="max-width: 320px"
>
<a-select-option
v-for="item in allYesNo"
:key="item.value"
:value="item.value"
>
{{ item.label }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item>
<a-typography-title :level="5">
{{ t("TXT_CODE_adab942e") }}

View File

@ -167,7 +167,10 @@ const btns = computed(() => {
{
title: t("TXT_CODE_4f34fc28"),
icon: AppstoreAddOutlined,
condition: () => !isAdmin.value,
condition: () =>
!isAdmin.value &&
instanceInfo.value?.config.processType === "docker" &&
state.settings.allowChangeCmd,
click: () => {
instanceFundamentalDetailDialog.value?.openDialog();
}

View File

@ -2551,5 +2551,7 @@
"TXT_CODE_ae566b56": "Optimizes the suffocation check by selectively skipping the check in a way that still appears vanilla. This should be left enabled on most servers, but is provided as a configuration option if the vanilla deviation is undesirable.",
"TXT_CODE_c6d3bd8": "MC Pufferfish",
"TXT_CODE_eee2a47f": "Image preview",
"TXT_CODE_66f38b2e": "Normal users can only modify part of the settings"
"TXT_CODE_66f38b2e": "Normal users can only modify part of the settings",
"TXT_CODE_a583cae4": "Allow normal users to edit the startup command",
"TXT_CODE_bfbdf579": "This feature allows normal users to edit the 'start' and 'update' commands of Docker instances"
}

View File

@ -2022,5 +2022,7 @@
"TXT_CODE_1548649e": "编辑计划任务",
"TXT_CODE_c6d3bd8": "MC Pufferfish",
"TXT_CODE_eee2a47f": "图像预览",
"TXT_CODE_66f38b2e": "普通用户仅可修改部分设置"
"TXT_CODE_66f38b2e": "普通用户仅可修改部分设置",
"TXT_CODE_a583cae4": "准许普通用户编辑启动命令",
"TXT_CODE_bfbdf579": "该功能允许普通用户编辑 Docker 实例的“启动”和“更新”命令"
}

View File

@ -57,4 +57,7 @@ export default class SystemConfig {
businessMode = false;
businessId = "";
// Whether to allow users to edit the start & update command of Docker instances
allowChangeCmd = false;
}

View File

@ -431,13 +431,24 @@ router.put(
instanceUuid
});
const isCmdChanged = (cmd: string | null, instanceCmd: string) => cmd !== instanceCmd;
const hasPermission = isTopPermissionByUuid(getUserUuid(ctx));
if (
(startCommand || updateCommand) &&
instance.config.processType !== "docker" &&
(startCommand !== instance.config.startCommand ||
updateCommand !== instance.config.updateCommand)
)
return verificationFailed(ctx);
isCmdChanged(startCommand, instance.config.startCommand) &&
isCmdChanged(updateCommand, instance.config.updateCommand)
) {
if (instance.config.processType !== "docker" && !hasPermission)
return verificationFailed(ctx);
if (
instance.config.processType === "docker" &&
!systemConfig?.allowChangeCmd &&
!hasPermission
)
return verificationFailed(ctx);
}
const result = await new RemoteRequest(remoteService).request("instance/update", {
instanceUuid,

View File

@ -79,7 +79,8 @@ router.all(
canFileManager: systemConfig?.canFileManager || false,
allowUsePreset: systemConfig?.allowUsePreset || false,
businessMode: systemConfig?.businessMode || false,
businessId: systemConfig?.businessId || null
businessId: systemConfig?.businessId || null,
allowChangeCmd: systemConfig?.allowChangeCmd || false
} as Partial<SystemConfig>
};
}

View File

@ -53,12 +53,14 @@ router.put("/setting", permission({ level: ROLE.ADMIN }), async (ctx) => {
if (config.presetPackAddr != null) systemConfig.presetPackAddr = String(config.presetPackAddr);
if (config.businessMode != null) systemConfig.businessMode = Boolean(config.businessMode);
if (config.businessId != null) systemConfig.businessId = String(config.businessId);
if (config.allowChangeCmd != null) systemConfig.allowChangeCmd = Boolean(config.allowChangeCmd);
if (config.language != null) {
logger.warn($t("TXT_CODE_e29a9317"), config.language);
systemConfig.language = String(config.language);
await i18next.changeLanguage(systemConfig.language.toLowerCase());
remoteService.changeDaemonLanguage(systemConfig.language);
}
saveSystemConfig(systemConfig);
ctx.body = "OK";
return;