diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-03-02 07:24:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-02 07:24:26 +0100 |
commit | 6c08266ee93f6a038e8f96253791b4e5793237b1 (patch) | |
tree | fd6ab9ffffd560a200cc5eb7f36b0d10ef15ed96 /gitlab | |
parent | 9a30266d197c45b00bafd4cea2aa4ca30637046b (diff) | |
parent | c8c4b4262113860b61318706b913f45634279ec6 (diff) | |
download | gitlab-6c08266ee93f6a038e8f96253791b4e5793237b1.tar.gz |
Merge pull request #445 from esabouraud/feature-unshare
Add support for unsharing projects with groups
Diffstat (limited to 'gitlab')
-rw-r--r-- | gitlab/v3/cli.py | 8 | ||||
-rw-r--r-- | gitlab/v3/objects.py | 14 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 16 |
3 files changed, 38 insertions, 0 deletions
diff --git a/gitlab/v3/cli.py b/gitlab/v3/cli.py index a8e3a5f..94fa03c 100644 --- a/gitlab/v3/cli.py +++ b/gitlab/v3/cli.py @@ -69,6 +69,7 @@ EXTRA_ACTIONS = { '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 @@ class GitlabCLI(object): 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 0db9dfd..dec2933 100644 --- a/gitlab/v3/objects.py +++ b/gitlab/v3/objects.py @@ -2056,6 +2056,20 @@ class Project(GitlabObject): 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. diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 69c3185..16564e4 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -2672,6 +2672,22 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): '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) |