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
0fec46b3
Commit
0fec46b3
authored
2 years ago
by
ml bonhomme
Committed by
Erwan Rouchet
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Skip get_max_level when a model is being created
parent
b269b169
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1802
Skip get_max_level when a model is being created
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/training/serializers.py
+6
-1
6 additions, 1 deletion
arkindex/training/serializers.py
arkindex/training/tests/test_model_api.py
+1
-1
1 addition, 1 deletion
arkindex/training/tests/test_model_api.py
with
7 additions
and
2 deletions
arkindex/training/serializers.py
+
6
−
1
View file @
0fec46b3
...
...
@@ -48,8 +48,13 @@ class ModelSerializer(TrainingModelMixin, ModelLightSerializer):
@extend_schema_field
(
serializers
.
ListField
(
child
=
serializers
.
ChoiceField
([
'
read
'
,
'
write
'
,
'
admin
'
])))
def
get_rights
(
self
,
model
):
level
=
get_max_level
(
self
.
context
[
'
request
'
].
user
,
model
)
# to avoid a stale read on get_max_level when creating a model (because the corresponding membership is
# created at the same time as the model) if a model is being created we return these rights without
# actually checking them.
if
self
.
context
[
'
request
'
].
method
==
'
POST
'
:
return
[
'
read
'
,
'
write
'
,
'
admin
'
]
level
=
get_max_level
(
self
.
context
[
'
request
'
].
user
,
model
)
rights
=
[
'
read
'
]
if
level
>=
Role
.
Contributor
.
value
:
rights
.
append
(
'
write
'
)
...
...
This diff is collapsed.
Click to expand it.
arkindex/training/tests/test_model_api.py
+
1
−
1
View file @
0fec46b3
...
...
@@ -573,7 +573,7 @@ class TestModelAPI(FixtureAPITestCase):
"
name
"
:
'
The Best Model Ever
'
,
"
description
"
:
"
This is actually the best model ever.
"
}
with
self
.
assertNumQueries
(
8
):
with
self
.
assertNumQueries
(
6
):
response
=
self
.
client
.
post
(
reverse
(
'
api:models
'
),
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
...
...
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