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

Tue, 22 Jun 2010 19:00:01 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 22 Jun 2010 19:00:01 +0100
changeset 3285
c116c4b2db5a
parent 3284
867d6413fe0a
child 3286
e5234625fc42

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 file | annotate | diff | comparison | revisions
--- 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;

mercurial