# HG changeset patch # User Matthew Wild # Date 1277229601 -3600 # Node ID c116c4b2db5aa449a51dbfe2f1d1606511e141fe # Parent 867d6413fe0a851c2009a99e5fc981d8e5aedd45 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 diff -r 867d6413fe0a -r c116c4b2db5a core/usermanager.lua --- a/core/usermanager.lua Sun Jun 20 04:07:55 2010 +0500 +++ b/core/usermanager.lua Tue Jun 22 19:00:01 2010 +0100 @@ -91,24 +91,43 @@ function is_admin(jid, host) local is_admin; - if host and host ~= "*" then - is_admin = hosts[host].users.is_admin(jid); - 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 + 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 table", host); + log("error", "Option 'admins' for host '%s' is not a list", host); end end - return is_admin; + + 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", "Global option 'admins' is not a list"); + end + end + + -- 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;