Skip to content

Commit

Permalink
Merge pull request #4032 from open-formulieren/feature/3688-attachments
Browse files Browse the repository at this point in the history
[#3688] Use Documents URLs as fileupload variables values
  • Loading branch information
Viicos authored Mar 22, 2024
2 parents 1d922e5 + 92b2832 commit 75c3268
Show file tree
Hide file tree
Showing 14 changed files with 514 additions and 103 deletions.
1 change: 1 addition & 0 deletions docker/docker-compose.open-zaak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
- CELERY_BROKER_URL=redis://openzaak-redis:6379/1
- CELERY_RESULT_BACKEND=redis://openzaak-redis:6379/1
- NOTIFICATIONS_DISABLED=true
- JWT_EXPIRY=99999999999 # Roughly 3170 years. This is required for tests with time frozen to work
ports:
- 8003:8000
volumes: &openzaak_web_volumes
Expand Down
20 changes: 20 additions & 0 deletions docker/objects-apis/fixtures/objects_api_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
"_name": "Person"
}
},
{
"model": "core.objecttype",
"pk": 2,
"fields": {
"service": 1,
"uuid": "527b8408-7421-4808-a744-43ccb7bdaaa2",
"_name": "File uploads"
}
},
{
"model": "token.tokenauth",
"pk": "7657474c3d75f56ae0abd0d1bf7994b09964dca9",
Expand All @@ -32,6 +41,17 @@
"fields": null
}
},
{
"model": "token.permission",
"pk": 1,
"fields": {
"token_auth": "7657474c3d75f56ae0abd0d1bf7994b09964dca9",
"object_type": 2,
"mode": "read_and_write",
"use_fields": false,
"fields": null
}
},
{
"model": "zgw_consumers.service",
"pk": 1,
Expand Down
55 changes: 54 additions & 1 deletion docker/objects-apis/fixtures/objecttypes_api_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@
"allow_geometry": true
}
},
{
"model": "core.objecttype",
"pk": 3,
"fields": {
"uuid": "527b8408-7421-4808-a744-43ccb7bdaaa2",
"name": "File Uploads",
"name_plural": "File Uploads",
"description": "",
"data_classification": "confidential",
"maintainer_organization": "",
"maintainer_department": "",
"contact_person": "",
"contact_email": "",
"source": "",
"update_frequency": "unknown",
"provider_organization": "",
"documentation_url": "",
"labels": {},
"created_at": "2024-02-08",
"modified_at": "2024-02-08",
"allow_geometry": true
}
},
{
"model": "core.objectversion",
"pk": 1,
Expand Down Expand Up @@ -133,7 +156,9 @@
"name": {
"type": "object",
"properties": {
"last.name": {"type": "string"}
"last.name": {
"type": "string"
}
}
},
"submission_pdf_url": {
Expand Down Expand Up @@ -186,6 +211,34 @@
"status": "published"
}
},
{
"model": "core.objectversion",
"pk": 5,
"fields": {
"object_type": 3,
"version": 1,
"created_at": "2024-02-08",
"modified_at": "2024-02-08",
"published_at": "2024-02-08",
"json_schema": {
"type": "object",
"title": "File uploads",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"single_file": {
"type": "string"
},
"multiple_files": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"status": "published"
}
},
{
"model": "token.tokenauth",
"pk": "171be5abaf41e7856b423ad513df1ef8f867ff48",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 4.2.10 on 2024-03-21 11:36

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("submissions", "0004_auto_20231128_1536"),
("registrations_objects_api", "0013_objectsapiregistrationdata"),
]

operations = [
migrations.RemoveField(
model_name="objectsapiregistrationdata",
name="attachment_urls",
),
migrations.CreateModel(
name="ObjectsAPISubmissionAttachment",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"document_url",
models.URLField(
help_text="The URL of the submission attachment registered in the Documents API.",
verbose_name="document_url",
),
),
(
"submission_file_attachment",
models.ForeignKey(
help_text="The submission file attachment.",
on_delete=django.db.models.deletion.CASCADE,
to="submissions.submissionfileattachment",
verbose_name="submission file attachment",
),
),
],
),
]
24 changes: 16 additions & 8 deletions src/openforms/registrations/contrib/objects_api/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import ValidationError
from django.db import models
from django.template.loader import render_to_string
Expand Down Expand Up @@ -222,12 +221,21 @@ class ObjectsAPIRegistrationData(models.Model):
help_text=_("The CSV URL of the document on the Documents API."),
blank=True,
)
attachment_urls = ArrayField(
models.URLField(
_("attachment url"), help_text=_("The attachment URL on the Documents API.")


class ObjectsAPISubmissionAttachment(models.Model):
"""A utility model to link a submission file attachment with the Documents API URL."""

submission_file_attachment = models.ForeignKey(
"submissions.SubmissionFileAttachment",
on_delete=models.CASCADE,
verbose_name=_("submission file attachment"),
help_text=_("The submission file attachment."),
)

document_url = models.URLField(
_("document_url"),
help_text=_(
"The URL of the submission attachment registered in the Documents API."
),
verbose_name=_("attachment urls"),
help_text=_("The list of attachment URLs on the Documents API."),
blank=True,
default=list,
)
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ def get_initial_value(self, submission: Submission | None = None):
return submission.objects_api_registration_data.csv_url


@register("attachment_urls")
class AttachmentUrls(BaseStaticVariable):
name = _("Attachment Urls")
data_type = FormVariableDataTypes.array

def get_initial_value(self, submission: Submission | None = None):
if submission is None:
return None
return submission.objects_api_registration_data.attachment_urls


@register("payment_completed")
class PaymentCompleted(BaseStaticVariable):
name = _("Payment completed")
Expand Down
Loading

0 comments on commit 75c3268

Please sign in to comment.