Skip to content
Snippets Groups Projects
Commit 77588f8a authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Properly handle a missing process

parent f3c0b0d0
No related branches found
No related tags found
No related merge requests found
from django.core.exceptions import ObjectDoesNotExist
from drf_spectacular.authentication import TokenScheme
from drf_spectacular.contrib.rest_framework_simplejwt import SimpleJWTScheme
from rest_framework.authentication import TokenAuthentication
......@@ -83,15 +84,20 @@ class TaskAuthentication(TokenAuthentication):
# Same error message as the standard TokenAuthentication
raise AuthenticationFailed('Invalid token.')
if not task.workflow.process:
# There is no Workflow.process_id, since the FK is on Process.workflow_id,
# and accessing Workflow.process when there is no process causes an exception
# instead of returning None.
try:
process = task.workflow.process
except ObjectDoesNotExist:
raise AuthenticationFailed('Task has no process.')
user = task.workflow.process.creator
if not user or not user.is_active:
if not process.creator_id or not process.creator.is_active:
# Same error message as the standard TokenAuthentication
raise AuthenticationFailed('User inactive or deleted.')
return (user, task)
# Must return a 2-tuple that will be set as (self.request.user, self.request.auth)
return (process.creator, task)
class TaskAuthenticationExtension(TokenScheme):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment