From 434a0e7b67941da4adf2c38b94bd5ec23bc0892b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 22 Jun 2010 19:00:01 +0100 Subject: usermanager: is_admin: Resume the old role of determining precisely whether a user is an admin for a given host (or a global admin) - auth providers checked for JIDs not listed in the config if they support it --- core/usermanager.lua | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'core') diff --git a/core/usermanager.lua b/core/usermanager.lua index bb8cd962..a369b9e0 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -91,24 +91,43 @@ end function is_admin(jid, host) local is_admin; - if host and host ~= "*" then - is_admin = hosts[host].users.is_admin(jid); + jid = jid_bare(jid); + host = host or "*"; + + local host_admins = config.get(host, "core", "admins"); + local global_admins = config.get("*", "core", "admins"); + + if host_admins and host_admins ~= global_admins then + if type(host_admins) == "table" then + for _,admin in ipairs(host_admins) do + if admin == jid then + is_admin = true; + break; + end + end + elseif admins then + log("error", "Option 'admins' for host '%s' is not a list", host); + end end - if not is_admin then -- Test only whether this JID is a global admin - local admins = config.get("*", "core", "admins"); - if type(admins) == "table" then - jid = jid_bare(jid); - for _,admin in ipairs(admins) do + + if not is_admin and global_admins then + if type(global_admins) == "table" then + for _,admin in ipairs(global_admins) do if admin == jid then is_admin = true; break; end end elseif admins then - log("error", "Option 'admins' for host '%s' is not a table", host); + log("error", "Global option 'admins' is not a list"); end end - return is_admin; + + -- Still not an admin, check with auth provider + if not is_admin and host ~= "*" and hosts[host].users.is_admin then + is_admin = hosts[host].users.is_admin(jid); + end + return is_admin or false; end return _M; -- cgit v1.2.3