Restore password policy editing in Web Console

This commit is contained in:
SantaSpeen committed 2026-11-22 03:34:20 +03:00
1 parent bf3b40d9a5
commit 4801cfbe77
6 files changed
+174 -25

No files matched your search

+57 -9
View File
@@ -4,7 +4,7 @@ const element = (id) => document.getElementById(id);
const routes = ["overview", "storage", "security", "audit"];
const nav = [...document.querySelectorAll("nav button")];
const dateFormat = new Intl.DateTimeFormat("ru", { dateStyle: "short", timeStyle: "short" });
const labels = { LOGIN: "Вход", LOGOUT: "Выход" };
const labels = { LOGIN: "Вход", LOGOUT: "Выход", SETTINGS: "Настройки" };
const pageSize = 20;
let token = "";
let revision = 0;
@@ -149,6 +149,54 @@ function definitions(target, entries) {
}
const yesNo = (value) => value === "true" ? "Да" : value === "false" ? "Нет" : "—";
const policyForm = element("policy");
const policyInputs = [...policyForm.querySelectorAll("input[name], select[name]")];
for (const [name, options] of Object.entries({
minimumLength: Array.from({ length: 13 }, (_, index) => index + 8),
expirationDaysAfter: [30, 60, 90, 120, 150, 180],
expirationReminderDaysBefore: Array.from({ length: 10 }, (_, index) => index + 1)
})) {
policyForm.elements[name].replaceChildren(...options.map((value) => new Option(value, value)));
}
function updateExpirationFields() {
const enabled = policyForm.elements.isExpirationEnabled.checked;
policyForm.elements.expirationDaysAfter.disabled = !enabled;
policyForm.elements.expirationReminderDaysBefore.disabled = !enabled;
}
policyForm.elements.isExpirationEnabled.addEventListener("change", updateExpirationFields);
policyForm.addEventListener("input", () => message("policy-feedback", ""));
policyForm.addEventListener("submit", async (event) => {
event.preventDefault();
const feedback = element("policy-feedback");
feedback.dataset.error = "true";
if (policyInputs.filter((field) => field.name.endsWith("Enabled") &&
field.name !== "isExpirationEnabled" && field.checked).length < 2) {
message("policy-feedback", "Выберите не менее двух типов символов.");
return;
}
const data = policyInputs.map((field) => ({
section: "PasswordPolicy",
key: field.name,
value: field.type === "checkbox" ? String(field.checked) : field.value
}));
const fields = element("policy-fields");
const requestToken = token;
fields.disabled = true;
message("policy-feedback", "");
try {
await api("/api/v1/settings/settingvalues", { data });
if (requestToken !== token) return;
feedback.dataset.error = "false";
message("policy-feedback", "Политика сохранена.");
} catch (error) {
if (requestToken === token) message("policy-feedback", error.message);
} finally {
if (requestToken === token) fields.disabled = false;
}
});
const loaders = {
async overview(active) {
const [health, result] = await Promise.all([api("/health"), api("/api/v1/info/versions")]);
@@ -169,6 +217,8 @@ const loaders = {
element("copy-path").disabled = !storagePath;
},
async security(active) {
element("policy-fields").disabled = true;
message("policy-feedback", "");
const [policy, protection, counts] = await Promise.all([
api("/api/v1/settings/settingvalues/section/PasswordPolicy"),
api("/api/v1/settings/settingvaluesp2/section/ProtectPatientSocialIDs/key/isEnabled"),
@@ -176,14 +226,12 @@ const loaders = {
]);
if (!active()) return;
const values = Object.fromEntries(policy.data.map(({ key, value }) => [key, value]));
definitions("policy", [
["Минимальная длина", values.minimumLength],
["Прописные буквы", yesNo(values.isUpperAlphabetsEnabled)],
["Строчные буквы", yesNo(values.isLowerAlphabetsEnabled)],
["Цифры", yesNo(values.isNumericDigitsEnabled)],
["Специальные символы", yesNo(values.isSpecialCharactersEnabled)],
["Срок действия", yesNo(values.isExpirationEnabled)]
]);
for (const field of policyInputs) {
if (field.type === "checkbox") field.checked = values[field.name] === "true";
else field.value = values[field.name];
}
element("policy-fields").disabled = false;
updateExpirationFields();
definitions("privacy", [
["Защита включена", yesNo(protection.data[0]?.value)],
["Защищено", counts.protectedSocialIDs],