Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
77588f8a
Commit
77588f8a
authored
2 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Properly handle a missing process
parent
f3c0b0d0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex/ponos/authentication.py
+10
-4
10 additions, 4 deletions
arkindex/ponos/authentication.py
with
10 additions
and
4 deletions
arkindex/ponos/authentication.py
+
10
−
4
View file @
77588f8a
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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment