Changeset

3030:2be7801474fb

usermanager: Fix for is_admin to work with the new auth provider architecture
author Matthew Wild <mwild1@gmail.com>
date Fri, 07 May 2010 21:42:45 +0100
parents 3029:0c7beabfed5b
children 3031:421890f3f247
files core/usermanager.lua
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/core/usermanager.lua	Fri May 07 16:21:04 2010 +0500
+++ b/core/usermanager.lua	Fri May 07 21:42:45 2010 +0100
@@ -83,12 +83,8 @@
 	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 @@
 		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 @@
 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;