fix(connection): hide production protection for plugin connections

This commit is contained in:
t8y2
2026-09-17 00:57:42 +08:00
parent 13a209d4c2
commit 84ae93aaa8
2 changed files with 22 additions and 3 deletions
@@ -4110,8 +4110,9 @@ function connectionConfigForSubmit(id: string, generatedName = "", validatePlugi
config.keepalive_interval_secs = form.value.keepalive_interval_secs;
config.read_only = form.value.read_only;
config.save_password = form.value.save_password;
config.is_production = form.value.is_production;
config.production_databases = form.value.production_databases;
// 生产保护只拦截 SQL/数据编辑路径,插件连接走不到;表单已隐藏该区块,提交时清掉历史残留标志。
config.is_production = false;
config.production_databases = [];
} else {
config = { ...formValueForSubmit(), id } as LegacyConnectionConfig;
}
@@ -9027,7 +9028,7 @@ function openExternalUrl(url: string) {
</p>
</div>
</div>
<div class="grid grid-cols-4 items-start gap-4 rounded-[6px] border border-red-500/25 bg-red-500/[0.035] px-3 py-2.5">
<div v-if="!isPluginConnection" class="grid grid-cols-4 items-start gap-4 rounded-[6px] border border-red-500/25 bg-red-500/[0.035] px-3 py-2.5">
<Label :class="[connectionLabelSmallClass, 'pt-0.5 text-red-700 dark:text-red-300']">
<span class="inline-flex items-center justify-end gap-1"><ShieldAlert class="h-3.5 w-3.5" />PROD</span>
</Label>
@@ -0,0 +1,18 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const dialogSource = readFileSync(new URL("../../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8");
describe("ConnectionDialog production protection section", () => {
it("hides the production protection section for plugin connections", () => {
expect(dialogSource).toContain('<div v-if="!isPluginConnection" class="grid grid-cols-4 items-start gap-4 rounded-[6px] border border-red-500/25 bg-red-500/[0.035] px-3 py-2.5">');
});
it("clears stale production flags when submitting plugin connections", () => {
const submitFn = dialogSource.slice(dialogSource.indexOf("function connectionConfigForSubmit"));
const pluginBranch = submitFn.slice(0, submitFn.indexOf("} else {"));
expect(pluginBranch).toContain("config.is_production = false;");
expect(pluginBranch).toContain("config.production_databases = [];");
expect(pluginBranch).not.toContain("config.is_production = form.value.is_production;");
});
});