mod_admin_shell: Support setting roles on hosts other than the users'
authorKim Alvefur <zash@zash.se>
Mon, 06 Dec 2021 21:56:19 +0100
changeset 12018 efbf288b529e
parent 12017 ae45f052b34b
child 12019 b4db17aeff01
mod_admin_shell: Support setting roles on hosts other than the users' Needed to e.g. grant admin rights on a component, or grant non-local users local privileges. Leave the same host syntax for convenience, since this might be the common case.
plugins/mod_admin_shell.lua
--- a/plugins/mod_admin_shell.lua	Mon Dec 06 21:55:57 2021 +0100
+++ b/plugins/mod_admin_shell.lua	Mon Dec 06 21:56:19 2021 +0100
@@ -250,7 +250,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:roles(jid, roles) - Set 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]]
 	elseif section == "muc" then
@@ -1328,12 +1328,16 @@
 	end
 end
 
+-- user:roles("someone@example.com", "example.com", {"prosody:admin"})
 -- user:roles("someone@example.com", {"prosody:admin"})
-function def_env.user:roles(jid, new_roles)
-	local username, host = jid_split(jid);
+function def_env.user:roles(jid, host, new_roles)
+	local username, userhost = jid_split(jid);
+	if new_roles == nil then host, new_roles = userhost, host; end
 	if not prosody.hosts[host] then
 		return nil, "No such host: "..host;
-	elseif not um.user_exists(username, host) then
+	elseif not prosody.hosts[userhost] then
+		return nil, "No such host: "..userhost;
+	elseif not um.user_exists(username, userhost) then
 		return nil, "No such user";
 	end
 	return um.set_roles(jid, host, coerce_roles(new_roles));