From 5fdd06e1ee57e42a746aefcb96d819c0ed7835bf Mon Sep 17 00:00:00 2001 From: Eric Sabouraud Date: Wed, 28 Feb 2018 15:53:25 +0100 Subject: [PATCH 1/2] Add support for unsharing projects to v4 API --- docs/gl_objects/projects.py | 4 ++++ gitlab/v4/objects.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/gl_objects/projects.py b/docs/gl_objects/projects.py index 1b0a6b95d..790841604 100644 --- a/docs/gl_objects/projects.py +++ b/docs/gl_objects/projects.py @@ -101,6 +101,10 @@ project.share(group.id, gitlab.DEVELOPER_ACCESS) # end share +# unshare +project.unshare(group.id) +# end unshare + # hook list hooks = project.hooks.list() # end hook list diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 69c31854a..16564e4e2 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -2672,6 +2672,22 @@ def share(self, group_id, group_access, expires_at=None, **kwargs): 'expires_at': expires_at} self.manager.gitlab.http_post(path, post_data=data, **kwargs) + @cli.register_custom_action('Project', ('group_id', )) + @exc.on_http_error(exc.GitlabDeleteError) + def unshare(self, group_id, **kwargs): + """Delete a shared project link within a group. + + Args: + group_id (int): ID of the group. + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabDeleteError: If the server failed to perform the request + """ + path = '/projects/%s/share/%s' % (self.get_id(), group_id) + self.manager.gitlab.http_delete(path, **kwargs) + # variables not supported in CLI @cli.register_custom_action('Project', ('ref', 'token')) @exc.on_http_error(exc.GitlabCreateError) From c8c4b4262113860b61318706b913f45634279ec6 Mon Sep 17 00:00:00 2001 From: Eric Sabouraud Date: Wed, 28 Feb 2018 16:02:12 +0100 Subject: [PATCH 2/2] Add support for unsharing projects to v3 API (untested) --- gitlab/v3/cli.py | 8 ++++++++ gitlab/v3/objects.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/gitlab/v3/cli.py b/gitlab/v3/cli.py index a8e3a5fae..94fa03cfc 100644 --- a/gitlab/v3/cli.py +++ b/gitlab/v3/cli.py @@ -69,6 +69,7 @@ 'archive': {'required': ['id']}, 'unarchive': {'required': ['id']}, 'share': {'required': ['id', 'group-id', 'group-access']}, + 'unshare': {'required': ['id', 'group-id']}, 'upload': {'required': ['id', 'filename', 'filepath']}}, gitlab.v3.objects.User: { 'block': {'required': ['id']}, @@ -213,6 +214,13 @@ def do_project_share(self, cls, gl, what, args): except Exception as e: cli.die("Impossible to share project", e) + def do_project_unshare(self, cls, gl, what, args): + try: + o = self.do_get(cls, gl, what, args) + o.unshare(args['group_id']) + except Exception as e: + cli.die("Impossible to unshare project", e) + def do_user_block(self, cls, gl, what, args): try: o = self.do_get(cls, gl, what, args) diff --git a/gitlab/v3/objects.py b/gitlab/v3/objects.py index 0db9dfd6b..dec29339b 100644 --- a/gitlab/v3/objects.py +++ b/gitlab/v3/objects.py @@ -2056,6 +2056,20 @@ def share(self, group_id, group_access, **kwargs): r = self.gitlab._raw_post(url, data=data, **kwargs) raise_error_from_response(r, GitlabCreateError, 201) + def unshare(self, group_id, **kwargs): + """Delete a shared project link within a group. + + Args: + group_id (int): ID of the group. + + Raises: + GitlabConnectionError: If the server cannot be reached. + GitlabDeleteError: If the server fails to perform the request. + """ + url = "/projects/%s/share/%s" % (self.id, group_id) + r = self.gitlab._raw_delete(url, **kwargs) + raise_error_from_response(r, GitlabDeleteError, 204) + def trigger_build(self, ref, token, variables={}, **kwargs): """Trigger a CI build.