Comparison

plugins/mod_admin_shell.lua @ 13170:082c7d856e61

core, plugins: Split prosody:user role into prosody:{guest,registered,member} This gives us more granular control over different types of user account. Accounts registered by IBR get assigned prosody:registered by default, while accounts provisioned by an admin (e.g. via prosodyctl shell) will receive prosody:member by default.
author Matthew Wild <mwild1@gmail.com>
date Thu, 29 Jun 2023 15:36:13 +0100
parent 13132:5bfcfd12c423
comparison
equal deleted inserted replaced
13169:7b6e7290265b 13170:082c7d856e61
280 print [[user:delete(jid) - Permanently remove the specified user account]] 280 print [[user:delete(jid) - Permanently remove the specified user account]]
281 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] 281 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]]
282 elseif section == "roles" then 282 elseif section == "roles" then
283 print [[Roles may grant access or restrict users from certain operations]] 283 print [[Roles may grant access or restrict users from certain operations]]
284 print [[Built-in roles are:]] 284 print [[Built-in roles are:]]
285 print [[ prosody:user - Normal user (default)]] 285 print [[ prosody:guest - Guest/anonymous user]]
286 print [[ prosody:admin - Host administrator]] 286 print [[ prosody:registered - Registered user]]
287 print [[ prosody:member - Provisioned user]]
288 print [[ prosody:admin - Host administrator]]
287 print [[ prosody:operator - Server administrator]] 289 print [[ prosody:operator - Server administrator]]
288 print [[]] 290 print [[]]
289 print [[Roles can be assigned using the user management commands (see 'help user').]] 291 print [[Roles can be assigned using the user management commands (see 'help user').]]
290 elseif section == "muc" then 292 elseif section == "muc" then
291 -- TODO `muc:room():foo()` commands 293 -- TODO `muc:room():foo()` commands
1580 return nil, "No such host: "..host; 1582 return nil, "No such host: "..host;
1581 elseif um.user_exists(username, host) then 1583 elseif um.user_exists(username, host) then
1582 return nil, "User exists"; 1584 return nil, "User exists";
1583 end 1585 end
1584 1586
1585 if role then 1587 if not role then
1586 local ok, err = um.create_user(username, nil, host); 1588 role = module:get_option_string("default_provisioned_role", "prosody:member");
1587 if not ok then 1589 end
1588 return nil, "Could not create user: "..err; 1590
1589 end 1591 local ok, err = um.create_user_with_role(username, password, host, role);
1590 1592 if not ok then
1591 local role_ok, rerr = um.set_user_role(jid, host, role); 1593 return nil, "Could not create user: "..err;
1592 if not role_ok then 1594 end
1593 return nil, "Could not set role: " .. tostring(rerr); 1595
1594 end 1596 return true, ("Created %s with role '%s'"):format(jid, role);
1595
1596 if password then
1597 local ok, err = um.set_password(username, password, host, nil);
1598 if not ok then
1599 return nil, "Could not set password for user: "..err;
1600 end
1601
1602 local ok, err = um.enable_user(username, host);
1603 if not ok and err ~= "method not implemented" then
1604 return nil, "Could not enable user: "..err;
1605 end
1606 end
1607 else
1608 local ok, err = um.create_user(username, password, host);
1609 if not ok then
1610 return nil, "Could not create user: "..err;
1611 end
1612 end
1613
1614 return true, "User created";
1615 end 1597 end
1616 1598
1617 function def_env.user:disable(jid) 1599 function def_env.user:disable(jid)
1618 local username, host = jid_split(jid); 1600 local username, host = jid_split(jid);
1619 if not prosody.hosts[host] then 1601 if not prosody.hosts[host] then