Skip to content
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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

redis:
image: redis:8
ports:
- 6379:6379

steps:
- uses: actions/checkout@v4
- name: Set up backend environment
Expand All @@ -62,11 +67,15 @@ jobs:
coverage run src/manage.py test src
env:
DJANGO_SETTINGS_MODULE: objects.conf.ci
DEBUG: 'true'
SECRET_KEY: dummy
DB_USER: postgres
DB_PASSWORD: ''
DB_POOL_ENABLED: ${{ matrix.use_pooling }}

CELERY_BROKER_URL: 'redis://localhost:6379/0'
CELERY_ONCE_REDIS_URL: 'redis://localhost:6379/0'

- name: Publish coverage report
uses: codecov/codecov-action@v4
with:
Expand Down
28 changes: 24 additions & 4 deletions src/objects/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework import serializers
from rest_framework_gis.serializers import GeometryField

from objects.core.models import Object, ObjectRecord, ObjectType
from objects.core.models import Object, ObjectRecord, ObjectType, Reference
from objects.token.models import Permission, TokenAuth
from objects.utils.serializers import DynamicFieldsMixin

Expand All @@ -16,7 +16,13 @@
logger = structlog.stdlib.get_logger(__name__)


class ObjectRecordSerializer(serializers.ModelSerializer):
class ReferenceSerializer(serializers.ModelSerializer):
class Meta:
model = Reference
fields = ["type", "url"]


class ObjectRecordSerializer(serializers.ModelSerializer[ObjectRecord]):
correctionFor = ObjectSlugRelatedField(
source="correct",
slug_field="index",
Expand All @@ -30,6 +36,7 @@ class ObjectRecordSerializer(serializers.ModelSerializer):
read_only=True,
help_text=_("Index of the record, which corrects the current record"),
)
references = ReferenceSerializer(many=True, read_only=False, default=[])

class Meta:
model = ObjectRecord
Expand All @@ -38,6 +45,7 @@ class Meta:
"typeVersion",
"data",
"geometry",
"references",
"startAt",
"endAt",
"registrationAt",
Expand Down Expand Up @@ -125,7 +133,11 @@ def create(self, validated_data):
object = Object.objects.create(**object_data)

validated_data["object"] = object
references = validated_data.pop("references", [])
record = super().create(validated_data)
Reference.objects.bulk_create(
Reference(record=record, **ref_data) for ref_data in references
)
token_auth: TokenAuth = self.context["request"].auth
logger.info(
"object_created",
Expand All @@ -149,11 +161,19 @@ def update(self, instance, validated_data):
if "start_at" not in validated_data:
validated_data["start_at"] = instance.start_at

if self.partial and "data" in validated_data:
if self.partial:
# Apply JSON Merge Patch for record data
validated_data["data"] = merge_patch(instance.data, validated_data["data"])
validated_data["data"] = merge_patch(
instance.data, validated_data.pop("data", {})
)

references = validated_data.pop(
"references", instance.references.values("type", "url")
)
record = super().create(validated_data)
Reference.objects.bulk_create(
Reference(record=record, **ref_data) for ref_data in references
)
token_auth: TokenAuth = self.context["request"].auth
logger.info(
"object_updated",
Expand Down
89 changes: 76 additions & 13 deletions src/objects/api/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,49 @@
format: uuid
description: Unique identifier (UUID4)
required: true
- in: query
name: zaak
schema:
type: string
format: uri
description: '**Experimental** When destructing for archiving a ztc.ZAAK pass
in the ZAAK URL that is being destroyed. If this OBJECT''s current RECORD
has other ZAAK references, then object destruction is cancelled and only
this ZAAK URL is removed from the RECORD''s references.'
tags:
- objects
security:
- tokenAuth: []
responses:
'200':
headers:
Content-Crs:
schema:
type: string
enum:
- EPSG:4326
description: 'The ''Coordinate Reference System'' (CRS) of the request
data. According to the GeoJSON spec, WGS84 is the default (EPSG: 4326
is the same as WGS84).'
API-version:
schema:
type: string
description: 'Geeft een specifieke API-versie aan in de context van
een specifieke aanroep. Voorbeeld: 1.2.1.'
content:
application/json:
schema:
$ref: '#/components/schemas/BehoudenResponse'
description: OBJECT kept because it has multiple ZAKEN. Specified ZAAK parameter
removed from RECORD.
'204':
headers:
API-version:
schema:
type: string
description: 'Geeft een specifieke API-versie aan in de context van
een specifieke aanroep. Voorbeeld: 1.2.1.'
description: No response body
description: OBJECT and all its RECORDs deleted.
/objects/{uuid}/{index}:
get:
operationId: object_history_detail
Expand Down Expand Up @@ -857,7 +887,18 @@
description: OK
components:
schemas:
BehoudenResponse:
type: object
properties:
behouden:
type: array
items:
type: string
format: uri
description: Kept OBJECT URLs
required:
- behouden
GeoJSONGeometry:

Check warning on line 901 in src/objects/api/v2/openapi.yaml

View workflow job for this annotation

GitHub Actions / Checks / Lint OAS

schema-camel-case Schema name should be CamelCase in #/components/schemas/GeoJSONGeometry
title: GeoJSONGeometry
type: object
oneOf:
Expand Down Expand Up @@ -886,7 +927,7 @@
properties:
type:
allOf:
- $ref: '#/components/schemas/TypeEnum'
- $ref: '#/components/schemas/GeometryTypeEnum'
description: The geometry type
GeometryCollection:
type: object
Expand All @@ -903,6 +944,18 @@
type: array
items:
$ref: '#/components/schemas/Geometry'
GeometryTypeEnum:
type: string
enum:
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- Feature
- FeatureCollection
- GeometryCollection
HistoryRecord:
type: object
properties:
Expand Down Expand Up @@ -1087,6 +1140,11 @@
of the object. Geometry can be added only if the related OBJECTTYPE allows
this (`OBJECTTYPE.allowGeometry = true` or `OBJECTTYPE.allowGeometry`
doesn't exist)
references:
type: array
items:
$ref: '#/components/schemas/Reference'
default: []
startAt:
type: string
format: date
Expand Down Expand Up @@ -1287,18 +1345,23 @@
type: array
items:
$ref: '#/components/schemas/Point2D'
TypeEnum:
type: string
Reference:
type: object
properties:
type:
$ref: '#/components/schemas/ReferenceTypeEnum'
url:
type: string
format: uri
maxLength: 200
required:
- type
- url
ReferenceTypeEnum:
enum:
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- Feature
- FeatureCollection
- GeometryCollection
- zaak
type: string
description: '* `zaak` - Zaak'
securitySchemes:
tokenAuth:
type: apiKey
Expand All @@ -1306,7 +1369,7 @@
name: Authorization
description: Token-based authentication with required prefix "Token"
servers:
- url: /api/v2

Check warning on line 1372 in src/objects/api/v2/openapi.yaml

View workflow job for this annotation

GitHub Actions / Checks / Lint OAS

servers-use-https Server URL /api/v2 "/api/v2" must match the pattern "^https://.*".
tags:
- name: objects
- name: permissions
Expand Down
Loading