-
Notifications
You must be signed in to change notification settings - Fork 29
fix(LAB-4295): add differents methods to handle review and labeling steps #2039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stchabi
wants to merge
1
commit into
main
Choose a base branch
from
feature/lab-4295-aau-i-add-update-and-delete-steps-with-the-sdk-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,12 +12,31 @@ | |
| from kili.domain.types import ListOrTuple | ||
| from kili.exceptions import NotFound | ||
|
|
||
| from .mappers import project_input_mapper | ||
| from .mappers import ( | ||
| add_review_step_input_mapper, | ||
| delete_step_input_mapper, | ||
| project_input_mapper, | ||
| rename_step_input_mapper, | ||
| update_labeling_step_properties_input_mapper, | ||
| update_review_step_properties_input_mapper, | ||
| ) | ||
| from .operations import ( | ||
| get_add_review_step_mutation, | ||
| get_delete_step_mutation, | ||
| get_rename_step_mutation, | ||
| get_steps_query, | ||
| get_update_labeling_step_properties_mutation, | ||
| get_update_project_workflow_mutation, | ||
| get_update_review_step_properties_mutation, | ||
| ) | ||
| from .types import ( | ||
| AddReviewStepInput, | ||
| DeleteStepInput, | ||
| ProjectWorkflowDataKiliAPIGatewayInput, | ||
| RenameStepInput, | ||
| UpdateLabelingStepPropertiesInput, | ||
| UpdateReviewStepPropertiesInput, | ||
| ) | ||
| from .types import ProjectWorkflowDataKiliAPIGatewayInput | ||
|
|
||
|
|
||
| class ProjectWorkflowOperationMixin(BaseOperationMixin): | ||
|
|
@@ -177,3 +196,65 @@ def remove_reviewers_from_step( | |
| ) | ||
|
|
||
| return removed_emails | ||
|
|
||
| def add_review_step(self, data: AddReviewStepInput) -> dict: | ||
| """Add a review step to a project workflow.""" | ||
| existing_members = ProjectUserQuery(self.graphql_client, self.http_client)( | ||
| where=ProjectUserWhere(project_id=data.project_id, status="ACTIVATED", deleted=False), | ||
| fields=["role", "user.email", "user.id", "activated"], | ||
| options=QueryOptions(None), | ||
| ) | ||
| members_by_email = {m["user"]["email"]: m for m in (existing_members or [])} | ||
| assignees_to_add = [] | ||
| assignees_added = [] | ||
| assignees_not_added = [] | ||
| for email in data.assignees: | ||
| member = members_by_email.get(email) | ||
| if member and member.get("role") != "LABELER": | ||
| user_id = member["user"]["id"] | ||
| assignees_to_add.append(user_id) | ||
| assignees_added.append(email) | ||
| else: | ||
| assignees_not_added.append(email) | ||
| if assignees_not_added: | ||
| warnings.warn( | ||
| "These emails were not added (not found or can not review): " | ||
| + ", ".join(assignees_not_added) | ||
| ) | ||
| data.assignees = assignees_to_add | ||
|
Comment on lines
+202
to
+224
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it would be cleaner to use existing method (like |
||
| variables = {"input": add_review_step_input_mapper(data)} | ||
| mutation = get_add_review_step_mutation() | ||
| result = self.graphql_client.execute(mutation, variables) | ||
| steps = result.get("data", {}).get("steps", []) | ||
| return next(step for step in steps if step.get("name") == data.name) | ||
stchabi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def update_labeling_step_properties(self, data: UpdateLabelingStepPropertiesInput) -> dict: | ||
| """Update properties of a labeling step.""" | ||
| variables = {"input": update_labeling_step_properties_input_mapper(data)} | ||
| mutation = get_update_labeling_step_properties_mutation() | ||
| result = self.graphql_client.execute(mutation, variables) | ||
| steps = result.get("data", {}).get("steps", []) | ||
| return next(step for step in steps if step.get("id") == data.step_id) | ||
|
|
||
| def update_review_step_properties(self, data: UpdateReviewStepPropertiesInput) -> dict: | ||
| """Update properties of a review step.""" | ||
| variables = {"input": update_review_step_properties_input_mapper(data)} | ||
| mutation = get_update_review_step_properties_mutation() | ||
| result = self.graphql_client.execute(mutation, variables) | ||
| steps = result.get("data", {}).get("steps", []) | ||
| return next(step for step in steps if step.get("id") == data.step_id) | ||
|
|
||
| def delete_step(self, data: DeleteStepInput) -> dict: | ||
| """Delete a step from a project workflow.""" | ||
| variables = {"input": delete_step_input_mapper(data)} | ||
| mutation = get_delete_step_mutation() | ||
| result = self.graphql_client.execute(mutation, variables) | ||
| return result["data"] | ||
|
|
||
| def rename_step(self, data: RenameStepInput) -> dict: | ||
| """Rename a step in a project workflow.""" | ||
| variables = {"input": rename_step_input_mapper(data)} | ||
| mutation = get_rename_step_mutation() | ||
| result = self.graphql_client.execute(mutation, variables) | ||
| steps = result.get("data", {}).get("steps", []) | ||
| return next(step for step in steps if step.get("id") == data.step_id) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got two strange behaviors during my tests :
-> we should not raise an error when reactivating a step IMO