File: __init__.py

package info (click to toggle)
python-bioblend 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,096 kB
  • sloc: python: 7,596; sh: 219; makefile: 158
file content (217 lines) | stat: -rw-r--r-- 6,410 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
"""
Contains possible interactions with the Galaxy Groups
"""
from typing import (
    Any,
    Dict,
    List,
    Optional,
    TYPE_CHECKING,
)

from bioblend.galaxy.client import Client

if TYPE_CHECKING:
    from bioblend.galaxy import GalaxyInstance


class GroupsClient(Client):
    module = "groups"

    def __init__(self, galaxy_instance: "GalaxyInstance") -> None:
        super().__init__(galaxy_instance)

    def get_groups(self) -> List[Dict[str, Any]]:
        """
        Get all (not deleted) groups.

        :rtype: list
        :return: A list of dicts with details on individual groups.
          For example::

            [{'id': '33abac023ff186c2',
              'model_class': 'Group',
              'name': 'Listeria',
              'url': '/api/groups/33abac023ff186c2'},
             {'id': '73187219cd372cf8',
              'model_class': 'Group',
              'name': 'LPN',
              'url': '/api/groups/73187219cd372cf8'}]
        """
        return self._get()

    def show_group(self, group_id: str) -> Dict[str, Any]:
        """
        Get details of a given group.

        :type group_id: str
        :param group_id: Encoded group ID

        :rtype: dict
        :return: A description of group
          For example::

            {'id': '33abac023ff186c2',
             'model_class': 'Group',
             'name': 'Listeria',
             'roles_url': '/api/groups/33abac023ff186c2/roles',
             'url': '/api/groups/33abac023ff186c2',
             'users_url': '/api/groups/33abac023ff186c2/users'}
        """
        return self._get(id=group_id)

    def create_group(
        self, group_name: str, user_ids: Optional[List[str]] = None, role_ids: Optional[List[str]] = None
    ) -> List[Dict[str, Any]]:
        """
        Create a new group.

        :type group_name: str
        :param group_name: A name for the new group

        :type user_ids: list
        :param user_ids: A list of encoded user IDs to add to the new group

        :type role_ids: list
        :param role_ids: A list of encoded role IDs to add to the new group

        :rtype: list
        :return: A (size 1) list with newly created group
          details, like::

            [{'id': '7c9636938c3e83bf',
              'model_class': 'Group',
              'name': 'My Group Name',
              'url': '/api/groups/7c9636938c3e83bf'}]
        """
        if user_ids is None:
            user_ids = []
        if role_ids is None:
            role_ids = []
        payload = {"name": group_name, "user_ids": user_ids, "role_ids": role_ids}
        return self._post(payload)

    def update_group(
        self,
        group_id: str,
        group_name: Optional[str] = None,
        user_ids: Optional[List[str]] = None,
        role_ids: Optional[List[str]] = None,
    ) -> None:
        """
        Update a group.

        :type group_id: str
        :param group_id: Encoded group ID

        :type group_name: str
        :param group_name: A new name for the group. If None, the group name is
          not changed.

        :type user_ids: list
        :param user_ids: New list of encoded user IDs for the group. It will
          substitute the previous list of users (with [] if not specified)

        :type role_ids: list
        :param role_ids: New list of encoded role IDs for the group. It will
          substitute the previous list of roles (with [] if not specified)

        :rtype: None
        :return: None
        """
        if user_ids is None:
            user_ids = []
        if role_ids is None:
            role_ids = []
        payload = {"name": group_name, "user_ids": user_ids, "role_ids": role_ids}
        return self._put(payload=payload, id=group_id)

    def get_group_users(self, group_id: str) -> List[Dict[str, Any]]:
        """
        Get the list of users associated to the given group.

        :type group_id: str
        :param group_id: Encoded group ID

        :rtype: list of dicts
        :return: List of group users' info
        """
        url = self._make_url(group_id) + "/users"
        return self._get(url=url)

    def get_group_roles(self, group_id: str) -> List[Dict[str, Any]]:
        """
        Get the list of roles associated to the given group.

        :type group_id: str
        :param group_id: Encoded group ID

        :rtype: list of dicts
        :return: List of group roles' info
        """
        url = self._make_url(group_id) + "/roles"
        return self._get(url=url)

    def add_group_user(self, group_id: str, user_id: str) -> Dict[str, Any]:
        """
        Add a user to the given group.

        :type group_id: str
        :param group_id: Encoded group ID

        :type user_id: str
        :param user_id: Encoded user ID to add to the group

        :rtype: dict
        :return: Added group user's info
        """
        url = "/".join((self._make_url(group_id), "users", user_id))
        return self._put(url=url)

    def add_group_role(self, group_id: str, role_id: str) -> Dict[str, Any]:
        """
        Add a role to the given group.

        :type group_id: str
        :param group_id: Encoded group ID

        :type role_id: str
        :param role_id: Encoded role ID to add to the group

        :rtype: dict
        :return: Added group role's info
        """
        url = "/".join((self._make_url(group_id), "roles", role_id))
        return self._put(url=url)

    def delete_group_user(self, group_id: str, user_id: str) -> Dict[str, Any]:
        """
        Remove a user from the given group.

        :type group_id: str
        :param group_id: Encoded group ID

        :type user_id: str
        :param user_id: Encoded user ID to remove from the group

        :rtype: dict
        :return: The user which was removed
        """
        url = "/".join((self._make_url(group_id), "users", user_id))
        return self._delete(url=url)

    def delete_group_role(self, group_id: str, role_id: str) -> Dict[str, Any]:
        """
        Remove a role from the given group.

        :type group_id: str
        :param group_id: Encoded group ID

        :type role_id: str
        :param role_id: Encoded role ID to remove from the group

        :rtype: dict
        :return: The role which was removed
        """
        url = "/".join((self._make_url(group_id), "roles", role_id))
        return self._delete(url=url)