Skip to content

Commit 9322db6

Browse files
feat(group): add support for group restore API
1 parent aa44f2a commit 9322db6

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

docs/gl_objects/groups.rst

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ Remove a group::
8888
# or
8989
group.delete()
9090

91+
Restore a Group marked for deletion (Premium only):::
92+
93+
group.restore()
94+
95+
9196
Share/unshare the group with a group::
9297

9398
group.share(group2.id, gitlab.const.AccessLevel.DEVELOPER)

gitlab/v4/objects/groups.py

+15
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,21 @@ def unshare(self, group_id: int, **kwargs: Any) -> None:
287287
path = f"/groups/{self.encoded_id}/share/{group_id}"
288288
self.manager.gitlab.http_delete(path, **kwargs)
289289

290+
@cli.register_custom_action("Group")
291+
@exc.on_http_error(exc.GitlabRestoreError)
292+
def restore(self, **kwargs: Any) -> None:
293+
"""Restore a group marked for deletion..
294+
295+
Args:
296+
**kwargs: Extra options to send to the server (e.g. sudo)
297+
298+
Raises:
299+
GitlabAuthenticationError: If authentication is not correct
300+
GitlabRestoreError: If the server failed to perform the request
301+
"""
302+
path = f"/groups/{self.encoded_id}/restore"
303+
self.manager.gitlab.http_post(path, **kwargs)
304+
290305

291306
class GroupManager(CRUDMixin, RESTManager):
292307
_path = "/groups"

tests/unit/objects/test_groups.py

+17
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ def resp_delete_saml_group_link(no_content):
316316
yield rsps
317317

318318

319+
@pytest.fixture
320+
def resp_restore_group(created_content):
321+
with responses.RequestsMock() as rsps:
322+
rsps.add(
323+
method=responses.POST,
324+
url="http://localhost/api/v4/groups/1/restore",
325+
json=created_content,
326+
content_type="application/json",
327+
status=201,
328+
)
329+
yield rsps
330+
331+
319332
def test_get_group(gl, resp_groups):
320333
data = gl.groups.get(1)
321334
assert isinstance(data, gitlab.v4.objects.Group)
@@ -453,3 +466,7 @@ def test_create_saml_group_link(group, resp_create_saml_group_link):
453466
def test_delete_saml_group_link(group, resp_delete_saml_group_link):
454467
saml_group_link = group.saml_group_links.create(create_saml_group_link_request_body)
455468
saml_group_link.delete()
469+
470+
471+
def test_group_restore(group, resp_restore_group):
472+
group.restore()

0 commit comments

Comments
 (0)