From 85f116f9f39501ecec3c33fdd2d638230ae3fe73 Mon Sep 17 00:00:00 2001 From: Johnny5 Date: Sat, 21 Oct 2023 12:58:50 -0500 Subject: [PATCH] Bitbucket Cloud: Adding getting workspace members. (#1266) --- .../bitbucket/cloud/workspaces/__init__.py | 7 +++ .../bitbucket/cloud/workspaces/members.py | 62 +++++++++++++++++++ docs/bitbucket.rst | 7 +++ 3 files changed, 76 insertions(+) create mode 100644 atlassian/bitbucket/cloud/workspaces/members.py diff --git a/atlassian/bitbucket/cloud/workspaces/__init__.py b/atlassian/bitbucket/cloud/workspaces/__init__.py index 19d1c17a9..f40768e32 100644 --- a/atlassian/bitbucket/cloud/workspaces/__init__.py +++ b/atlassian/bitbucket/cloud/workspaces/__init__.py @@ -3,6 +3,7 @@ from requests import HTTPError from ..base import BitbucketCloudBase +from .members import WorkspaceMembers from .permissions import Permissions from .projects import Projects from ..repositories import WorkspaceRepositories @@ -88,6 +89,7 @@ def __init__(self, data, *args, **kwargs): self.__permissions = Permissions(self.url_joiner(self.url, "permissions"), **self._new_session_args) self.__projects = Projects(self.get_link("projects"), **self._new_session_args) self.__repositories = WorkspaceRepositories(self.get_link("repositories"), **self._new_session_args) + self.__members = WorkspaceMembers(self.get_link("members"), **self._new_session_args) @property def name(self): @@ -137,3 +139,8 @@ def projects(self): def repositories(self): """The workspace repositories""" return self.__repositories + + @property + def members(self): + """The workspace members""" + return self.__members diff --git a/atlassian/bitbucket/cloud/workspaces/members.py b/atlassian/bitbucket/cloud/workspaces/members.py new file mode 100644 index 000000000..c770eb47c --- /dev/null +++ b/atlassian/bitbucket/cloud/workspaces/members.py @@ -0,0 +1,62 @@ +# coding=utf-8 + +from ..base import BitbucketCloudBase + + +class WorkspaceMembers(BitbucketCloudBase): + def __init__(self, url, *args, **kwargs): + super(WorkspaceMembers, self).__init__(url, *args, **kwargs) + + def __get_object(self, data): + return WorkspaceMember(data, **self._new_session_args) + + def each(self): + """ + Get all members in the workspace + + :return: A generator for the member objects + + API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-workspace-members-get + """ + for member in self._get_paged(None): + yield self.__get_object(member) + + return + + def get(self, member): + """ + Returns the requested member + + :param member: string: Member's UUID or Atlassian ID. + + :return: The requested Member object + + API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-workspace-members-member-get + """ + + return self.__get_object(super(WorkspaceMembers, self).get(member)) + + +class WorkspaceMember(BitbucketCloudBase): + def __init__(self, data, *args, **kwargs): + super(WorkspaceMember, self).__init__(None, *args, data=data, expected_type="workspace_membership", **kwargs) + + @property + def links(self): + """The member links""" + return self.get_data("links") + + @property + def type(self): + """The member type""" + return self.get_data("type") + + @property + def user(self): + """The member user dictionary""" + return self.get_data("user") + + @property + def workspace(self): + """The member workspace dictionary""" + return self.get_data("workspace") diff --git a/docs/bitbucket.rst b/docs/bitbucket.rst index 0dd3d5472..35d1979b9 100755 --- a/docs/bitbucket.rst +++ b/docs/bitbucket.rst @@ -413,6 +413,13 @@ Bitbucket Cloud # Delete repository_variable repository_variable.delete() + # Get a list of workspace members + workplace.members.each() + + # Get a specific workspace member + workplace.members.get("a-user-account-id") + workplace.members.get("{a-user-uuid}") + Pipelines management --------------------