Comparison

plugins/mod_admin_shell.lua @ 12014:efbf288b529e

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.
author Kim Alvefur <zash@zash.se>
date Mon, 06 Dec 2021 21:56:19 +0100
parent 12013:ae45f052b34b
child 12018:c65789f5004e
comparison
equal deleted inserted replaced
12013:ae45f052b34b 12014:efbf288b529e
248 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] 248 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]]
249 print [[host:list() - List the currently-activated hosts]] 249 print [[host:list() - List the currently-activated hosts]]
250 elseif section == "user" then 250 elseif section == "user" then
251 print [[user:create(jid, password, roles) - Create the specified user account]] 251 print [[user:create(jid, password, roles) - Create the specified user account]]
252 print [[user:password(jid, password) - Set the password for the specified user account]] 252 print [[user:password(jid, password) - Set the password for the specified user account]]
253 print [[user:roles(jid, roles) - Set roles for an user]] 253 print [[user:roles(jid, host, roles) - Set roles for an user (see 'help roles')]]
254 print [[user:delete(jid) - Permanently remove the specified user account]] 254 print [[user:delete(jid) - Permanently remove the specified user account]]
255 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] 255 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]]
256 elseif section == "muc" then 256 elseif section == "muc" then
257 -- TODO `muc:room():foo()` commands 257 -- TODO `muc:room():foo()` commands
258 print [[muc:create(roomjid, { config }) - Create the specified MUC room with the given config]] 258 print [[muc:create(roomjid, { config }) - Create the specified MUC room with the given config]]
1326 else 1326 else
1327 return nil, "Could not change password for user: "..err; 1327 return nil, "Could not change password for user: "..err;
1328 end 1328 end
1329 end 1329 end
1330 1330
1331 -- user:roles("someone@example.com", "example.com", {"prosody:admin"})
1331 -- user:roles("someone@example.com", {"prosody:admin"}) 1332 -- user:roles("someone@example.com", {"prosody:admin"})
1332 function def_env.user:roles(jid, new_roles) 1333 function def_env.user:roles(jid, host, new_roles)
1333 local username, host = jid_split(jid); 1334 local username, userhost = jid_split(jid);
1335 if new_roles == nil then host, new_roles = userhost, host; end
1334 if not prosody.hosts[host] then 1336 if not prosody.hosts[host] then
1335 return nil, "No such host: "..host; 1337 return nil, "No such host: "..host;
1336 elseif not um.user_exists(username, host) then 1338 elseif not prosody.hosts[userhost] then
1339 return nil, "No such host: "..userhost;
1340 elseif not um.user_exists(username, userhost) then
1337 return nil, "No such user"; 1341 return nil, "No such user";
1338 end 1342 end
1339 return um.set_roles(jid, host, coerce_roles(new_roles)); 1343 return um.set_roles(jid, host, coerce_roles(new_roles));
1340 end 1344 end
1341 1345