From cf137f99020a2f1ac67b761861a7baa4ef2cfe07 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 6 Dec 2021 21:56:19 +0100 Subject: 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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua index 5e021173..b7800764 100644 --- a/plugins/mod_admin_shell.lua +++ b/plugins/mod_admin_shell.lua @@ -250,7 +250,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: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 @@ function def_env.user:password(jid, password) 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)); -- cgit v1.2.3