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

Commit7c6e541

Browse files
committed
feat: add share/unshare group with group
1 parent1606310 commit7c6e541

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

‎docs/gl_objects/groups.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ Remove a group::
7474
# or
7575
group.delete()
7676

77+
Share/unshare the group with a group::
78+
79+
group.share(group2.id, gitlab.DEVELOPER_ACCESS)
80+
group.unshare(group2.id)
81+
7782
Import / Export
7883
===============
7984

‎gitlab/v4/objects.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,44 @@ def ldap_sync(self, **kwargs):
14671467
path="/groups/%s/ldap_sync"%self.get_id()
14681468
self.manager.gitlab.http_post(path,**kwargs)
14691469

1470+
@cli.register_custom_action("Group", ("group_id","group_access"), ("expires_at",))
1471+
@exc.on_http_error(exc.GitlabCreateError)
1472+
defshare(self,group_id,group_access,expires_at=None,**kwargs):
1473+
"""Share the group with a group.
1474+
1475+
Args:
1476+
group_id (int): ID of the group.
1477+
group_access (int): Access level for the group.
1478+
**kwargs: Extra options to send to the server (e.g. sudo)
1479+
1480+
Raises:
1481+
GitlabAuthenticationError: If authentication is not correct
1482+
GitlabCreateError: If the server failed to perform the request
1483+
"""
1484+
path="/groups/%s/share"%self.get_id()
1485+
data= {
1486+
"group_id":group_id,
1487+
"group_access":group_access,
1488+
"expires_at":expires_at,
1489+
}
1490+
self.manager.gitlab.http_post(path,post_data=data,**kwargs)
1491+
1492+
@cli.register_custom_action("Group", ("group_id",))
1493+
@exc.on_http_error(exc.GitlabDeleteError)
1494+
defunshare(self,group_id,**kwargs):
1495+
"""Delete a shared group link within a group.
1496+
1497+
Args:
1498+
group_id (int): ID of the group.
1499+
**kwargs: Extra options to send to the server (e.g. sudo)
1500+
1501+
Raises:
1502+
GitlabAuthenticationError: If authentication is not correct
1503+
GitlabDeleteError: If the server failed to perform the request
1504+
"""
1505+
path="/groups/%s/share/%s"% (self.get_id(),group_id)
1506+
self.manager.gitlab.http_delete(path,**kwargs)
1507+
14701508

14711509
classGroupManager(CRUDMixin,RESTManager):
14721510
_path="/groups"

‎tools/python_test_v4.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@
255255

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

259-
assertlen(gl.groups.list())==3
260+
assertlen(gl.groups.list())==4
260261
assertlen(gl.groups.list(search="oup1"))==1
261262
assertgroup3.parent_id==p_id
262263
assertgroup2.subgroups.list()[0].id==group3.id
@@ -266,6 +267,16 @@
266267

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

270+
group4.share(group1.id,gitlab.const.DEVELOPER_ACCESS)
271+
group4.share(group2.id,gitlab.const.MAINTAINER_ACCESS)
272+
# Reload group4 to have updated shared_with_groups
273+
group4=gl.groups.get(group4.id)
274+
assertlen(group4.shared_with_groups)==2
275+
group4.unshare(group1.id)
276+
# Reload group4 to have updated shared_with_groups
277+
group4=gl.groups.get(group4.id)
278+
assertlen(group4.shared_with_groups)==1
279+
269280
# User memberships (admin only)
270281
memberships1=user1.memberships.list()
271282
assertlen(memberships1)==1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp