收紧全局设置与DNS权限并更新进度清单

限制系统设置修改、DNS在线测试和续期操作的角色权限,补充前后端回归测试与开发进度记录。
This commit is contained in:
xuans committed 2026-09-29 22:33:32 +08:00
1 parent f254dd9248
commit ba6bd80382
12 files changed
+160 -10

No files matched your search

+16
View File
@@ -15,6 +15,8 @@ function dnsVerificationTimeoutFor(providerID) {
export function useDashboard() {
const status = ref(null);
const currentUser = ref(null);
const canManageSystemSettings = computed(() => currentUser.value?.role === "super_admin");
const canRunRenewal = computed(() => currentUser.value?.role === "super_admin");
const domains = ref([]);
const servers = ref([]);
const sshKeys = ref([]);
@@ -864,6 +866,10 @@ export function useDashboard() {
}
async function runRenewalNow() {
if (!canRunRenewal.value) {
error.value = "只有超级管理员可以执行续期检查";
return;
}
error.value = "";
notice.value = "";
try {
@@ -904,6 +910,10 @@ export function useDashboard() {
}
async function testDNS() {
if (!canManageSystemSettings.value) {
dnsTestError.value = "只有超级管理员可以进行 DNS 在线测试";
return;
}
handleDNSProviderChange();
const dns = settingsForm.value.dns;
const provider = selectedDNSProvider.value;
@@ -986,6 +996,10 @@ export function useDashboard() {
async function saveSettings() {
settingsError.value = "";
if (!canManageSystemSettings.value) {
settingsError.value = "只有超级管理员可以保存系统设置";
return;
}
verificationClock.value = Date.now();
if (!dnsReadyToSave.value) {
settingsError.value = "DNS 服务商配置尚未通过在线测试,请先完成测试";
@@ -1216,6 +1230,8 @@ export function useDashboard() {
...domainForm,
status,
currentUser,
canManageSystemSettings,
canRunRenewal,
domains,
servers,
sshKeys,
@@ -276,11 +276,25 @@ async function setup(t, request) {
return Response.json({ items: [] });
});
const { state } = mounted;
state.currentUser.value = { account: "test-admin", role: "super_admin" };
state.openSettings();
await nextTick();
return mounted;
}
test("普通管理员不能在前端执行全局续期、DNS验证或保存系统设置", async (t) => {
const { state } = await setup(t, () => verifiedResponse());
state.currentUser.value = { account: "operator", role: "admin" };
state.showSettings.value = true;
await state.testDNS();
assert.equal(state.dnsTestError.value, "只有超级管理员可以进行 DNS 在线测试");
await state.saveSettings();
assert.equal(state.settingsError.value, "只有超级管理员可以保存系统设置");
await state.runRenewalNow();
assert.equal(state.error.value, "只有超级管理员可以执行续期检查");
});
test("编辑服务器正确保留已有密码状态,新建和未配置密码仍要求输入", async (t) => {
const { state } = await setup(t, () => verifiedResponse());
state.openServerEdit({ id: "configured", auth_method: "password", password_configured: true });
@@ -540,6 +554,7 @@ test("settingsReadEditSaveContract", async (t) => {
}
return Response.json({ items: [] });
});
state.currentUser.value = { account: "test-admin", role: "super_admin" };
state.openSettings();
state.settingsForm.value.acme.renewal_threshold_days = 91;
assert.equal(state.dnsReadyToSave.value, true);
+2 -1
View File
@@ -129,6 +129,7 @@ const {
validateDomain,
deployDomain,
runRenewalNow,
canRunRenewal,
cancelTask,
openTaskDetails,
closeTaskDetails,
@@ -158,7 +159,7 @@ const { activeSection, activeLabel, sections, selectSection } = useDashboardNavi
<button class="secondary-button" type="button" @click="loadData">
刷新状态
</button>
<button v-if="activeSection === 'activity'" class="secondary-button" type="button" @click="runRenewalNow">
<button v-if="activeSection === 'activity' && canRunRenewal" class="secondary-button" type="button" @click="runRenewalNow">
立即检查续期
</button>
<button
@@ -161,3 +161,18 @@
grid-template-columns: 1fr;
}
}
.settings-fields {
min-width: 0;
margin: 0;
padding: 0;
border: 0;
}
.settings-readonly-notice {
margin: 0 0 16px;
padding: 10px 12px;
border: 1px solid #f1d48a;
border-radius: 8px;
color: #755b18;
background: #fff8e6;
}
@@ -16,6 +16,7 @@ const {
dnsVerificationElapsedSeconds,
dnsVerificationTimeoutSeconds,
dnsReadyToSave,
canManageSystemSettings,
handleDNSProviderChange,
clearDNSCredentials,
testDNS,
@@ -36,6 +37,9 @@ const { activeSection, submitSettings, navigateTabs } = useSettingsModal(saveSet
</div>
<button class="close-button" type="button" aria-label="关闭" @click="closeSettings">×</button>
</div>
<p v-if="!canManageSystemSettings" class="settings-readonly-notice">
当前账号仅可查看系统设置,修改配置和 DNS 在线验证需要超级管理员权限。
</p>
<div class="settings-tabs" role="tablist" aria-labelledby="settings-title">
<button
id="settings-tab-service"
@@ -87,6 +91,7 @@ const { activeSection, submitSettings, navigateTabs } = useSettingsModal(saveSet
</button>
</div>
<form novalidate @submit.prevent="submitSettings">
<fieldset :disabled="!canManageSystemSettings" class="settings-fields">
<section
v-show="activeSection === 'service'"
id="settings-panel-service"
@@ -381,6 +386,7 @@ const { activeSection, submitSettings, navigateTabs } = useSettingsModal(saveSet
{{ settingsSaving ? "保存中……" : "保存设置" }}
</button>
</div>
</fieldset>
</form>
</section>
</div>