diff options
author | Mahadevan Karthi <mahadevan.karthi@engineering.digital.dwp.gov.uk> | 2023-01-18 15:58:36 +0000 |
---|---|---|
committer | John Villalovos <john@sodarock.com> | 2023-01-18 11:37:49 -0800 |
commit | 9322db663ecdaecf399e3192810d973c6a9a4020 (patch) | |
tree | f48d39f80d7fe23f6fcfb3afbd1a45967c461f36 | |
parent | aa44f2aed8150f8c891837e06296c7bbef17c292 (diff) | |
download | gitlab-9322db663ecdaecf399e3192810d973c6a9a4020.tar.gz |
feat(group): add support for group restore API
-rw-r--r-- | docs/gl_objects/groups.rst | 5 | ||||
-rw-r--r-- | gitlab/v4/objects/groups.py | 15 | ||||
-rw-r--r-- | tests/unit/objects/test_groups.py | 17 |
3 files changed, 37 insertions, 0 deletions
diff --git a/docs/gl_objects/groups.rst b/docs/gl_objects/groups.rst index fafa40a..37977da 100644 --- a/docs/gl_objects/groups.rst +++ b/docs/gl_objects/groups.rst @@ -88,6 +88,11 @@ Remove a group:: # or group.delete() +Restore a Group marked for deletion (Premium only)::: + + group.restore() + + Share/unshare the group with a group:: group.share(group2.id, gitlab.const.AccessLevel.DEVELOPER) diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py index d03eb38..0eb516f 100644 --- a/gitlab/v4/objects/groups.py +++ b/gitlab/v4/objects/groups.py @@ -287,6 +287,21 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): path = f"/groups/{self.encoded_id}/share/{group_id}" self.manager.gitlab.http_delete(path, **kwargs) + @cli.register_custom_action("Group") + @exc.on_http_error(exc.GitlabRestoreError) + def restore(self, **kwargs: Any) -> None: + """Restore a group marked for deletion.. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabRestoreError: If the server failed to perform the request + """ + path = f"/groups/{self.encoded_id}/restore" + self.manager.gitlab.http_post(path, **kwargs) + class GroupManager(CRUDMixin, RESTManager): _path = "/groups" diff --git a/tests/unit/objects/test_groups.py b/tests/unit/objects/test_groups.py index 58c3508..1f25821 100644 --- a/tests/unit/objects/test_groups.py +++ b/tests/unit/objects/test_groups.py @@ -316,6 +316,19 @@ def resp_delete_saml_group_link(no_content): yield rsps +@pytest.fixture +def resp_restore_group(created_content): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.POST, + url="http://localhost/api/v4/groups/1/restore", + json=created_content, + content_type="application/json", + status=201, + ) + yield rsps + + def test_get_group(gl, resp_groups): data = gl.groups.get(1) assert isinstance(data, gitlab.v4.objects.Group) @@ -453,3 +466,7 @@ def test_create_saml_group_link(group, resp_create_saml_group_link): def test_delete_saml_group_link(group, resp_delete_saml_group_link): saml_group_link = group.saml_group_links.create(create_saml_group_link_request_body) saml_group_link.delete() + + +def test_group_restore(group, resp_restore_group): + group.restore() |