Skip to content
Snippets Groups Projects
Commit 0fec46b3 authored by ml bonhomme's avatar ml bonhomme :bee: Committed by Erwan Rouchet
Browse files

Skip get_max_level when a model is being created

parent b269b169
No related branches found
No related tags found
1 merge request!1802Skip get_max_level when a model is being created
......@@ -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')
......
......@@ -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)
......
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