Lock admin role permissions on server and client

This commit is contained in:
Jage9
2026-02-27 19:36:09 -05:00
parent 240d2ecfe8
commit 37419a5592
4 changed files with 17 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
// Maintainer-controlled web client version. // Maintainer-controlled web client version.
// Format: YYYY.MM.DD Rn (example: 2026.02.20 R2) // Format: YYYY.MM.DD Rn (example: 2026.02.20 R2)
window.CHGRID_WEB_VERSION = "2026.02.27 R299"; window.CHGRID_WEB_VERSION = "2026.02.27 R300";
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid. // Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
window.CHGRID_TIME_ZONE = "America/Detroit"; window.CHGRID_TIME_ZONE = "America/Detroit";

View File

@@ -2825,6 +2825,11 @@ function handleAdminRolePermissionListModeInput(code: string, key: string): void
audio.sfxUiBlip(); audio.sfxUiBlip();
return; return;
} }
if (role.name === 'admin') {
updateStatus('Admin role permissions are locked on.');
audio.sfxUiCancel();
return;
}
const nextPermissions = new Set(role.permissions); const nextPermissions = new Set(role.permissions);
if (nextPermissions.has(value)) { if (nextPermissions.has(value)) {
nextPermissions.delete(value); nextPermissions.delete(value);

View File

@@ -307,6 +307,8 @@ class AuthService:
"""Replace one role's permission assignment with validated keys.""" """Replace one role's permission assignment with validated keys."""
normalized_role = self._normalize_role_name(role_name) normalized_role = self._normalize_role_name(role_name)
if normalized_role == "admin":
raise AuthError("Admin role permissions are locked on.")
role_row = self._db_fetchone("SELECT id, name FROM roles WHERE name = ?", (normalized_role,)) role_row = self._db_fetchone("SELECT id, name FROM roles WHERE name = ?", (normalized_role,))
if role_row is None: if role_row is None:
raise AuthError("Role not found.") raise AuthError("Role not found.")

View File

@@ -78,3 +78,12 @@ def test_delete_role_rejects_admin_and_user(tmp_path: Path) -> None:
service.delete_role("user", "editor") service.delete_role("user", "editor")
finally: finally:
service.close() service.close()
def test_update_role_permissions_rejects_admin(tmp_path: Path) -> None:
service = make_auth_service(tmp_path)
try:
with pytest.raises(AuthError):
service.update_role_permissions("admin", ["chat.send"])
finally:
service.close()