From 11f02047a95d16a87a61b15eb69ce08269ce83a1 Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:04:51 +0100 Subject: [PATCH 1/3] feat(guideline): enable non-admin ausers to fetch their own guidelines --- src/app/api/api_v1/endpoints/guidelines.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/api/api_v1/endpoints/guidelines.py b/src/app/api/api_v1/endpoints/guidelines.py index f1040c5..f3474e0 100644 --- a/src/app/api/api_v1/endpoints/guidelines.py +++ b/src/app/api/api_v1/endpoints/guidelines.py @@ -42,10 +42,11 @@ async def get_guideline( @router.get("/", status_code=status.HTTP_200_OK, summary="Fetch all the guidelines") async def fetch_guidelines( guidelines: GuidelineCRUD = Depends(get_guideline_crud), - user: User = Security(get_current_user, scopes=[UserScope.ADMIN]), + user: User = Security(get_current_user, scopes=[UserScope.USER, UserScope.ADMIN]), ) -> List[Guideline]: telemetry_client.capture(user.id, event="guideline-fetch") - return [elt for elt in await guidelines.fetch_all()] + filter_pair = ("creator_id", user.id) if user.scope != UserScope.ADMIN else None + return [elt for elt in await guidelines.fetch_all(filter_pair=filter_pair)] @router.patch("/{guideline_id}", status_code=status.HTTP_200_OK, summary="Update a guideline content") From eb8af2c3e307b3bb7f81fa3c3f3b520ad7c793a5 Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:05:54 +0100 Subject: [PATCH 2/3] test(guideline): update test case --- src/tests/endpoints/test_guidelines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/endpoints/test_guidelines.py b/src/tests/endpoints/test_guidelines.py index 885ea49..89f76c2 100644 --- a/src/tests/endpoints/test_guidelines.py +++ b/src/tests/endpoints/test_guidelines.py @@ -77,7 +77,7 @@ async def test_get_guideline( [ (None, 401, "Not authenticated"), (0, 200, None), - (1, 403, "Incompatible token scope."), + (1, 200, None), ], ) @pytest.mark.asyncio() From 643493de01f7b697e3a3113e5ae0d9475b2fecad Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:48:39 +0100 Subject: [PATCH 3/3] test(guidelines): update test case --- src/tests/endpoints/test_guidelines.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/tests/endpoints/test_guidelines.py b/src/tests/endpoints/test_guidelines.py index 89f76c2..7b966e6 100644 --- a/src/tests/endpoints/test_guidelines.py +++ b/src/tests/endpoints/test_guidelines.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, List, Union import pytest from httpx import AsyncClient @@ -73,11 +73,11 @@ async def test_get_guideline( @pytest.mark.parametrize( - ("user_idx", "status_code", "status_detail"), + ("user_idx", "status_code", "status_detail", "expected_result"), [ - (None, 401, "Not authenticated"), - (0, 200, None), - (1, 200, None), + (None, 401, "Not authenticated", None), + (0, 200, None, pytest.guideline_table), + (1, 200, None, pytest.guideline_table[1:]), ], ) @pytest.mark.asyncio() @@ -87,6 +87,7 @@ async def test_fetch_guidelines( user_idx: Union[int, None], status_code: int, status_detail: Union[str, None], + expected_result: Union[List[Dict[str, Any]], None], ): auth = None if isinstance(user_idx, int): @@ -97,7 +98,7 @@ async def test_fetch_guidelines( if isinstance(status_detail, str): assert response.json()["detail"] == status_detail if response.status_code // 100 == 2: - assert response.json() == pytest.guideline_table + assert response.json() == expected_result @pytest.mark.parametrize(