Skip to content

Commit 6c08266

Browse files
author
Gauvain Pocentek
authored
Merge pull request #445 from esabouraud/feature-unshare
Add support for unsharing projects with groups
2 parents 9a30266 + c8c4b42 commit 6c08266

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

docs/gl_objects/projects.py

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
project.share(group.id, gitlab.DEVELOPER_ACCESS)
102102
# end share
103103

104+
# unshare
105+
project.unshare(group.id)
106+
# end unshare
107+
104108
# hook list
105109
hooks = project.hooks.list()
106110
# end hook list

gitlab/v3/cli.py

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
'archive': {'required': ['id']},
7070
'unarchive': {'required': ['id']},
7171
'share': {'required': ['id', 'group-id', 'group-access']},
72+
'unshare': {'required': ['id', 'group-id']},
7273
'upload': {'required': ['id', 'filename', 'filepath']}},
7374
gitlab.v3.objects.User: {
7475
'block': {'required': ['id']},
@@ -213,6 +214,13 @@ def do_project_share(self, cls, gl, what, args):
213214
except Exception as e:
214215
cli.die("Impossible to share project", e)
215216

217+
def do_project_unshare(self, cls, gl, what, args):
218+
try:
219+
o = self.do_get(cls, gl, what, args)
220+
o.unshare(args['group_id'])
221+
except Exception as e:
222+
cli.die("Impossible to unshare project", e)
223+
216224
def do_user_block(self, cls, gl, what, args):
217225
try:
218226
o = self.do_get(cls, gl, what, args)

gitlab/v3/objects.py

+14
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,20 @@ def share(self, group_id, group_access, **kwargs):
20562056
r = self.gitlab._raw_post(url, data=data, **kwargs)
20572057
raise_error_from_response(r, GitlabCreateError, 201)
20582058

2059+
def unshare(self, group_id, **kwargs):
2060+
"""Delete a shared project link within a group.
2061+
2062+
Args:
2063+
group_id (int): ID of the group.
2064+
2065+
Raises:
2066+
GitlabConnectionError: If the server cannot be reached.
2067+
GitlabDeleteError: If the server fails to perform the request.
2068+
"""
2069+
url = "/projects/%s/share/%s" % (self.id, group_id)
2070+
r = self.gitlab._raw_delete(url, **kwargs)
2071+
raise_error_from_response(r, GitlabDeleteError, 204)
2072+
20592073
def trigger_build(self, ref, token, variables={}, **kwargs):
20602074
"""Trigger a CI build.
20612075

gitlab/v4/objects.py

+16
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,22 @@ def share(self, group_id, group_access, expires_at=None, **kwargs):
26722672
'expires_at': expires_at}
26732673
self.manager.gitlab.http_post(path, post_data=data, **kwargs)
26742674

2675+
@cli.register_custom_action('Project', ('group_id', ))
2676+
@exc.on_http_error(exc.GitlabDeleteError)
2677+
def unshare(self, group_id, **kwargs):
2678+
"""Delete a shared project link within a group.
2679+
2680+
Args:
2681+
group_id (int): ID of the group.
2682+
**kwargs: Extra options to send to the server (e.g. sudo)
2683+
2684+
Raises:
2685+
GitlabAuthenticationError: If authentication is not correct
2686+
GitlabDeleteError: If the server failed to perform the request
2687+
"""
2688+
path = '/projects/%s/share/%s' % (self.get_id(), group_id)
2689+
self.manager.gitlab.http_delete(path, **kwargs)
2690+
26752691
# variables not supported in CLI
26762692
@cli.register_custom_action('Project', ('ref', 'token'))
26772693
@exc.on_http_error(exc.GitlabCreateError)

0 commit comments

Comments
 (0)