Changeset

13684:026a75a443de 13.0

mod_admin_shell: Hide secondary role commands, focus on primary roles Secondary roles are an advanced feature without any strong use cases currently. Having multiple ways to manage roles is confusing. Now the 'user:role' command will just show the primary role if that is all there is, but will list secondary roles too if there are any (which in 99.9% of cases there won't be).
author Matthew Wild <mwild1@gmail.com>
date Thu, 13 Feb 2025 16:18:59 +0000
parents 13683:4c1f26b4883b
children 13685:b9fce1651699
files plugins/mod_admin_shell.lua
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_admin_shell.lua	Thu Feb 13 16:16:19 2025 +0000
+++ b/plugins/mod_admin_shell.lua	Thu Feb 13 16:18:59 2025 +0000
@@ -364,6 +364,10 @@
 	};
 end
 
+local function hidden_command(s)
+	return describe_command(s, true);
+end
+
 -- Console commands --
 -- These are simple commands, not valid standalone in Lua
 
@@ -1803,9 +1807,8 @@
 	end);
 end
 
-describe_command [[user:roles(jid, host) - Show current roles for an user]]
+describe_command [[user:role(jid, host) - Show primary role for a user]]
 function def_env.user:role(jid, host)
-	local print = self.session.print;
 	local username, userhost = jid_split(jid);
 	if host == nil then host = userhost; end
 	if not prosody.hosts[host] then
@@ -1817,15 +1820,22 @@
 	local primary_role = um.get_user_role(username, host);
 	local secondary_roles = um.get_user_secondary_roles(username, host);
 
+	local primary_role_desc = primary_role and primary_role.name or "<none>";
+
+	local secondary_roles = um.get_user_secondary_roles(username, host);
+
 	print(primary_role and primary_role.name or "<none>");
 
-	local count = primary_role and 1 or 0;
+	local n_secondary = 0;
 	for role_name in pairs(secondary_roles or {}) do
-		count = count + 1;
+		n_secondary = n_secondary + 1;
 		print(role_name.." (secondary)");
 	end
 
-	return true, count == 1 and "1 role" or count.." roles";
+	if n_secondary > 0 then
+		return true, primary_role_desc.." (primary)";
+	end
+	return true, primary_role_desc;
 end
 def_env.user.roles = def_env.user.role;
 
@@ -1847,7 +1857,7 @@
 	end
 end
 
-describe_command [[user:addrole(jid, host, role) - Add a secondary role to a user]]
+hidden_command [[user:addrole(jid, host, role) - Add a secondary role to a user]]
 function def_env.user:addrole(jid, host, new_role)
 	local username, userhost = jid_split(jid);
 	if new_role == nil then host, new_role = userhost, host; end
@@ -1865,7 +1875,7 @@
 	return true, "Role added";
 end
 
-describe_command [[user:delrole(jid, host, role) - Remove a secondary role from a user]]
+hidden_command [[user:delrole(jid, host, role) - Remove a secondary role from a user]]
 function def_env.user:delrole(jid, host, role_name)
 	local username, userhost = jid_split(jid);
 	if role_name == nil then host, role_name = userhost, host; end