core/usermanager.lua

changeset 3285
c116c4b2db5a
parent 3218
032b81731f0f
child 3293
4ce9d569a99c
equal deleted inserted replaced
3284:867d6413fe0a 3285:c116c4b2db5a
89 return hosts[host].users; 89 return hosts[host].users;
90 end 90 end
91 91
92 function is_admin(jid, host) 92 function is_admin(jid, host)
93 local is_admin; 93 local is_admin;
94 if host and host ~= "*" then 94 jid = jid_bare(jid);
95 is_admin = hosts[host].users.is_admin(jid); 95 host = host or "*";
96 end 96
97 if not is_admin then -- Test only whether this JID is a global admin 97 local host_admins = config.get(host, "core", "admins");
98 local admins = config.get("*", "core", "admins"); 98 local global_admins = config.get("*", "core", "admins");
99 if type(admins) == "table" then 99
100 jid = jid_bare(jid); 100 if host_admins and host_admins ~= global_admins then
101 for _,admin in ipairs(admins) do 101 if type(host_admins) == "table" then
102 for _,admin in ipairs(host_admins) do
102 if admin == jid then 103 if admin == jid then
103 is_admin = true; 104 is_admin = true;
104 break; 105 break;
105 end 106 end
106 end 107 end
107 elseif admins then 108 elseif admins then
108 log("error", "Option 'admins' for host '%s' is not a table", host); 109 log("error", "Option 'admins' for host '%s' is not a list", host);
109 end 110 end
110 end 111 end
111 return is_admin; 112
113 if not is_admin and global_admins then
114 if type(global_admins) == "table" then
115 for _,admin in ipairs(global_admins) do
116 if admin == jid then
117 is_admin = true;
118 break;
119 end
120 end
121 elseif admins then
122 log("error", "Global option 'admins' is not a list");
123 end
124 end
125
126 -- Still not an admin, check with auth provider
127 if not is_admin and host ~= "*" and hosts[host].users.is_admin then
128 is_admin = hosts[host].users.is_admin(jid);
129 end
130 return is_admin or false;
112 end 131 end
113 132
114 return _M; 133 return _M;

mercurial