Skip to content

Add support for unsharing projects with groups #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/gl_objects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions gitlab/v3/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']},
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions gitlab/v3/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 16 additions & 0 deletions gitlab/v4/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down