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
4541bb92
Commit
4541bb92
authored
3 years ago
by
Valentin Rigal
Committed by
Bastien Abadie
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix internal user check to update worker activities
parent
d80610fc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1336
Fix internal user check to update worker activities
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/dataimport/tests/test_workeractivity.py
+9
-0
9 additions, 0 deletions
arkindex/dataimport/tests/test_workeractivity.py
arkindex/project/permissions.py
+2
-4
2 additions, 4 deletions
arkindex/project/permissions.py
with
11 additions
and
4 deletions
arkindex/dataimport/tests/test_workeractivity.py
+
9
−
0
View file @
4541bb92
...
...
@@ -8,6 +8,7 @@ from arkindex.dataimport.models import ActivityState, DataImportMode, WorkerActi
from
arkindex.documents.models
import
Classification
,
ClassificationState
,
Element
,
MLClass
from
arkindex.documents.tasks
import
initialize_activity
from
arkindex.project.tests
import
FixtureTestCase
from
arkindex.users.models
import
User
class
TestWorkerActivity
(
FixtureTestCase
):
...
...
@@ -84,14 +85,22 @@ class TestWorkerActivity(FixtureTestCase):
def
test_put_activity_requires_internal
(
self
):
"""
Only internal users (workers) are able to update the state of a worker activity
Internal users with an instance admin are able to update a worker activity
"""
internal_admin_user
=
User
.
objects
.
create_user
(
'
god@test.test
'
,
'
G0D
'
)
internal_admin_user
.
is_internal
=
True
internal_admin_user
.
is_admin
=
True
internal_admin_user
.
save
()
cases
=
(
(
None
,
status
.
HTTP_403_FORBIDDEN
,
0
),
(
self
.
user
,
status
.
HTTP_403_FORBIDDEN
,
2
),
(
self
.
superuser
,
status
.
HTTP_403_FORBIDDEN
,
2
),
(
self
.
internal_user
,
status
.
HTTP_200_OK
,
3
),
(
internal_admin_user
,
status
.
HTTP_200_OK
,
3
)
)
for
user
,
status_code
,
requests_count
in
cases
:
self
.
activity
.
state
=
WorkerActivityState
.
Queued
self
.
activity
.
save
()
if
user
:
self
.
client
.
force_login
(
user
)
with
self
.
assertNumQueries
(
requests_count
):
...
...
This diff is collapsed.
Click to expand it.
arkindex/project/permissions.py
+
2
−
4
View file @
4541bb92
...
...
@@ -7,7 +7,7 @@ class AllowNone(object):
Systematically refuse permission
"""
def
has_permission
(
self
,
request
,
view
):
return
Non
e
return
Fals
e
class
InternalGroupPermissionMixin
(
object
):
...
...
@@ -17,9 +17,7 @@ class InternalGroupPermissionMixin(object):
"""
def
has_permission
(
self
,
request
,
view
):
if
request
.
user
.
is_authenticated
and
\
not
request
.
user
.
is_admin
and
\
request
.
user
.
is_internal
:
if
request
.
user
.
is_authenticated
and
request
.
user
.
is_internal
:
return
True
return
super
().
has_permission
(
request
,
view
)
...
...
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