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

+29 -14
View File
@@ -87,20 +87,35 @@ final class WebConsoleAPI {
guard path == ["settings", "settingvalues", "section", "passwordpolicy"] else {
return Reply(["data": []], errorCode: -100037)
}
// Display the defaults from CreateSETTINGDBTable.sql.
let policy = [
"minimumLength": "10",
"isUpperAlphabetsEnabled": "true",
"isLowerAlphabetsEnabled": "true",
"isNumericDigitsEnabled": "true",
"isSpecialCharactersEnabled": "true",
"isExpirationEnabled": "false",
"expirationDaysAfter": "180",
"expirationReminderDaysBefore": "10",
]
return Reply(["data": policy.sorted { $0.key < $1.key }.map {
["section": "PasswordPolicy", "key": $0.key, "value": $0.value]
}])
do {
let policy = try store.passwordPolicy()
return Reply(["data": policy.sorted { $0.key < $1.key }.map {
["section": "PasswordPolicy", "key": $0.key, "value": $0.value]
}])
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
case ("settings", "settingvalues", "POST") where path.count == 2:
guard let rows = input["data"] as? [[String: String]], (1...8).contains(rows.count) else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
var changes: [String: String] = [:]
for row in rows {
guard row["section"] == "PasswordPolicy", let key = row["key"],
let value = row["value"], changes[key] == nil else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
changes[key] = value
}
do {
try store.updatePasswordPolicy(changes)
event(type: "SETTINGS", message: "Updated password policy.")
return Reply()
} catch StoreError.invalid {
return Reply(status: "400 Bad Request", errorCode: -1021)
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
case ("settings", "settingvaluesp2", "GET"):
guard path == ["settings", "settingvaluesp2", "section", "protectpatientsocialids", "key", "isenabled"] else {
return Reply(["data": []], errorCode: -100037)