Comparison

plugins/mod_admin_shell.lua @ 13681:8f43b954bdac 13.0

mod_admin_shell: Fix result handling of user addrole/delrole commands
author Matthew Wild <mwild1@gmail.com>
date Thu, 13 Feb 2025 15:54:39 +0000
parent 13641:d980c3e03637
child 13683:4c1f26b4883b
comparison
equal deleted inserted replaced
13680:22f1444f08f9 13681:8f43b954bdac
1853 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then 1853 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then
1854 return nil, "No such user"; 1854 return nil, "No such user";
1855 elseif userhost ~= host then 1855 elseif userhost ~= host then
1856 return nil, "Can't add roles outside users own host" 1856 return nil, "Can't add roles outside users own host"
1857 end 1857 end
1858 return um.add_user_secondary_role(username, host, new_role); 1858 local role, err = um.add_user_secondary_role(username, host, new_role);
1859 if not role then
1860 return nil, err;
1861 end
1862 return true, "Role added";
1859 end 1863 end
1860 1864
1861 describe_command [[user:delrole(jid, host, role) - Remove a secondary role from a user]] 1865 describe_command [[user:delrole(jid, host, role) - Remove a secondary role from a user]]
1862 function def_env.user:delrole(jid, host, role_name) 1866 function def_env.user:delrole(jid, host, role_name)
1863 local username, userhost = jid_split(jid); 1867 local username, userhost = jid_split(jid);
1867 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then 1871 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then
1868 return nil, "No such user"; 1872 return nil, "No such user";
1869 elseif userhost ~= host then 1873 elseif userhost ~= host then
1870 return nil, "Can't remove roles outside users own host" 1874 return nil, "Can't remove roles outside users own host"
1871 end 1875 end
1872 return um.remove_user_secondary_role(username, host, role_name); 1876 local ok, err = um.remove_user_secondary_role(username, host, role_name);
1877 if not ok then
1878 return nil, err;
1879 end
1880 return true, "Role removed";
1873 end 1881 end
1874 1882
1875 describe_command [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] 1883 describe_command [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]]
1876 -- TODO switch to table view, include roles 1884 -- TODO switch to table view, include roles
1877 function def_env.user:list(host, pat) 1885 function def_env.user:list(host, pat)