From 7a706aecec8f2508ef13aed9e4ed7d55bcf7d3d0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 23 Jan 2022 20:06:50 +0100 Subject: mod_admin_shell: Add command to show current user roles --- plugins/mod_admin_shell.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'plugins') 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) -- cgit v1.2.3