aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2022-01-23 20:06:50 +0100
committerKim Alvefur <zash@zash.se>2022-01-23 20:06:50 +0100
commit7a706aecec8f2508ef13aed9e4ed7d55bcf7d3d0 (patch)
tree719af111286df2f25565bc8370a0241f4129ddcf /plugins
parent1809c0460f51547c5ee26f37c426cc65352bb886 (diff)
downloadprosody-7a706aecec8f2508ef13aed9e4ed7d55bcf7d3d0.tar.gz
prosody-7a706aecec8f2508ef13aed9e4ed7d55bcf7d3d0.zip
mod_admin_shell: Add command to show current user roles
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_shell.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua
index 01fef416..088f0bfa 100644
--- a/plugins/mod_admin_shell.lua
+++ b/plugins/mod_admin_shell.lua
@@ -251,6 +251,7 @@ function commands.help(session, data)
elseif section == "user" then
print [[user:create(jid, password, roles) - Create the specified user account]]
print [[user:password(jid, password) - Set the password for the specified user account]]
+ print [[user:showroles(jid, host) - Show current roles for an user]]
print [[user:roles(jid, host, roles) - Set roles for an user (see 'help roles')]]
print [[user:delete(jid) - Permanently remove the specified user account]]
print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]]
@@ -1347,6 +1348,25 @@ function def_env.user:password(jid, password)
end
end
+function def_env.user:showroles(jid, host)
+ local username, userhost = jid_split(jid);
+ if host == nil then host = userhost; end
+ if host ~= "*" and not prosody.hosts[host] then
+ return nil, "No such host: "..host;
+ elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then
+ return nil, "No such user";
+ end
+ local roles = um.get_roles(jid, host);
+ if not roles then return true, "No roles"; end
+ local count = 0;
+ local print = self.session.print;
+ for role in pairs(roles) do
+ count = count + 1;
+ print(role);
+ end
+ return true, count == 1 and "1 role" or count.." roles";
+end
+
-- user:roles("someone@example.com", "example.com", {"prosody:admin"})
-- user:roles("someone@example.com", {"prosody:admin"})
function def_env.user:roles(jid, host, new_roles)