From a638f49976e894a83b15912bb17e2d3921a0651f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 7 May 2010 21:42:45 +0100 Subject: usermanager: Fix for is_admin to work with the new auth provider architecture --- core/usermanager.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/core/usermanager.lua b/core/usermanager.lua index 1ee4736e..c9ac041c 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -83,12 +83,8 @@ function new_default_provider(host) end function provider.is_admin(jid) - host = host or "*"; local admins = config.get(host, "core", "admins"); - if host ~= "*" and admins == config.get("*", "core", "admins") then - return nil; - end - if type(admins) == "table" then + if admins ~= config.get("*", "core", "admins") and type(admins) == "table" then jid = jid_bare(jid); for _,admin in ipairs(admins) do if admin == jid then return true; end @@ -96,7 +92,7 @@ function new_default_provider(host) elseif admins then log("warn", "Option 'admins' for host '%s' is not a table", host); end - return nil; + return is_admin(jid); -- Test whether it's a global admin instead end return provider; end @@ -126,7 +122,20 @@ function get_supported_methods(host) end function is_admin(jid, host) - return hosts[host].users.is_admin(jid); + if host and host ~= "*" then + return hosts[host].users.is_admin(jid); + else -- 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 admin == jid then return true; end + end + elseif admins then + log("warn", "Option 'admins' for host '%s' is not a table", host); + end + return nil; + end end return _M; -- cgit v1.2.3