diff --git a/emeis/core/serializers.py b/emeis/core/serializers.py index 8f4e07e..18029ce 100644 --- a/emeis/core/serializers.py +++ b/emeis/core/serializers.py @@ -82,7 +82,7 @@ class Meta: class ScopeSerializer(BaseSerializer): class Meta: model = Scope - fields = BaseSerializer.Meta.fields + ("name", "description", "parent") + fields = BaseSerializer.Meta.fields + ("name", "description", "parent", "level") class PermissionSerializer(BaseSerializer): diff --git a/emeis/core/tests/test_views.py b/emeis/core/tests/test_views.py index b98a348..08d612d 100644 --- a/emeis/core/tests/test_views.py +++ b/emeis/core/tests/test_views.py @@ -133,6 +133,7 @@ def test_scope_search_filter(db, scope_factory, client): "en": "scope2", "fr": "", } + assert result["data"][0]["attributes"]["level"] == 0 response = client.get(url, {"filter[search]": "scope"}) assert response.status_code == HTTP_200_OK @@ -140,6 +141,21 @@ def test_scope_search_filter(db, scope_factory, client): assert len(result["data"]) == 3 +def test_cannot_write_level(db, client, settings, user): + data = { + "data": { + "type": "scopes", + "attributes": {"name": {"en": "test"}, "level": 400}, + } + } + + resp = client.post(reverse("scope-list"), data=data) + + assert resp.status_code == HTTP_201_CREATED + result = resp.json() + assert result["data"]["attributes"]["level"] == 0 + + def test_acl_user_filter(db, user, acl_factory, client): acl = acl_factory(user=user) acl_factory()