From 62d687ff4e986b26fd444acd9ab3fdbfc24bdf6d Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Mon, 3 Aug 2026 18:05:49 -0700 Subject: [PATCH] Fix #435: add --role/-r to creategroup tabcmd Classic accepts a default site role for the group at creation time via --role/-r; users added later without an explicit role inherit this default. tabcmd 2 was missing the flag, so groups were always created with no minimum_site_role. Reuse UserCommand.set_role_arg for the same choices and case-insensitive parsing that createsiteusers/removeusers use, and set GroupItem.minimum_site_role before calling groups.create when the flag was supplied. TSC handles the wire-format via update_req(). Fixes #435. --- tabcmd/commands/group/create_group_command.py | 6 ++++++ tests/parsers/test_parser_create_group.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tabcmd/commands/group/create_group_command.py b/tabcmd/commands/group/create_group_command.py index ff04039f..162e029f 100644 --- a/tabcmd/commands/group/create_group_command.py +++ b/tabcmd/commands/group/create_group_command.py @@ -3,6 +3,7 @@ from tabcmd.commands.auth.session import Session from tabcmd.commands.constants import Errors from tabcmd.commands.server import Server +from tabcmd.commands.user.user_data import UserCommand from tabcmd.execution.localize import _ from tabcmd.execution.logger_config import log @@ -19,6 +20,7 @@ class CreateGroupCommand(Server): def define_args(create_group_parser): args_group = create_group_parser.add_argument_group(title=CreateGroupCommand.name) args_group.add_argument("name") + UserCommand.set_role_arg(args_group) @classmethod def run_command(cls, args): @@ -29,6 +31,10 @@ def run_command(cls, args): try: logger.info(_("creategroup.status").format(args.name)) new_group = TSC.GroupItem(args.name) + if getattr(args, "role", None): + # Classic parity: --role/-r sets the group's default site role, so + # users added later without an explicit role inherit this one. + new_group.minimum_site_role = args.role server.groups.create(new_group) logger.info(_("common.output.succeeded")) except Exception as e: diff --git a/tests/parsers/test_parser_create_group.py b/tests/parsers/test_parser_create_group.py index db9500aa..b70e3cc6 100644 --- a/tests/parsers/test_parser_create_group.py +++ b/tests/parsers/test_parser_create_group.py @@ -20,3 +20,19 @@ def test_creategroup_parser_missing_all_args(self): mock_args = [commandname] with self.assertRaises(SystemExit): self.parser_under_test.parse_args(mock_args) + + def test_creategroup_parser_role_flag(self): + args = self.parser_under_test.parse_args([commandname, "name", "--role", "Viewer"]) + assert args.role == "Viewer" + + def test_creategroup_parser_role_short_flag(self): + args = self.parser_under_test.parse_args([commandname, "name", "-r", "Explorer"]) + assert args.role == "Explorer" + + def test_creategroup_parser_role_case_insensitive(self): + args = self.parser_under_test.parse_args([commandname, "name", "--role", "creator"]) + assert args.role == "Creator" + + def test_creategroup_parser_role_optional(self): + args = self.parser_under_test.parse_args([commandname, "name"]) + assert args.role is None