aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2021-08-26 16:35:43 +0100
committerMatthew Wild <mwild1@gmail.com>2021-08-26 16:35:43 +0100
commit58e6c71f1237015c8c37228a85011e22a82b55cb (patch)
treea583a23310d9c7e497073cf45ae34eed7050efef /core
parent6742da8c10807b16d66984a4a05ce8637fe32c4e (diff)
downloadprosody-58e6c71f1237015c8c37228a85011e22a82b55cb.tar.gz
prosody-58e6c71f1237015c8c37228a85011e22a82b55cb.zip
usermanager, mod_authz_internal: Add methods to fetch users/JIDs of given role
Diffstat (limited to 'core')
-rw-r--r--core/usermanager.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/usermanager.lua b/core/usermanager.lua
index b51833cc..55faa0c9 100644
--- a/core/usermanager.lua
+++ b/core/usermanager.lua
@@ -9,6 +9,7 @@
local modulemanager = require "core.modulemanager";
local log = require "util.logger".init("usermanager");
local type = type;
+local it = require "util.iterators";
local jid_bare = require "util.jid".bare;
local jid_split = require "util.jid".split;
local jid_prep = require "util.jid".prep;
@@ -49,6 +50,10 @@ local global_authz_provider = {
return admin_role;
end
end;
+ get_jids_with_role = function (role)
+ if role ~= "prosody:admin" then return {}; end
+ return it.to_array(global_admins);
+ end;
};
local provider_mt = { __index = new_null_provider() };
@@ -180,6 +185,23 @@ local function is_admin(jid, host)
return roles and roles["prosody:admin"];
end
+local function get_users_with_role(role, host)
+ if not hosts[host] then return false; end
+ if type(role) ~= "string" then return false; end
+
+ return hosts[host].authz.get_users_with_role(role);
+end
+
+local function get_jids_with_role(role, host)
+ if host and not hosts[host] then return false; end
+ if type(role) ~= "string" then return false; end
+
+ host = host or "*";
+
+ local authz_provider = (host ~= "*" and hosts[host].authz) or global_authz_provider;
+ return authz_provider.get_jids_with_role(role);
+end
+
return {
new_null_provider = new_null_provider;
initialize_host = initialize_host;
@@ -195,4 +217,6 @@ return {
get_roles = get_roles;
set_roles = set_roles;
is_admin = is_admin;
+ get_users_with_role = get_users_with_role;
+ get_jids_with_role = get_jids_with_role;
};