Skip to content

Commit

Permalink
feat(group): add support for group restore API
Browse files Browse the repository at this point in the history
  • Loading branch information
mahadevan-karthi-dwp authored and JohnVillalovos committed Jan 18, 2023
1 parent aa44f2a commit 9322db6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/gl_objects/groups.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions gitlab/v4/objects/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,21 @@ def unshare(self, group_id: int, **kwargs: Any) -> None:
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"
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/objects/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit 9322db6

Please sign in to comment.