Comparison

core/usermanager.lua @ 11745:3a2d58a39872

usermanager, mod_authz_internal: Add methods to fetch users/JIDs of given role
author Matthew Wild <mwild1@gmail.com>
date Thu, 26 Aug 2021 16:35:43 +0100
parent 11473:afe80b64e209
child 11898:89aa591bb895
comparison
equal deleted inserted replaced
11744:5f99aa6bb76d 11745:3a2d58a39872
7 -- 7 --
8 8
9 local modulemanager = require "core.modulemanager"; 9 local modulemanager = require "core.modulemanager";
10 local log = require "util.logger".init("usermanager"); 10 local log = require "util.logger".init("usermanager");
11 local type = type; 11 local type = type;
12 local it = require "util.iterators";
12 local jid_bare = require "util.jid".bare; 13 local jid_bare = require "util.jid".bare;
13 local jid_split = require "util.jid".split; 14 local jid_split = require "util.jid".split;
14 local jid_prep = require "util.jid".prep; 15 local jid_prep = require "util.jid".prep;
15 local config = require "core.configmanager"; 16 local config = require "core.configmanager";
16 local sasl_new = require "util.sasl".new; 17 local sasl_new = require "util.sasl".new;
46 get_user_roles = function (user) end; --luacheck: ignore 212/user 47 get_user_roles = function (user) end; --luacheck: ignore 212/user
47 get_jid_roles = function (jid) 48 get_jid_roles = function (jid)
48 if global_admins:contains(jid) then 49 if global_admins:contains(jid) then
49 return admin_role; 50 return admin_role;
50 end 51 end
52 end;
53 get_jids_with_role = function (role)
54 if role ~= "prosody:admin" then return {}; end
55 return it.to_array(global_admins);
51 end; 56 end;
52 }; 57 };
53 58
54 local provider_mt = { __index = new_null_provider() }; 59 local provider_mt = { __index = new_null_provider() };
55 60
176 end 181 end
177 182
178 local function is_admin(jid, host) 183 local function is_admin(jid, host)
179 local roles = get_roles(jid, host); 184 local roles = get_roles(jid, host);
180 return roles and roles["prosody:admin"]; 185 return roles and roles["prosody:admin"];
186 end
187
188 local function get_users_with_role(role, host)
189 if not hosts[host] then return false; end
190 if type(role) ~= "string" then return false; end
191
192 return hosts[host].authz.get_users_with_role(role);
193 end
194
195 local function get_jids_with_role(role, host)
196 if host and not hosts[host] then return false; end
197 if type(role) ~= "string" then return false; end
198
199 host = host or "*";
200
201 local authz_provider = (host ~= "*" and hosts[host].authz) or global_authz_provider;
202 return authz_provider.get_jids_with_role(role);
181 end 203 end
182 204
183 return { 205 return {
184 new_null_provider = new_null_provider; 206 new_null_provider = new_null_provider;
185 initialize_host = initialize_host; 207 initialize_host = initialize_host;
193 get_sasl_handler = get_sasl_handler; 215 get_sasl_handler = get_sasl_handler;
194 get_provider = get_provider; 216 get_provider = get_provider;
195 get_roles = get_roles; 217 get_roles = get_roles;
196 set_roles = set_roles; 218 set_roles = set_roles;
197 is_admin = is_admin; 219 is_admin = is_admin;
220 get_users_with_role = get_users_with_role;
221 get_jids_with_role = get_jids_with_role;
198 }; 222 };