-
Notifications
You must be signed in to change notification settings - Fork 604
[ENG-401] fix: token queue should respect sub queues while calling serve next #3708
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
base: develop
Are you sure you want to change the base?
Changes from 5 commits
637e5ce
9d383a7
bc2eec6
14ac7ae
a7ace39
140b0b1
b21fa4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,17 +81,27 @@ def perform_create(self, instance): | |
| super().perform_create(instance) | ||
|
|
||
| def validate_data(self, instance, model_obj=None): | ||
| if ( | ||
| model_obj | ||
| and instance.sub_queue | ||
| and model_obj.sub_queue | ||
| and instance.sub_queue != model_obj.sub_queue.external_id | ||
| ): | ||
| existing_current = TokenSubQueue.objects.filter( | ||
| current_token=model_obj | ||
| ).exists() | ||
| if existing_current: | ||
| raise ValidationError("Sub Queue already has a current token") | ||
| if model_obj and instance.sub_queue: | ||
| if ( | ||
| model_obj.sub_queue | ||
| and instance.sub_queue != model_obj.sub_queue.external_id | ||
| ): | ||
| existing_current = TokenSubQueue.objects.filter( | ||
| current_token=model_obj | ||
| ).exists() | ||
| if existing_current: | ||
| raise ValidationError("Sub Queue already has a current token") | ||
|
|
||
| if ( | ||
| instance.sub_queue | ||
| and instance.status == TokenStatusOptions.IN_PROGRESS.value | ||
| ): | ||
| new_current = get_object_or_404( | ||
| TokenSubQueue, | ||
| external_id=instance.sub_queue, | ||
| ) | ||
| if new_current.current_token and new_current.current_token != model_obj: | ||
| raise ValidationError("Sub Queue already has a current token") | ||
|
|
||
| return super().validate_data(instance, model_obj) | ||
|
Comment on lines
83
to
100
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.
The new validation at lines 94–98 that blocks direct The |
||
|
|
||
|
|
@@ -100,18 +110,34 @@ def perform_update(self, instance): | |
| raise ValidationError("Sub Queue and Queue are not in the same facility") | ||
| with transaction.atomic(): | ||
| obj = self.get_object() | ||
| if obj.sub_queue and obj.sub_queue != instance.sub_queue: | ||
| if ( | ||
| instance.sub_queue | ||
| and obj.sub_queue.resource != instance.sub_queue.resource | ||
| ): | ||
| raise ValidationError( | ||
| "Sub Queue and Queue are not in the same resource" | ||
| ) | ||
| # Clear current token if the sub queue is changed | ||
| if obj.sub_queue.current_token == obj: | ||
| obj.sub_queue.current_token = None | ||
| obj.sub_queue.save(update_fields=["current_token", "modified_date"]) | ||
| if ( | ||
| instance.sub_queue | ||
| and obj.sub_queue != instance.sub_queue | ||
| and instance.status == TokenStatusOptions.IN_PROGRESS.value | ||
| ): | ||
| raise ValidationError( | ||
| "Use set_next endpoint to change the sub queue of a token" | ||
| ) | ||
| if ( | ||
| obj.sub_queue | ||
| and obj.sub_queue != instance.sub_queue | ||
| and instance.sub_queue | ||
| and obj.sub_queue.resource != instance.sub_queue.resource | ||
| ): | ||
| raise ValidationError( | ||
| "Sub Queue and Queue are not in the same resource" | ||
| ) | ||
| # Clear current token if the sub queue is changed | ||
| if ( | ||
| obj.sub_queue | ||
| and obj.sub_queue.current_token == obj | ||
| and ( | ||
| obj.sub_queue != instance.sub_queue | ||
| or instance.status != TokenStatusOptions.IN_PROGRESS.value | ||
| ) | ||
| ): | ||
| obj.sub_queue.current_token = None | ||
| obj.sub_queue.save(update_fields=["current_token", "modified_date"]) | ||
|
nandkishorr marked this conversation as resolved.
|
||
| super().perform_update(instance) | ||
|
|
||
| def perform_destroy(self, instance): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.