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

✨ Add zaak to document file and status endpoint #60

Merged
merged 1 commit into from
Dec 21, 2023
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
26 changes: 26 additions & 0 deletions src/dowc/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class DocumentFileSerializer(serializers.ModelSerializer):
"The URL that opens the MS Office WebDAV client on the local machine."
)
)
zaak = serializers.URLField(
help_text=_(
"URL-reference to ZAAK if the DocumentFile is associated with a ZAAK."
),
required=False,
allow_blank=True,
)

class Meta:
model = DocumentFile
Expand All @@ -32,6 +39,7 @@ class Meta:
"uuid",
"info_url",
"unversioned_url",
"zaak",
)
extra_kwargs = {
"drc_url": {
Expand Down Expand Up @@ -206,6 +214,24 @@ class Meta:
}


class StatusSerializer(serializers.Serializer):
zaak = serializers.URLField(
help_text=_(
"URL-reference to ZAAK if the DocumentFile is associated with a ZAAK."
),
required=False,
allow_blank=True,
)
documents = serializers.ListField(
child=serializers.CharField(
required=False,
help_text=_("URL-reference to document in DRC API."),
),
required=False,
allow_empty=True,
)


class SupportedFileExtensionsSerializer(serializers.Serializer):
extensions = serializers.ListField(
child=serializers.CharField(required=True, help_text=_("File extension.")),
Expand Down
85 changes: 75 additions & 10 deletions src/dowc/api/tests/test_documentfile_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,12 @@ def test_retrieve_documentfiles_on_url(self, m):
)

# Retrieve documentfiles with this data
data = [
{"document": "http://some-unversioned-url.com/1"},
{"document": "http://some-unversioned-url.com/2"},
]
data = {
"documents": [
"http://some-unversioned-url.com/1",
"http://some-unversioned-url.com/2",
]
}

# Call get on list
response = self.client.post(reverse_lazy("documentfile-status"), data=data)
Expand All @@ -508,6 +510,67 @@ def test_retrieve_documentfiles_on_url(self, m):
],
)

def test_retrieve_documentfiles_on_zaak(self, m):
mock_service_oas_get(m, self.DRC_URL, "drc")

# Two documentfiles purpose to write
df1 = DocumentFileFactory.create(
unversioned_url="http://some-unversioned-url.com/1",
purpose=DocFileTypes.write,
zaak="http://some-zaak.nl/",
)
df2 = DocumentFileFactory.create(
unversioned_url="http://some-unversioned-url.com/2",
purpose=DocFileTypes.write,
zaak="http://some-other-zaak.nl/",
)

# Retrieve documentfiles with this data
data = {"zaak": "http://some-other-zaak.nl/"}

# Call get on list
response = self.client.post(reverse_lazy("documentfile-status"), data=data)

# Check response status
self.assertEqual(response.status_code, status.HTTP_200_OK)

results = response.json()

# Expecting 1 documentfiles
self.assertEqual(
results,
[
{
"document": "http://some-unversioned-url.com/2",
"uuid": str(df2.uuid),
},
],
)

def test_retrieve_documentfiles_no_zaak_no_urls(self, m):
mock_service_oas_get(m, self.DRC_URL, "drc")

# Two documentfiles purpose to write
df1 = DocumentFileFactory.create(
unversioned_url="http://some-unversioned-url.com/1",
purpose=DocFileTypes.write,
zaak="http://some-zaak.nl/",
)

# Retrieve documentfiles with this data
data = {}

# Call get on list
response = self.client.post(reverse_lazy("documentfile-status"), data=data)

# Check response status
self.assertEqual(response.status_code, status.HTTP_200_OK)

results = response.json()

# Expecting 1 documentfiles
self.assertEqual(results, [])

def test_retrieve_documentfiles_on_url_empty_array(self, m):
mock_service_oas_get(m, self.DRC_URL, "drc")

Expand All @@ -522,7 +585,7 @@ def test_retrieve_documentfiles_on_url_empty_array(self, m):
)

# Retrieve documentfiles with this data
data = []
data = dict()

# Call get on list
response = self.client.post(reverse_lazy("documentfile-status"), data=data)
Expand All @@ -532,7 +595,7 @@ def test_retrieve_documentfiles_on_url_empty_array(self, m):

results = response.json()

# Expecting 2 documentfiles
# Expecting 0 documentfiles
self.assertEqual(
results,
[],
Expand All @@ -552,10 +615,12 @@ def test_application_token(self, m):
)

# Retrieve documentfiles with this data
data = [
{"document": "http://some-unversioned-url.com/1"},
{"document": "http://some-unversioned-url.com/2"},
]
data = {
"documents": [
"http://some-unversioned-url.com/1",
"http://some-unversioned-url.com/2",
]
}

self.client.logout()
token = ApplicationTokenFactory.create()
Expand Down
21 changes: 13 additions & 8 deletions src/dowc/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .serializers import (
DocumentFileSerializer,
DocumentStatusSerializer,
StatusSerializer,
UnlockedDocumentSerializer,
)

Expand Down Expand Up @@ -140,22 +141,26 @@ def perform_destroy(self, instance):

@extend_schema(
summary=_("Retrieve open documents."),
request=DocumentStatusSerializer,
request=StatusSerializer,
responses={200: DocumentStatusSerializer},
)
@action(
methods=["post"],
detail=False,
)
def status(self, request, *args, **kwargs):
serializer = DocumentStatusSerializer(data=request.data, many=True)
serializer = StatusSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
if not serializer.data:
return Response([])

queryset = self.get_queryset().filter(
purpose=DocFileTypes.write,
unversioned_url__in=[url["document"] for url in serializer.data],
)
filters = dict()
if docs := serializer.data.get("documents"):
filters["unversioned_url__in"] = docs
if zaak := serializer.data.get("zaak"):
filters["zaak"] = zaak

if not filters:
return Response(list())

queryset = self.get_queryset().filter(purpose=DocFileTypes.write, **filters)
serializer = DocumentStatusSerializer(queryset, many=True)
return Response(serializer.data)
22 changes: 22 additions & 0 deletions src/dowc/core/migrations/0013_documentfile_zaak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.12 on 2023-12-20 20:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0012_alter_documentfile_purpose"),
]

operations = [
migrations.AddField(
model_name="documentfile",
name="zaak",
field=models.URLField(
blank=True,
default="",
help_text="URL-reference to ZAAK if associated to one.",
),
),
]
5 changes: 5 additions & 0 deletions src/dowc/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ class DocumentFile(models.Model):
info_url = models.URLField(
default="", help_text=_("Points to the origin of the document's usage.")
)
zaak = models.URLField(
help_text=_("URL-reference to ZAAK if associated to one."),
default="",
blank=True,
)

api_document: Optional[Document] = None

Expand Down
Loading