-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy path__init__.py
More file actions
219 lines (198 loc) · 7.25 KB
/
__init__.py
File metadata and controls
219 lines (198 loc) · 7.25 KB
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
218
219
"""Project user queries."""
from collections.abc import Generator, Iterable, Sequence
from typing import (
Literal,
Optional,
overload,
)
from typeguard import typechecked
from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions
from kili.core.graphql.operations.project_user.queries import (
ProjectUserQuery,
ProjectUserWhere,
)
from kili.domain.types import ListOrTuple
from kili.entrypoints.base import BaseOperationEntrypointMixin
from kili.presentation.client.helpers.common_validators import (
disable_tqdm_if_as_generator,
)
from kili.utils.logcontext import for_all_methods, log_call
@for_all_methods(log_call, exclude=["__init__"])
class QueriesProjectUser(BaseOperationEntrypointMixin):
"""Set of ProjectUser queries."""
# pylint: disable=too-many-arguments,redefined-builtin
@overload
def project_users(
self,
project_id: str,
email: Optional[str] = None,
id: Optional[str] = None,
organization_id: Optional[str] = None,
status_in: Optional[Sequence[Literal["ACTIVATED", "ORG_ADMIN", "ORG_SUSPENDED"]]] = (
"ACTIVATED",
"ORG_ADMIN",
),
fields: ListOrTuple[str] = (
"activated",
"id",
"role",
"starred",
"user.email",
"user.id",
"status",
),
first: Optional[int] = None,
skip: int = 0,
disable_tqdm: Optional[bool] = None,
*,
as_generator: Literal[True],
) -> Generator[dict, None, None]:
...
@overload
def project_users(
self,
project_id: str,
email: Optional[str] = None,
id: Optional[str] = None,
organization_id: Optional[str] = None,
status_in: Optional[Sequence[Literal["ACTIVATED", "ORG_ADMIN", "ORG_SUSPENDED"]]] = (
"ACTIVATED",
"ORG_ADMIN",
),
fields: ListOrTuple[str] = (
"activated",
"id",
"role",
"starred",
"user.email",
"user.id",
"status",
),
first: Optional[int] = None,
skip: int = 0,
disable_tqdm: Optional[bool] = None,
*,
as_generator: Literal[False] = False,
) -> list[dict]:
...
@typechecked
def project_users(
self,
project_id: str,
email: Optional[str] = None,
id: Optional[str] = None,
organization_id: Optional[str] = None,
status_in: Optional[Sequence[Literal["ACTIVATED", "ORG_ADMIN", "ORG_SUSPENDED"]]] = (
"ACTIVATED",
"ORG_ADMIN",
),
fields: ListOrTuple[str] = (
"activated",
"id",
"role",
"starred",
"user.email",
"user.id",
"status",
),
first: Optional[int] = None,
skip: int = 0,
disable_tqdm: Optional[bool] = None,
*,
as_generator: bool = False,
) -> Iterable[dict]:
# pylint: disable=line-too-long
"""Return project users (possibly with their KPIs) that match a set of criteria.
Args:
project_id: Identifier of the project.
email: Email of the user.
id: Identifier of the user.
organization_id: Identifier of the user's organization.
status_in: If `None`, all users are returned.
- `ORG_ADMIN`: Is an Organization Admin. Is automatically added to projects.
- `ACTIVATED`: Has been invited to the project. Is not an Organization Admin
- `ORG_SUSPENDED`: Has been suspended at the organization level. Can no longer access any projects.
fields: All the fields to request among the possible fields for the projectUsers.
See [the documentation](https://api-docs.kili-technology.com/types/objects/project-user) for all possible fields.
first: Maximum number of users to return.
skip: Number of project users to skip.
disable_tqdm: If `True`, the progress bar will be disabled.
as_generator: If `True`, a generator on the project users is returned.
Returns:
An iterable with the project users that match the criteria.
Examples:
```python
# Retrieve consensus marks of all users in project
>>> kili.project_users(project_id=project_id, fields=['consensusMark', 'user.email'])
```
"""
if status_in is not None and "status" not in fields:
fields = [*fields, "status"]
where = ProjectUserWhere(
project_id=project_id,
email=email,
_id=id,
organization_id=organization_id,
)
disable_tqdm = disable_tqdm_if_as_generator(as_generator, disable_tqdm)
options = QueryOptions(disable_tqdm, first, skip)
project_users_gen = ProjectUserQuery(self.graphql_client, self.http_client)(
where, fields, options
)
if status_in is not None:
status_in_set = set(status_in)
project_users_gen = (
project_user
for project_user in project_users_gen
if project_user["status"] in status_in_set
)
if as_generator:
return project_users_gen
return list(project_users_gen)
@typechecked
def count_project_users(
self,
project_id: str,
email: Optional[str] = None,
id: Optional[str] = None,
organization_id: Optional[str] = None,
status_in: Optional[Sequence[Literal["ACTIVATED", "ORG_ADMIN", "ORG_SUSPENDED"]]] = (
"ACTIVATED",
"ORG_ADMIN",
"ORG_SUSPENDED",
),
) -> int:
"""Count the number of projects and their users that match a set of criteria.
Args:
project_id: Identifier of the project
email: Email of the user
id: Identifier of the user
organization_id: Identifier of the user's organization
status_in: If `None`, all users are returned.
- `ORG_ADMIN`: Is an Organization Admin. Is automatically added to projects.
- `ACTIVATED`: Has been invited to the project. Is not an Organization Admin
- `ORG_SUSPENDED`: Has been suspended at the organization level. Can no longer access any projects.
Returns:
The number of project users with the parameters provided
"""
if status_in is None:
where = ProjectUserWhere(
deleted=False,
project_id=project_id,
email=email,
_id=id,
organization_id=organization_id,
)
return ProjectUserQuery(self.graphql_client, self.http_client).count(where)
count = 0
for status in set(status_in):
where = ProjectUserWhere(
deleted=False,
project_id=project_id,
email=email,
_id=id,
organization_id=organization_id,
status=status,
)
count += ProjectUserQuery(self.graphql_client, self.http_client).count(where)
return count