Skip to content

Commit

Permalink
feat(case): remove idpId and idpIds filters and add identityIds filter
Browse files Browse the repository at this point in the history
  • Loading branch information
open-dynaMIX committed Aug 2, 2024
1 parent 2537b05 commit 304fab1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions api/mysagw/case/filters.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from django_filters import CharFilter
from django_filters.rest_framework import FilterSet

from mysagw.filters import CharMultiValueFilter, UUIDMultiValueFilter
from mysagw.filters import UUIDMultiValueFilter

from . import models


class CaseAccessFilterSet(FilterSet):
idp_id = CharFilter(field_name="identity__idp_id")
case_ids = UUIDMultiValueFilter(field_name="case_id")
idp_ids = CharMultiValueFilter(field_name="identity__idp_id")
identity_ids = UUIDMultiValueFilter(field_name="identity_id")

class Meta:
model = models.CaseAccess
fields = ["idp_id", "case_ids", "idp_ids"]
fields = ["case_ids", "identity_ids"]
17 changes: 12 additions & 5 deletions api/mysagw/case/tests/test_case_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ def test_case_list(
identity_factory,
case_access_factory,
):
identity_0 = identity_factory(idp_id="00000000-0000-0000-0000-000000000000")
identity_1 = identity_factory(idp_id="11111111-1111-1111-1111-111111111111")
case_access_factory.create_batch(2, identity=identity_0, email=None)
case_access_factory(identity=identity_1, email=None)
identity_0 = identity_factory()
identity_1 = identity_factory()
case_access_factory(
identity=identity_0, email=None, case_id="00000000-0000-0000-0000-000000000000"
)
case_access_factory(
identity=identity_0, email=None, case_id="11111111-1111-1111-1111-111111111111"
)
case_access_factory(
identity=identity_1, email=None, case_id="00000000-0000-0000-0000-000000000000"
)
case_access_factory()

url = reverse("caseaccess-list")

response = client.get(url, {"filter[idpId]": filter_id} if filter_id else None)
response = client.get(url, {"filter[caseIds]": filter_id} if filter_id else None)

assert response.status_code == expected_status

Expand Down
6 changes: 2 additions & 4 deletions api/mysagw/case/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ class CaseAccessViewSet(
permission_classes = (IsAuthenticated & (IsAdmin | IsStaff | HasCaseAccess),)

def list(self, request, *args, **kwargs):
expected_keys = ["filter[idpId]", "filter[caseIds]", "filter[idpIds]"]
expected_keys = ["filter[idpId]", "filter[caseIds]", "filter[identityIds]"]
if not request.GET or set(expected_keys).isdisjoint(request.GET.keys()):
msg = f"At least one of following filters must be used: {', '.join(expected_keys)}"
raise ValidationError(
msg,
)
raise ValidationError(msg)
return super().list(request, *args, **kwargs)

def destroy(self, request, *args, **kwargs):
Expand Down

0 comments on commit 304fab1

Please sign in to comment.