Skip to content

Commit fb90304

Browse files
authored
feat: Add new method to update project workflow (#1836)
1 parent 1e9cc08 commit fb90304

File tree

14 files changed

+204
-1
lines changed

14 files changed

+204
-1
lines changed

docs/sdk/project_workflow.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Project Workflow module
2+
3+
::: kili.presentation.client.project_workflow.ProjectWorkflowClientMethods

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ nav:
2828
- Project: sdk/project.md
2929
- Project User: sdk/project_user.md
3030
- Project Version: sdk/project_version.md
31+
- Project Workflow: sdk/project_workflow.md
3132
- Tag: sdk/tag.md
3233
- User: sdk/user.md
3334
- Command Line Interface:

src/kili/adapters/kili_api_gateway/kili_api_gateway.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
OrganizationOperationMixin,
1818
)
1919
from kili.adapters.kili_api_gateway.project.operations_mixin import ProjectOperationMixin
20+
from kili.adapters.kili_api_gateway.project_workflow.operations_mixin import (
21+
ProjectWorkflowOperationMixin,
22+
)
2023
from kili.adapters.kili_api_gateway.tag import TagOperationMixin
2124
from kili.adapters.kili_api_gateway.user.operation_mixin import UserOperationMixin
2225
from kili.core.graphql.graphql_client import GraphQLClient
@@ -32,6 +35,7 @@ class KiliAPIGateway(
3235
NotificationOperationMixin,
3336
OrganizationOperationMixin,
3437
ProjectOperationMixin,
38+
ProjectWorkflowOperationMixin,
3539
TagOperationMixin,
3640
UserOperationMixin,
3741
EventOperationMixin,

src/kili/adapters/kili_api_gateway/project_workflow/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""GraphQL payload data mappers for project operations."""
2+
3+
from typing import Dict
4+
5+
from .types import ProjectWorkflowDataKiliAPIGatewayInput
6+
7+
8+
def project_input_mapper(data: ProjectWorkflowDataKiliAPIGatewayInput) -> Dict:
9+
"""Build the GraphQL ProjectWorfklowData variable to be sent in an operation."""
10+
return {
11+
"enforceStepSeparation": data.enforce_step_separation,
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""GraphQL Project Workflow operations."""
2+
3+
4+
def get_update_project_workflow_mutation(fragment: str) -> str:
5+
"""Return the GraphQL editProjectWorkflowSettings mutation."""
6+
return f"""
7+
mutation editProjectWorkflowSettings($input: EditProjectWorkflowSettingsInput!) {{
8+
data: editProjectWorkflowSettings(input: $input) {{
9+
{fragment}
10+
}}
11+
}}
12+
"""
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Mixin extending Kili API Gateway class with Projects related operations."""
2+
3+
from typing import Dict
4+
5+
from kili.adapters.kili_api_gateway.base import BaseOperationMixin
6+
from kili.adapters.kili_api_gateway.helpers.queries import (
7+
fragment_builder,
8+
)
9+
from kili.domain.project import ProjectId
10+
11+
from .mappers import project_input_mapper
12+
from .operations import (
13+
get_update_project_workflow_mutation,
14+
)
15+
from .types import ProjectWorkflowDataKiliAPIGatewayInput
16+
17+
18+
class ProjectWorkflowOperationMixin(BaseOperationMixin):
19+
"""Mixin extending Kili API Gateway class with Projects workflow related operations."""
20+
21+
def update_project_workflow(
22+
self,
23+
project_id: ProjectId,
24+
project_workflow_data: ProjectWorkflowDataKiliAPIGatewayInput,
25+
) -> Dict:
26+
"""Update properties in a project workflow."""
27+
project_workflow_input = project_input_mapper(data=project_workflow_data)
28+
29+
fields = tuple(name for name, val in project_workflow_input.items() if val is not None)
30+
fragment = fragment_builder(fields)
31+
mutation = get_update_project_workflow_mutation(fragment)
32+
33+
project_workflow_input["projectId"] = project_id
34+
35+
variables = {"input": project_workflow_input}
36+
result = self.graphql_client.execute(mutation, variables)
37+
return result["data"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Types for the ProjectWorkflow-related Kili API gateway functions."""
2+
3+
from dataclasses import dataclass
4+
from typing import Optional
5+
6+
7+
@dataclass
8+
class ProjectWorkflowDataKiliAPIGatewayInput:
9+
"""ProjectWorkflow input data for Kili API Gateway."""
10+
11+
enforce_step_separation: Optional[bool]

src/kili/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from kili.presentation.client.notification import NotificationClientMethods
3333
from kili.presentation.client.organization import OrganizationClientMethods
3434
from kili.presentation.client.project import ProjectClientMethods
35+
from kili.presentation.client.project_workflow import ProjectWorkflowClientMethods
3536
from kili.presentation.client.tag import TagClientMethods
3637
from kili.presentation.client.user import UserClientMethods
3738
from kili.use_cases.api_key import ApiKeyUseCases
@@ -68,6 +69,7 @@ class Kili( # pylint: disable=too-many-ancestors,too-many-instance-attributes
6869
NotificationClientMethods,
6970
OrganizationClientMethods,
7071
ProjectClientMethods,
72+
ProjectWorkflowClientMethods,
7173
TagClientMethods,
7274
UserClientMethods,
7375
):

src/kili/entrypoints/mutations/asset/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ def assign_assets_to_labelers(
212212
external_ids: Optional[List[str]] = None,
213213
project_id: Optional[str] = None,
214214
) -> List[Dict[str, Any]]:
215-
# pylint: disable=line-too-long
216215
"""Assign a list of assets to a list of labelers.
217216
218217
Args:

0 commit comments

Comments
 (0)