Skip to content

Commit ef48bbf

Browse files
committed
Ensure all UUID are defined with format uuid in OpenAPI schema
1 parent 67eb86f commit ef48bbf

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

api/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ class Meta:
965965
"is_visible"
966966
)
967967

968+
observation_uuid = serializers.UUIDField(source="report_id", read_only=True)
968969
user_hidden_obj = serializers.HiddenField(default=serializers.CurrentUserDefault())
969970

970971
user = SimpleAnnotatorUserSerializer(read_only=True)
@@ -1103,7 +1104,6 @@ class Meta:
11031104
)
11041105
extra_kwargs = {
11051106
"user_id": {'read_only': True},
1106-
"observation_uuid": {'source': 'report', 'read_only': True},
11071107
'created_at': {"source": "created", 'read_only': True},
11081108
'updated_at': {"source": "last_modified", 'read_only': True},
11091109
}

api/views.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ class PartnersViewSet(ReadOnlyModelViewSet, GenericViewSet):
218218
serializer_class = PartnerSerializer
219219

220220

221+
# NOTE: this can be removed if Report.version_UUID is ever changed to UUIDField (from CharField)
222+
REPORT_VIEW_LOOKUP_FIELD = "uuid"
223+
REPORT_UUID_PATH_PARAM = OpenApiParameter(
224+
name=REPORT_VIEW_LOOKUP_FIELD,
225+
type=OpenApiTypes.UUID,
226+
location=OpenApiParameter.PATH,
227+
)
228+
@extend_schema_view(
229+
retrieve=extend_schema(parameters=[REPORT_UUID_PATH_PARAM]),
230+
destroy=extend_schema(parameters=[REPORT_UUID_PATH_PARAM]),
231+
update=extend_schema(parameters=[REPORT_UUID_PATH_PARAM]),
232+
partial_update=extend_schema(parameters=[REPORT_UUID_PATH_PARAM]),
233+
)
221234
class BaseReportViewSet(
222235
CreateModelMixin,
223236
ListModelMixin,
@@ -243,7 +256,7 @@ class BaseReportViewSet(
243256
pk_str=models.functions.Cast('pk', output_field=models.CharField()),
244257
).non_deleted().filter(point__isnull=False).order_by('-server_upload_time')
245258

246-
lookup_url_kwarg = "uuid"
259+
lookup_url_kwarg = REPORT_VIEW_LOOKUP_FIELD
247260

248261
filter_backends = (DjangoFilterBackend, SearchFilter)
249262
search_fields = ("report_id", "pk_str")
@@ -385,6 +398,19 @@ class ObservationViewSest(BaseReportWithPhotosViewSet):
385398
class MyObservationViewSest(BaseMyReportViewSet, ObservationViewSest):
386399
pass
387400

401+
# NOTE: this can be removed if TigaUser.user_UUID is ever changed to UUIDField (from CharField)
402+
USER_VIEW_LOOKUP_FIELD = "uuid"
403+
USER_UUID_PATH_PARAM = OpenApiParameter(
404+
name=USER_VIEW_LOOKUP_FIELD,
405+
type=OpenApiTypes.UUID,
406+
location=OpenApiParameter.PATH,
407+
)
408+
@extend_schema_view(
409+
retrieve=extend_schema(parameters=[USER_UUID_PATH_PARAM]),
410+
destroy=extend_schema(parameters=[USER_UUID_PATH_PARAM]),
411+
update=extend_schema(parameters=[USER_UUID_PATH_PARAM]),
412+
partial_update=extend_schema(parameters=[USER_UUID_PATH_PARAM]),
413+
)
388414
class UserViewSet(
389415
UpdateModelMixin, RetrieveModelMixin, GenericViewSet
390416
):
@@ -393,7 +419,7 @@ class UserViewSet(
393419

394420
permission_classes = (UserPermissions,)
395421

396-
lookup_url_kwarg = "uuid"
422+
lookup_url_kwarg = USER_VIEW_LOOKUP_FIELD
397423

398424
def get_object(self):
399425
try:
@@ -513,6 +539,20 @@ def get_serializer_class(self):
513539
return DeviceSerializer
514540

515541

542+
# NOTE: this can be removed if Report.version_UUID is ever changed to UUIDField (from CharField)
543+
IDENTIFICATION_TASK_VIEW_LOOKUP_FIELD = "observation_uuid"
544+
OBSERVATION_UUID_PATH_PARAM = OpenApiParameter(
545+
name=IDENTIFICATION_TASK_VIEW_LOOKUP_FIELD,
546+
type=OpenApiTypes.UUID,
547+
location=OpenApiParameter.PATH,
548+
)
549+
@extend_schema_view(
550+
retrieve=extend_schema(parameters=[OBSERVATION_UUID_PATH_PARAM]),
551+
destroy=extend_schema(parameters=[OBSERVATION_UUID_PATH_PARAM]),
552+
update=extend_schema(parameters=[OBSERVATION_UUID_PATH_PARAM]),
553+
partial_update=extend_schema(parameters=[OBSERVATION_UUID_PATH_PARAM]),
554+
review=extend_schema(parameters=[OBSERVATION_UUID_PATH_PARAM]),
555+
)
516556
class IdentificationTaskViewSet(RetrieveModelMixin, ListModelMixin, GenericNoMobileViewSet):
517557
queryset = IdentificationTask.objects.all().select_related(
518558
'taxon',
@@ -549,7 +589,7 @@ class IdentificationTaskViewSet(RetrieveModelMixin, ListModelMixin, GenericNoMob
549589
permission_classes = (IdentificationTaskPermissions | UserRolePermission,)
550590

551591
lookup_field = 'pk'
552-
lookup_url_kwarg = 'observation_uuid'
592+
lookup_url_kwarg = IDENTIFICATION_TASK_VIEW_LOOKUP_FIELD
553593

554594
def get_queryset(self):
555595
return super().get_queryset().browsable(user=self.request.user)

0 commit comments

Comments
 (0)