# HG changeset patch # User Kim Alvefur # Date 1638824179 -3600 # Node ID efbf288b529e26822014bf112adec16e2c9c2e29 # Parent ae45f052b34b9e63bb1f57f911740670d712abdd 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. diff -r ae45f052b34b -r efbf288b529e 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));