Software /
code /
prosody
Comparison
core/usermanager.lua @ 6979:0ce2b400663b
core.usermanager: Return as soon as possible once admin status is known
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 06 Dec 2015 23:47:47 +0100 |
parent | 6779:6236668da30a |
child | 7177:1295e14614f4 |
comparison
equal
deleted
inserted
replaced
6976:4688ff9d4f2b | 6979:0ce2b400663b |
---|---|
109 | 109 |
110 local function is_admin(jid, host) | 110 local function is_admin(jid, host) |
111 if host and not hosts[host] then return false; end | 111 if host and not hosts[host] then return false; end |
112 if type(jid) ~= "string" then return false; end | 112 if type(jid) ~= "string" then return false; end |
113 | 113 |
114 local is_admin; | |
115 jid = jid_bare(jid); | 114 jid = jid_bare(jid); |
116 host = host or "*"; | 115 host = host or "*"; |
117 | 116 |
118 local host_admins = config.get(host, "admins"); | 117 local host_admins = config.get(host, "admins"); |
119 local global_admins = config.get("*", "admins"); | 118 local global_admins = config.get("*", "admins"); |
120 | 119 |
121 if host_admins and host_admins ~= global_admins then | 120 if host_admins and host_admins ~= global_admins then |
122 if type(host_admins) == "table" then | 121 if type(host_admins) == "table" then |
123 for _,admin in ipairs(host_admins) do | 122 for _,admin in ipairs(host_admins) do |
124 if jid_prep(admin) == jid then | 123 if jid_prep(admin) == jid then |
125 is_admin = true; | 124 return true; |
126 break; | |
127 end | 125 end |
128 end | 126 end |
129 elseif host_admins then | 127 elseif host_admins then |
130 log("error", "Option 'admins' for host '%s' is not a list", host); | 128 log("error", "Option 'admins' for host '%s' is not a list", host); |
131 end | 129 end |
132 end | 130 end |
133 | 131 |
134 if not is_admin and global_admins then | 132 if global_admins then |
135 if type(global_admins) == "table" then | 133 if type(global_admins) == "table" then |
136 for _,admin in ipairs(global_admins) do | 134 for _,admin in ipairs(global_admins) do |
137 if jid_prep(admin) == jid then | 135 if jid_prep(admin) == jid then |
138 is_admin = true; | 136 return true; |
139 break; | |
140 end | 137 end |
141 end | 138 end |
142 elseif global_admins then | 139 elseif global_admins then |
143 log("error", "Global option 'admins' is not a list"); | 140 log("error", "Global option 'admins' is not a list"); |
144 end | 141 end |
145 end | 142 end |
146 | 143 |
147 -- Still not an admin, check with auth provider | 144 -- Still not an admin, check with auth provider |
148 if not is_admin and host ~= "*" and hosts[host].users and hosts[host].users.is_admin then | 145 if host ~= "*" and hosts[host].users and hosts[host].users.is_admin then |
149 is_admin = hosts[host].users.is_admin(jid); | 146 return hosts[host].users.is_admin(jid); |
150 end | 147 end |
151 return is_admin or false; | 148 return false; |
152 end | 149 end |
153 | 150 |
154 return { | 151 return { |
155 new_null_provider = new_null_provider; | 152 new_null_provider = new_null_provider; |
156 initialize_host = initialize_host; | 153 initialize_host = initialize_host; |