Mercurial > prosody-modules
changeset 6327:4f6fb56572f7
mod_protect_last_admin: Return util.error object to provide more information
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 29 Sep 2025 21:28:18 +0100 |
| parents | 2623515d8507 |
| children | 187b957dc528 |
| files | mod_protect_last_admin/mod_protect_last_admin.lua |
| diffstat | 1 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_protect_last_admin/mod_protect_last_admin.lua Thu Sep 25 18:21:27 2025 +0100 +++ b/mod_protect_last_admin/mod_protect_last_admin.lua Mon Sep 29 21:28:18 2025 +0100 @@ -6,6 +6,19 @@ local protected_roles = module:get_option_set("protect_last_admin_roles", { "prosody:admin", "prosody:operator" }); +local errors = require "prosody.util.error".init(module.name, { + ["cannot-remove-only-admin"] = { + code = 400; + type = "cancel"; + condition = "policy-violation"; + text = "Cannot remove the only administrator"; + extra = { + namespace = "https://prosody.im/protocol/errors"; + condition = "cannot-remove-only-admin"; + }; + }; +}); + local function other_protected_users(username, host) local protected_users = set.new(); for protected_role in protected_roles do @@ -39,7 +52,7 @@ end if not other_protected_users(username, host) then - event.reason = "Cannot remove the only administrator"; + event.reason = errors.new("cannot-remove-only-admin"); return false; end module:log("debug", "Permitting event, no reason not to!");
