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!: WABO dossiers should be publicly available #200

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions src/bouwdossiers/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from random import randint

import pytest
from django.conf import settings
from django.urls import reverse
from rest_framework.test import APITestCase
Expand Down Expand Up @@ -39,8 +40,8 @@ def test_api_list(self):
url = reverse("bouwdossier-list")

test_parameters = [
(None, 3),
(settings.BOUWDOSSIER_PUBLIC_SCOPE, 3),
(None, 7),
(settings.BOUWDOSSIER_PUBLIC_SCOPE, 7),
(settings.BOUWDOSSIER_READ_SCOPE, 7),
(settings.BOUWDOSSIER_EXTENDED_SCOPE, 7),
]
Expand Down Expand Up @@ -72,6 +73,7 @@ def test_api_detail_using_stadsdeel_and_dossier(self):
self.assertEqual(response.data["dossiernr"], dossiers[0].dossiernr)
delete_all_records()

@pytest.mark.xfail(reason="WABO dossiers should be publicly available")
def test_api_detail_wabo_using_stadsdeel_and_dossier_without_auth(self):
dossiers = create_bouwdossiers(4, source=SOURCE_WABO)
pk = dossiers[0].stadsdeel + str(dossiers[0].dossiernr)
Expand Down
32 changes: 10 additions & 22 deletions src/bouwdossiers/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging

from datapunt_api.rest import DatapuntViewSet
from django.conf import settings
from django.shortcuts import get_object_or_404
from django_filters.rest_framework import FilterSet, filters

from bouwdossiers import models, serializers, tools
from bouwdossiers.models import BouwDossier
from bouwdossiers.serializers import BouwDossierSerializer
from bouwdossiers.tools import separate_dossier

log = logging.getLogger(__name__)

Expand All @@ -32,7 +33,7 @@ class BouwDossierFilter(FilterSet):
dossier_type = filters.CharFilter()

class Meta:
model = models.BouwDossier
model = BouwDossier

fields = (
"dossiernr",
Expand All @@ -48,7 +49,7 @@ class Meta:
)

def dossier_with_stadsdeel(self, queryset, _filter_name, value):
stadsdeel, dossiernr = tools.separate_dossier(value)
stadsdeel, dossiernr = separate_dossier(value)
return queryset.filter(stadsdeel=stadsdeel, dossiernr=dossiernr)

def array_contains_filter(self, queryset, _filter_name, value):
Expand All @@ -59,29 +60,16 @@ def array_contains_filter(self, queryset, _filter_name, value):


class BouwDossierViewSet(DatapuntViewSet):
filterset_class = BouwDossierFilter

def get_queryset(self):
allowed_scopes = [
settings.BOUWDOSSIER_READ_SCOPE,
settings.BOUWDOSSIER_EXTENDED_SCOPE,
]
if any(scope in self.request.get_token_scopes for scope in allowed_scopes):
return models.BouwDossier.objects.all().prefetch_related(
"adressen", "documenten"
)
else:
return models.BouwDossier.objects.filter(source="EDEPOT").prefetch_related(
"adressen", "documenten"
)
serializer_class = BouwDossierSerializer
serializer_detail_class = BouwDossierSerializer

def get_serializer_class(self):
return serializers.BouwDossierSerializer
filterset_class = BouwDossierFilter
queryset = BouwDossier.objects.prefetch_related("adressen", "documenten")

def get_object(self):
# We expect a key of the form AA0000123 in which AA is the code for the
# stadsdeel and the numberic part (which can vary in length) is the dossiernumber
stadsdeel, dossiernr = tools.separate_dossier(self.kwargs["pk"])
stadsdeel, dossiernr = separate_dossier(self.kwargs["pk"])
obj = get_object_or_404(
self.get_queryset(), stadsdeel=stadsdeel.upper(), dossiernr=dossiernr
)
Expand Down
Loading