Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scopes): expose level on api #253

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion emeis/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 12 additions & 2 deletions emeis/core/tests/snapshots/snap_test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
"en": "Ago get want middle. Whose scientist draw free property consider rather. Have director true force.",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Stephanie Porter", "fr": ""},
Expand All @@ -196,6 +197,7 @@
"en": "Form leader fund task believe oil. Itself close again affect ok window church. Claim interview participant call strategy.",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Dr. Jose Campbell", "fr": ""},
Expand All @@ -215,6 +217,7 @@
"en": "Beyond seek officer player possible issue. Trial population standard. After away control expert without assume grow back.",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Mary White", "fr": ""},
Expand Down Expand Up @@ -543,6 +546,7 @@
Argue move appear catch toward help wind. Material minute ago get.""",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Pamela Horton", "fr": ""},
Expand All @@ -563,6 +567,7 @@
Son success provide beyond. Officer player possible issue ahead suffer.""",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Rebecca Gonzalez", "fr": ""},
Expand All @@ -584,6 +589,7 @@
Daughter single product trade.""",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Lorraine Reynolds", "fr": ""},
Expand Down Expand Up @@ -787,6 +793,7 @@
"en": "Ago get want middle. Whose scientist draw free property consider rather. Have director true force.",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Stephanie Porter", "fr": ""},
Expand Down Expand Up @@ -962,6 +969,7 @@
Argue move appear catch toward help wind. Material minute ago get.""",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Pamela Horton", "fr": ""},
Expand Down Expand Up @@ -1176,7 +1184,7 @@
Argue move appear catch toward help wind. Material minute ago get.','','']), NULL, 1, 2, 1, 0)""",
],
"request": {
"CONTENT_LENGTH": "506",
"CONTENT_LENGTH": "516",
"CONTENT_TYPE": "application/vnd.api+json",
"PATH_INFO": "/api/v1/scopes",
"QUERY_STRING": "",
Expand All @@ -1193,6 +1201,7 @@
Argue move appear catch toward help wind. Material minute ago get.""",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Pamela Horton", "fr": ""},
Expand Down Expand Up @@ -1406,7 +1415,7 @@
Argue move appear catch toward help wind. Material minute ago get.\',\'\',\'\']), "parent_id" = NULL WHERE "emeis_core_scope"."id" = \'9dd4e461-268c-8034-f5c8-564e155c67a6\'::uuid""",
],
"request": {
"CONTENT_LENGTH": "506",
"CONTENT_LENGTH": "516",
"CONTENT_TYPE": "application/vnd.api+json",
"PATH_INFO": "/api/v1/scopes/9dd4e461-268c-8034-f5c8-564e155c67a6",
"QUERY_STRING": "",
Expand All @@ -1423,6 +1432,7 @@
Argue move appear catch toward help wind. Material minute ago get.""",
"fr": "",
},
"level": 0,
"meta": {},
"modified-at": "2017-05-21T00:00:00Z",
"name": {"de": "", "en": "Pamela Horton", "fr": ""},
Expand Down
16 changes: 16 additions & 0 deletions emeis/core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,29 @@ 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
result = response.json()
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()
Expand Down