Changeset

12209:3fe2e5da05c3

mod_admin_shell: Add command to show current user roles
author Kim Alvefur <zash@zash.se>
date Sun, 23 Jan 2022 20:06:50 +0100
parents 12208:3edf1a38fb15
children 12211:5c2ae28f536e
files plugins/mod_admin_shell.lua
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_admin_shell.lua	Sun Jan 23 19:55:32 2022 +0100
+++ b/plugins/mod_admin_shell.lua	Sun Jan 23 20:06:50 2022 +0100
@@ -251,6 +251,7 @@
 	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 @@
 	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)