Protect the final administrator
This commit is contained in:
@@ -6066,6 +6066,7 @@ async function refreshUserManagement() {
|
||||
const list = requiredElement("user-list");
|
||||
try {
|
||||
const users = await listUsers();
|
||||
const adminCount = users.filter((user) => user.role === "admin").length;
|
||||
list.replaceChildren(...users.map((user) => {
|
||||
const row = document.createElement("div");
|
||||
row.className = "sch-row";
|
||||
@@ -6082,6 +6083,9 @@ async function refreshUserManagement() {
|
||||
option.selected = user.role === value;
|
||||
role.append(option);
|
||||
}
|
||||
const isOnlyAdmin = user.role === "admin" && adminCount === 1;
|
||||
role.disabled = isOnlyAdmin;
|
||||
if (isOnlyAdmin) role.title = "The final administrator cannot be demoted";
|
||||
const password = document.createElement("input");
|
||||
password.type = "password";
|
||||
password.placeholder = "New password";
|
||||
@@ -6100,7 +6104,8 @@ async function refreshUserManagement() {
|
||||
remove.type = "button";
|
||||
remove.textContent = "Remove";
|
||||
remove.className = "danger";
|
||||
remove.disabled = user.username === authUsername;
|
||||
remove.disabled = user.username === authUsername || isOnlyAdmin;
|
||||
if (isOnlyAdmin) remove.title = "The final administrator cannot be removed";
|
||||
remove.addEventListener("click", async () => {
|
||||
if (await window.trxUi.confirm({ title: "Remove user?", message: `Remove ${user.username} and revoke their sessions?`, confirmLabel: "Remove", danger: true })) {
|
||||
await runUserOperation(() => deleteUser(user.username));
|
||||
|
||||
Reference in New Issue
Block a user