Skip to content

Commit 88656f0

Browse files
authored
Update confluence.py - Add create_group and remove_group (#1180)
Based on new API endpoints provided in Confluence DC 8.2
1 parent e5824da commit 88656f0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

atlassian/confluence.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,43 @@ def get_all_groups(self, start=0, limit=1000):
20952095

20962096
return response.get("results")
20972097

2098+
def create_group(self, name):
2099+
"""
2100+
Create a group by given group parameter
2101+
2102+
:param name: str
2103+
:return: New group params
2104+
"""
2105+
url = "rest/api/admin/group"
2106+
data = { "name": name,
2107+
"type": "group" }
2108+
return self.post(url, data=data)
2109+
2110+
def remove_group(self, name):
2111+
"""
2112+
Delete a group by given group parameter
2113+
If you delete a group and content is restricted to that group, the content will be hidden from all users
2114+
2115+
:param name: str
2116+
:return:
2117+
"""
2118+
log.warning("Removing group...")
2119+
url = "rest/api/admin/group/{groupName}".format(groupName=name)
2120+
2121+
try:
2122+
response = self.delete(url)
2123+
except HTTPError as e:
2124+
if e.response.status_code == 404:
2125+
# Raise ApiError as the documented reason is ambiguous
2126+
raise ApiError(
2127+
"There is no group with the given name, "
2128+
"or the calling user does not have permission to delete it",
2129+
reason=e,
2130+
)
2131+
raise
2132+
2133+
return response
2134+
20982135
def get_group_members(self, group_name="confluence-users", start=0, limit=1000, expand=None):
20992136
"""
21002137
Get a paginated collection of users in the given group

0 commit comments

Comments
 (0)