From 35f4ad15917a42c3f9bbeb0e60cc111b24c9e21a Mon Sep 17 00:00:00 2001 From: derek-globus <113056046+derek-globus@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:02:41 -0500 Subject: [PATCH] globus group update --terms-and-conditions (#1038) --- ...erek_groups_update_terms_and_conditions.md | 4 +++ src/globus_cli/commands/group/_common.py | 1 + src/globus_cli/commands/group/update.py | 14 ++++++++--- tests/files/api_fixtures/groups.yaml | 1 + tests/functional/groups/test_group_update.py | 25 +++++++++++++++---- 5 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 changelog.d/20241015_133817_derek_groups_update_terms_and_conditions.md diff --git a/changelog.d/20241015_133817_derek_groups_update_terms_and_conditions.md b/changelog.d/20241015_133817_derek_groups_update_terms_and_conditions.md new file mode 100644 index 000000000..5dc5f3360 --- /dev/null +++ b/changelog.d/20241015_133817_derek_groups_update_terms_and_conditions.md @@ -0,0 +1,4 @@ + +### Enhancements + +* Added a `--terms-and-conditions` option to the `globus group update` command. diff --git a/src/globus_cli/commands/group/_common.py b/src/globus_cli/commands/group/_common.py index 40f54c213..6f0f27514 100644 --- a/src/globus_cli/commands/group/_common.py +++ b/src/globus_cli/commands/group/_common.py @@ -64,6 +64,7 @@ "my_memberships[].role", formatter=formatters.SortedArray, ), + Field("Terms and Conditions", "terms_and_conditions", wrap_enabled=True), ] GROUP_FIELDS = [Field("Group ID", "id")] + _BASE_GROUP_RECORD_FIELDS GROUP_FIELDS_W_SUBSCRIPTION = ( diff --git a/src/globus_cli/commands/group/update.py b/src/globus_cli/commands/group/update.py index 220860788..dd8b46422 100644 --- a/src/globus_cli/commands/group/update.py +++ b/src/globus_cli/commands/group/update.py @@ -15,6 +15,9 @@ @group_id_arg @click.option("--name", help="Name for the group") @click.option("--description", help="Description for the group") +@click.option( + "--terms-and-conditions", help="Terms and conditions for group membership" +) @LoginManager.requires_login("groups") def group_update( login_manager: LoginManager, @@ -22,6 +25,7 @@ def group_update( group_id: uuid.UUID, name: str | None, description: str | None, + terms_and_conditions: str | None, ) -> None: """Update an existing group.""" groups_client = login_manager.get_groups_client() @@ -30,10 +34,14 @@ def group_update( group = groups_client.get_group(group_id) # assemble put data using existing values for any field not given - # note that the API does not accept the full group document, so we must - # specify name and description instead of just iterating kwargs + # note that the API only allows modification of certain fields + # https://groups.api.globus.org/redoc#tag/groups/operation/update_group_v2_groups__group_id__put data = {} - for attrname, argval in (("name", name), ("description", description)): + for attrname, argval in ( + ("name", name), + ("description", description), + ("terms_and_conditions", terms_and_conditions), + ): if argval is not None: data[attrname] = argval else: diff --git a/tests/files/api_fixtures/groups.yaml b/tests/files/api_fixtures/groups.yaml index aadc99641..d56d03ef5 100644 --- a/tests/files/api_fixtures/groups.yaml +++ b/tests/files/api_fixtures/groups.yaml @@ -74,6 +74,7 @@ groups: "id": "8b7d57bc-1666-11ec-88b2-f50515619d57", "name": "Group 1", "description": "The first group.", + "terms_and_conditions": null, "group_type": "regular", "enforce_session": false, "my_memberships": [ diff --git a/tests/functional/groups/test_group_update.py b/tests/functional/groups/test_group_update.py index aef7fce24..e1b03d8ce 100644 --- a/tests/functional/groups/test_group_update.py +++ b/tests/functional/groups/test_group_update.py @@ -7,11 +7,26 @@ @pytest.mark.parametrize( "add_args, payload_contains", ( - (["--name", "New Name"], {"name": "New Name"}), - (["--description", "New Description"], {"description": "New Description"}), + (("--name", "New Name"), {"name": "New Name"}), + (("--description", "New Description"), {"description": "New Description"}), ( - ["--name", "New Name", "--description", "New Description"], - {"description": "New Description", "name": "New Name"}, + ("--terms-and-conditions", "New Terms and Conditions"), + {"terms_and_conditions": "New Terms and Conditions"}, + ), + ( + ( + "--name", + "New Name", + "--description", + "New Description", + "--terms-and-conditions", + "New Terms and Conditions", + ), + { + "description": "New Description", + "name": "New Name", + "terms_and_conditions": "New Terms and Conditions", + }, ), ), ) @@ -28,7 +43,7 @@ def test_group_update(run_line, add_args, payload_contains): group1_description = meta["group1_description"] # update name - result = run_line(["globus", "group", "update", group1_id] + add_args) + result = run_line(("globus", "group", "update", group1_id) + add_args) assert "Group updated successfully" in result.output # confirm that 'name' and 'description' are both always sent,