Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add share/unshare the group with a group#1139

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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
5 changes: 5 additions & 0 deletionsdocs/gl_objects/groups.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,6 +74,11 @@ Remove a group::
# or
group.delete()

Share/unshare the group with a group::

group.share(group2.id, gitlab.DEVELOPER_ACCESS)
group.unshare(group2.id)

Import / Export
===============

Expand Down
38 changes: 38 additions & 0 deletionsgitlab/v4/objects.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1467,6 +1467,44 @@ def ldap_sync(self, **kwargs):
path = "/groups/%s/ldap_sync" % self.get_id()
self.manager.gitlab.http_post(path, **kwargs)

@cli.register_custom_action("Group", ("group_id", "group_access"), ("expires_at",))
@exc.on_http_error(exc.GitlabCreateError)
def share(self, group_id, group_access, expires_at=None, **kwargs):
"""Share the group with a group.

Args:
group_id (int): ID of the group.
group_access (int): Access level for the group.
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabCreateError: If the server failed to perform the request
"""
path = "/groups/%s/share" % self.get_id()
data = {
"group_id": group_id,
"group_access": group_access,
"expires_at": expires_at,
}
self.manager.gitlab.http_post(path, post_data=data, **kwargs)

@cli.register_custom_action("Group", ("group_id",))
@exc.on_http_error(exc.GitlabDeleteError)
def unshare(self, group_id, **kwargs):
"""Delete a shared group 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 = "/groups/%s/share/%s" % (self.get_id(), group_id)
self.manager.gitlab.http_delete(path, **kwargs)


class GroupManager(CRUDMixin, RESTManager):
_path = "/groups"
Expand Down
15 changes: 13 additions & 2 deletionstools/python_test_v4.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -255,8 +255,9 @@

p_id = gl.groups.list(search="group2")[0].id
group3 = gl.groups.create({"name": "group3", "path": "group3", "parent_id": p_id})
group4 = gl.groups.create({"name": "group4", "path": "group4"})

assert len(gl.groups.list()) ==3
assert len(gl.groups.list()) ==4
assert len(gl.groups.list(search="oup1")) == 1
assert group3.parent_id == p_id
assert group2.subgroups.list()[0].id == group3.id
Expand All@@ -266,6 +267,16 @@

group2.members.create({"access_level": gitlab.const.OWNER_ACCESS, "user_id": user2.id})

group4.share(group1.id, gitlab.const.DEVELOPER_ACCESS)
group4.share(group2.id, gitlab.const.MAINTAINER_ACCESS)
# Reload group4 to have updated shared_with_groups
group4 = gl.groups.get(group4.id)
assert len(group4.shared_with_groups) == 2
group4.unshare(group1.id)
# Reload group4 to have updated shared_with_groups
group4 = gl.groups.get(group4.id)
assert len(group4.shared_with_groups) == 1

# User memberships (admin only)
memberships1 = user1.memberships.list()
assert len(memberships1) == 1
Expand DownExpand Up@@ -419,7 +430,7 @@
gr2_project = gl.projects.create({"name": "gr2_project", "namespace_id": group2.id})
sudo_project = gl.projects.create({"name": "sudo_project"}, sudo=user1.name)

assert len(gl.projects.list(owned=True)) ==2
assert len(gl.projects.list(owned=True)) ==3
assert len(gl.projects.list(search="admin")) == 1
assert len(gl.projects.list(as_list=False)) == 4

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp