From f3acc565f918f24d15d9bb9487451b66566ae5d4 Mon Sep 17 00:00:00 2001 From: ChowRex Date: Fri, 8 Dec 2023 10:14:33 +0800 Subject: [PATCH] Add more Crowd functions - Using universal request to get user's group, controled by `kind` param - Using universal request to get group's member, controled by `kind` param - Add a new function to determine whether the user is a member of a group --- atlassian/crowd.py | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/atlassian/crowd.py b/atlassian/crowd.py index e8443083b..1e5878dcd 100644 --- a/atlassian/crowd.py +++ b/atlassian/crowd.py @@ -131,16 +131,44 @@ def user_delete(self, username): return self.delete(self._crowd_api_url("usermanagement", "user"), params=params) - def user_groups(self, username): + def user_groups(self, username, kind='direct'): """ Get user's all group info :param username: str - username + :param kind: str - group type :return: The specify user's group info """ - path = self._crowd_api_url("usermanagement", "user/group/direct") + path = self._crowd_api_url("usermanagement", + "user/group/{kind}".format(kind=kind)) response = self.get(path, params={'username': username}) return search('groups[*].name', response) + def group_members(self, group, kind='direct'): + """ + Get group's all direct members + :param group: str - group name + :param kind: str - group type + :return: The specify group's direct members info + """ + path = self._crowd_api_url("usermanagement", + "group/user/{kind}".format(kind=kind)) + response = self.get(path, params={'groupname': group}) + return search('users[*].name', response) + + def is_user_in_group(self, username, group, kind='direct'): + """ + Check if the user is a member of the group + :param username: str - username + :param group: str - group name + :param kind: str - group type + :return: bool - Return `True` or `False` + """ + path = self._crowd_api_url("usermanagement", + "group/user/{kind}".format(kind=kind)) + params = {'username': username, 'groupname': group} + response = self.get(path, params=params, advanced_mode=True) + return response.status_code == 200 + def group_add_user(self, username, groupname): """ Add user to group @@ -157,15 +185,6 @@ def group_add_user(self, username, groupname): json=data, ) - def group_nested_members(self, group): - """ - Get nested members of group - :param group: - :return: - """ - params = {"groupname": group} - return self.get(self._crowd_api_url("group", "nested"), params=params) - def health_check(self): """ Get health status