|
12 | 12 | from kili.domain.types import ListOrTuple |
13 | 13 | from kili.exceptions import NotFound |
14 | 14 |
|
15 | | -from .mappers import project_input_mapper |
| 15 | +from .common import get_assignees_to_add_ids |
| 16 | +from .mappers import ( |
| 17 | + add_review_step_input_mapper, |
| 18 | + delete_step_input_mapper, |
| 19 | + project_input_mapper, |
| 20 | + rename_step_input_mapper, |
| 21 | + update_labeling_step_properties_input_mapper, |
| 22 | + update_review_step_properties_input_mapper, |
| 23 | +) |
16 | 24 | from .operations import ( |
| 25 | + get_add_review_step_mutation, |
| 26 | + get_delete_step_mutation, |
| 27 | + get_rename_step_mutation, |
17 | 28 | get_steps_query, |
| 29 | + get_update_labeling_step_properties_mutation, |
18 | 30 | get_update_project_workflow_mutation, |
| 31 | + get_update_review_step_properties_mutation, |
| 32 | +) |
| 33 | +from .types import ( |
| 34 | + AddReviewStepInput, |
| 35 | + DeleteStepInput, |
| 36 | + ProjectWorkflowDataKiliAPIGatewayInput, |
| 37 | + RenameStepInput, |
| 38 | + UpdateLabelingStepPropertiesInput, |
| 39 | + UpdateReviewStepPropertiesInput, |
19 | 40 | ) |
20 | | -from .types import ProjectWorkflowDataKiliAPIGatewayInput |
21 | 41 |
|
22 | 42 |
|
23 | 43 | class ProjectWorkflowOperationMixin(BaseOperationMixin): |
@@ -72,7 +92,7 @@ def list_activated_project_users(self, project_id: str) -> list[dict]: |
72 | 92 | return list( |
73 | 93 | ProjectUserQuery(self.graphql_client, self.http_client)( |
74 | 94 | where=where, |
75 | | - fields=["role", "user.id"], |
| 95 | + fields=["role", "user.id", "user.email"], |
76 | 96 | options=QueryOptions(disable_tqdm=True), |
77 | 97 | ) |
78 | 98 | ) |
@@ -177,3 +197,61 @@ def remove_reviewers_from_step( |
177 | 197 | ) |
178 | 198 |
|
179 | 199 | return removed_emails |
| 200 | + |
| 201 | + def add_review_step(self, data: AddReviewStepInput) -> dict: |
| 202 | + """Add a review step to a project workflow.""" |
| 203 | + existing_members = self.list_activated_project_users(data.project_id) |
| 204 | + assignees_to_add = get_assignees_to_add_ids(existing_members, data.assignees) |
| 205 | + data.assignees = assignees_to_add |
| 206 | + variables = {"input": add_review_step_input_mapper(data)} |
| 207 | + mutation = get_add_review_step_mutation() |
| 208 | + result = self.graphql_client.execute(mutation, variables) |
| 209 | + steps = result.get("data", {}).get("steps", []) |
| 210 | + step = next((step for step in steps if step.get("name") == data.step_name), None) |
| 211 | + if not step: |
| 212 | + raise NotFound(f"Could not find the stepId of the step {data.step_name}.") |
| 213 | + return step |
| 214 | + |
| 215 | + def update_labeling_step_properties(self, data: UpdateLabelingStepPropertiesInput) -> dict: |
| 216 | + """Update properties of a labeling step.""" |
| 217 | + variables = {"input": update_labeling_step_properties_input_mapper(data)} |
| 218 | + mutation = get_update_labeling_step_properties_mutation() |
| 219 | + result = self.graphql_client.execute(mutation, variables) |
| 220 | + steps = result.get("data", {}).get("steps", []) |
| 221 | + step = next((step for step in steps if step.get("id") == data.step_id), None) |
| 222 | + if not step: |
| 223 | + raise NotFound(f"Could not find the step with id {data.step_id}.") |
| 224 | + return step |
| 225 | + |
| 226 | + def update_review_step_properties(self, data: UpdateReviewStepPropertiesInput) -> dict: |
| 227 | + """Update properties of a review step.""" |
| 228 | + if data.assignees is not None: |
| 229 | + existing_members = self.list_activated_project_users(data.project_id) |
| 230 | + assignees_to_add = get_assignees_to_add_ids(existing_members, data.assignees) |
| 231 | + data.assignees = assignees_to_add |
| 232 | + variables = {"input": update_review_step_properties_input_mapper(data)} |
| 233 | + mutation = get_update_review_step_properties_mutation() |
| 234 | + result = self.graphql_client.execute(mutation, variables) |
| 235 | + steps = result.get("data", {}).get("steps", []) |
| 236 | + step = next((step for step in steps if step.get("id") == data.step_id), None) |
| 237 | + if not step: |
| 238 | + raise NotFound(f"Could not find the step with id {data.step_id}.") |
| 239 | + return step |
| 240 | + |
| 241 | + def delete_step(self, data: DeleteStepInput) -> dict: |
| 242 | + """Delete a step from a project workflow.""" |
| 243 | + variables = {"input": delete_step_input_mapper(data)} |
| 244 | + mutation = get_delete_step_mutation() |
| 245 | + result = self.graphql_client.execute(mutation, variables) |
| 246 | + return result["data"] |
| 247 | + |
| 248 | + def rename_step(self, data: RenameStepInput) -> dict: |
| 249 | + """Rename a step in a project workflow.""" |
| 250 | + variables = {"input": rename_step_input_mapper(data)} |
| 251 | + mutation = get_rename_step_mutation() |
| 252 | + result = self.graphql_client.execute(mutation, variables) |
| 253 | + steps = result.get("data", {}).get("steps", []) |
| 254 | + step = next((step for step in steps if step.get("id") == data.step_id), None) |
| 255 | + if not step: |
| 256 | + raise NotFound(f"Could not find the step with id {data.step_id}.") |
| 257 | + return step |
0 commit comments