Software /
code /
prosody
Comparison
plugins/mod_admin_shell.lua @ 12637:2200f0c6b3f1 0.12
mod_admin_shell: Switch names for user role management commands
user:roles() does not convey that this is the mutating command, it
should have been called setroles from the start but wasn't due to lack
of foresight. This has to accidentally removing roles when wanting to
show them.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 15 Aug 2022 18:56:22 +0200 |
parent | 12505:604bb5b8362d |
child | 12638:a47af78a9347 |
child | 12787:3735ad8d6f8e |
comparison
equal
deleted
inserted
replaced
12599:5aafcf6a0730 | 12637:2200f0c6b3f1 |
---|---|
255 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] | 255 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] |
256 print [[host:list() - List the currently-activated hosts]] | 256 print [[host:list() - List the currently-activated hosts]] |
257 elseif section == "user" then | 257 elseif section == "user" then |
258 print [[user:create(jid, password, roles) - Create the specified user account]] | 258 print [[user:create(jid, password, roles) - Create the specified user account]] |
259 print [[user:password(jid, password) - Set the password for the specified user account]] | 259 print [[user:password(jid, password) - Set the password for the specified user account]] |
260 print [[user:showroles(jid, host) - Show current roles for an user]] | 260 print [[user:roles(jid, host) - Show current roles for an user]] |
261 print [[user:roles(jid, host, roles) - Set roles for an user (see 'help roles')]] | 261 print [[user:setroles(jid, host, roles) - Set roles for an user (see 'help roles')]] |
262 print [[user:delete(jid) - Permanently remove the specified user account]] | 262 print [[user:delete(jid) - Permanently remove the specified user account]] |
263 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] | 263 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] |
264 elseif section == "roles" then | 264 elseif section == "roles" then |
265 print [[Roles may grant access or restrict users from certain operations]] | 265 print [[Roles may grant access or restrict users from certain operations]] |
266 print [[Built-in roles are:]] | 266 print [[Built-in roles are:]] |
1397 else | 1397 else |
1398 return nil, "Could not change password for user: "..err; | 1398 return nil, "Could not change password for user: "..err; |
1399 end | 1399 end |
1400 end | 1400 end |
1401 | 1401 |
1402 function def_env.user:showroles(jid, host) | 1402 function def_env.user:roles(jid, host, new_roles) |
1403 if new_roles or type(host) == "table" then | |
1404 return nil, "Use user:setroles(jid, host, roles) to change user roles"; | |
1405 end | |
1403 local username, userhost = jid_split(jid); | 1406 local username, userhost = jid_split(jid); |
1404 if host == nil then host = userhost; end | 1407 if host == nil then host = userhost; end |
1405 if host ~= "*" and not prosody.hosts[host] then | 1408 if host ~= "*" and not prosody.hosts[host] then |
1406 return nil, "No such host: "..host; | 1409 return nil, "No such host: "..host; |
1407 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then | 1410 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then |
1415 count = count + 1; | 1418 count = count + 1; |
1416 print(role); | 1419 print(role); |
1417 end | 1420 end |
1418 return true, count == 1 and "1 role" or count.." roles"; | 1421 return true, count == 1 and "1 role" or count.." roles"; |
1419 end | 1422 end |
1423 def_env.user.showroles = def_env.user.roles; -- COMPAT | |
1420 | 1424 |
1421 -- user:roles("someone@example.com", "example.com", {"prosody:admin"}) | 1425 -- user:roles("someone@example.com", "example.com", {"prosody:admin"}) |
1422 -- user:roles("someone@example.com", {"prosody:admin"}) | 1426 -- user:roles("someone@example.com", {"prosody:admin"}) |
1423 function def_env.user:roles(jid, host, new_roles) | 1427 function def_env.user:setroles(jid, host, new_roles) |
1424 local username, userhost = jid_split(jid); | 1428 local username, userhost = jid_split(jid); |
1425 if new_roles == nil then host, new_roles = userhost, host; end | 1429 if new_roles == nil then host, new_roles = userhost, host; end |
1426 if host ~= "*" and not prosody.hosts[host] then | 1430 if host ~= "*" and not prosody.hosts[host] then |
1427 return nil, "No such host: "..host; | 1431 return nil, "No such host: "..host; |
1428 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then | 1432 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then |