-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3895 from open-formulieren/feature/3688-objecttyp…
…es-api-endpoints-2 [#3688] Add Objecttypes API endpoints
- Loading branch information
Showing
12 changed files
with
530 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
25 changes: 25 additions & 0 deletions
25
src/openforms/registrations/contrib/objects_api/api/serializers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from rest_framework import serializers | ||
|
||
|
||
class ObjecttypeSerializer(serializers.Serializer): | ||
# Keys are defined in camel case as this is what we get from the Objecttype API | ||
url = serializers.URLField( | ||
label=_( | ||
"URL reference to this object. This is the unique identification and location of this object." | ||
), | ||
) | ||
uuid = serializers.UUIDField(label=_("Unique identifier (UUID4).")) | ||
name = serializers.CharField(label=_("Name of the object type.")) | ||
namePlural = serializers.CharField(label=_("Plural name of the object type.")) | ||
dataClassification = serializers.CharField( | ||
label=_("Confidential level of the object type.") | ||
) | ||
|
||
|
||
class ObjecttypeVersionSerializer(serializers.Serializer): | ||
version = serializers.IntegerField( | ||
label=_("Integer version of the Objecttype."), | ||
) | ||
status = serializers.CharField(label=_("Status of the object type version")) |
18 changes: 18 additions & 0 deletions
18
src/openforms/registrations/contrib/objects_api/api/urls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.urls import path | ||
|
||
from .views import ObjecttypesListView, ObjecttypeVersionsListView | ||
|
||
app_name = "objects_api" | ||
|
||
urlpatterns = [ | ||
path( | ||
"object-types", | ||
ObjecttypesListView.as_view(), | ||
name="object-types", | ||
), | ||
path( | ||
"object-types/<uuid:submission_uuid>/versions", | ||
ObjecttypeVersionsListView.as_view(), | ||
name="object-type-versions", | ||
), | ||
] |
51 changes: 51 additions & 0 deletions
51
src/openforms/registrations/contrib/objects_api/api/views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from typing import Any | ||
|
||
from drf_spectacular.utils import extend_schema, extend_schema_view | ||
from rest_framework import authentication, permissions, views | ||
|
||
from openforms.api.views import ListMixin | ||
|
||
from ..client import get_objecttypes_client | ||
from .serializers import ObjecttypeSerializer, ObjecttypeVersionSerializer | ||
|
||
|
||
@extend_schema_view( | ||
get=extend_schema( | ||
tags=["registration"], | ||
), | ||
) | ||
class ObjecttypesListView(ListMixin, views.APIView): | ||
""" | ||
List the available Objecttypes. | ||
Note that the response data is essentially proxied from the configured Objecttypes API. | ||
""" | ||
|
||
authentication_classes = (authentication.SessionAuthentication,) | ||
permission_classes = (permissions.IsAdminUser,) | ||
serializer_class = ObjecttypeSerializer | ||
|
||
def get_objects(self) -> list[dict[str, Any]]: | ||
with get_objecttypes_client() as client: | ||
return client.list_objecttypes() | ||
|
||
|
||
@extend_schema_view( | ||
get=extend_schema( | ||
tags=["registration"], | ||
), | ||
) | ||
class ObjecttypeVersionsListView(ListMixin, views.APIView): | ||
""" | ||
List the available versions for an Objecttype. | ||
Note that the response data is essentially proxied from the configured Objecttypes API. | ||
""" | ||
|
||
authentication_classes = (authentication.SessionAuthentication,) | ||
permission_classes = (permissions.IsAdminUser,) | ||
serializer_class = ObjecttypeVersionSerializer | ||
|
||
def get_objects(self) -> list[dict[str, Any]]: | ||
with get_objecttypes_client() as client: | ||
return client.list_objecttype_versions(self.kwargs["submission_uuid"]) |
36 changes: 36 additions & 0 deletions
36
.../ObjecttypeVersionsAPIEndpointsTests.test_list_objecttype_verions_unknown_objecttype.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate, br | ||
Authorization: | ||
- Token 171be5abaf41e7856b423ad513df1ef8f867ff48 | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- python-requests/2.31.0 | ||
method: GET | ||
uri: http://localhost:8001/api/v2/objecttypes/39da819c-ac6c-4037-ae2b-6bfc39f6564b/versions | ||
response: | ||
body: | ||
string: '{"count":0,"next":null,"previous":null,"results":[]}' | ||
headers: | ||
Allow: | ||
- GET, POST, HEAD, OPTIONS | ||
Content-Length: | ||
- '52' | ||
Content-Type: | ||
- application/json | ||
Referrer-Policy: | ||
- same-origin | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
37 changes: 37 additions & 0 deletions
37
...sAPIEndpointsTests/ObjecttypeVersionsAPIEndpointsTests.test_list_objecttype_versions.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate, br | ||
Authorization: | ||
- Token 171be5abaf41e7856b423ad513df1ef8f867ff48 | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- python-requests/2.31.0 | ||
method: GET | ||
uri: http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f/versions | ||
response: | ||
body: | ||
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f/versions/1","version":1,"objectType":"http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f","status":"published","jsonSchema":{"$id":"https://example.com/tree.schema.json","type":"object","title":"Tree","$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"height":{"type":"integer","description":"The | ||
height of the tree."}}},"createdAt":"2024-02-08","modifiedAt":"2024-02-08","publishedAt":"2024-02-08"}]}' | ||
headers: | ||
Allow: | ||
- GET, POST, HEAD, OPTIONS | ||
Content-Length: | ||
- '585' | ||
Content-Type: | ||
- application/json | ||
Referrer-Policy: | ||
- same-origin | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
37 changes: 37 additions & 0 deletions
37
...rsionsAPIEndpointsTests/ObjecttypeVersionsAPIEndpointsTests.test_staff_user_required.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate, br | ||
Authorization: | ||
- Token 171be5abaf41e7856b423ad513df1ef8f867ff48 | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- python-requests/2.31.0 | ||
method: GET | ||
uri: http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f/versions | ||
response: | ||
body: | ||
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f/versions/1","version":1,"objectType":"http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f","status":"published","jsonSchema":{"$id":"https://example.com/tree.schema.json","type":"object","title":"Tree","$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"height":{"type":"integer","description":"The | ||
height of the tree."}}},"createdAt":"2024-02-08","modifiedAt":"2024-02-08","publishedAt":"2024-02-08"}]}' | ||
headers: | ||
Allow: | ||
- GET, POST, HEAD, OPTIONS | ||
Content-Length: | ||
- '585' | ||
Content-Type: | ||
- application/json | ||
Referrer-Policy: | ||
- same-origin | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
36 changes: 36 additions & 0 deletions
36
...ttes/ObjecttypesAPIEndpointsTests/ObjecttypesAPIEndpointsTests.test_list_objecttypes.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate, br | ||
Authorization: | ||
- Token 171be5abaf41e7856b423ad513df1ef8f867ff48 | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- python-requests/2.31.0 | ||
method: GET | ||
uri: http://localhost:8001/api/v2/objecttypes | ||
response: | ||
body: | ||
string: '{"count":2,"next":null,"previous":null,"results":[{"url":"http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f","uuid":"3edfdaf7-f469-470b-a391-bb7ea015bd6f","name":"Tree","namePlural":"Trees","description":"","dataClassification":"confidential","maintainerOrganization":"","maintainerDepartment":"","contactPerson":"","contactEmail":"","source":"","updateFrequency":"unknown","providerOrganization":"","documentationUrl":"","labels":{},"createdAt":"2024-02-08","modifiedAt":"2024-02-08","allowGeometry":true,"versions":["http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f/versions/1"]},{"url":"http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48","uuid":"8e46e0a5-b1b4-449b-b9e9-fa3cea655f48","name":"Person","namePlural":"Persons","description":"","dataClassification":"open","maintainerOrganization":"","maintainerDepartment":"","contactPerson":"","contactEmail":"","source":"","updateFrequency":"unknown","providerOrganization":"","documentationUrl":"","labels":{},"createdAt":"2023-10-24","modifiedAt":"2024-02-08","allowGeometry":true,"versions":["http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions/1","http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions/2","http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions/3"]}]}' | ||
headers: | ||
Allow: | ||
- GET, POST, HEAD, OPTIONS | ||
Content-Length: | ||
- '1407' | ||
Content-Type: | ||
- application/json | ||
Referrer-Policy: | ||
- same-origin | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
Oops, something went wrong.