Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Raise 400 error for invalid contributor param type #433

Merged
merged 1 commit into from
Mar 29, 2019
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Return 400/Bad Request error for /api/facilities request with invalid contributor parameter type. [#433](https://github.com/open-apparel-registry/open-apparel-registry/pull/433)

### Security

## [2.0.0] - 2019-03-27
Expand Down
13 changes: 12 additions & 1 deletion src/django/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
from django.urls import reverse
from rest_framework.serializers import (CharField,
EmailField,
IntegerField,
ModelSerializer,
SerializerMethodField,
ValidationError)
ValidationError,
Serializer)
from rest_framework_gis.serializers import GeoFeatureModelSerializer
from rest_auth.serializers import (PasswordResetSerializer,
PasswordResetConfirmSerializer)
Expand Down Expand Up @@ -178,6 +180,15 @@ def get_statuses(self, facility_list):
.distinct())


class FacilityQueryParamsSerializer(Serializer):
name = CharField(required=False)
contributors = IntegerField(required=False)
contributor_types = CharField(required=False)
countries = CharField(required=False)
page = IntegerField(required=False)
pageSize = IntegerField(required=False)


class FacilitySerializer(GeoFeatureModelSerializer):
oar_id = SerializerMethodField()
country_name = SerializerMethodField()
Expand Down
7 changes: 7 additions & 0 deletions src/django/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from api.processing import parse_csv_line
from api.serializers import (FacilityListSerializer,
FacilityListItemSerializer,
FacilityQueryParamsSerializer,
FacilitySerializer,
FacilityDetailsSerializer,
UserSerializer,
Expand Down Expand Up @@ -404,10 +405,16 @@ def list(self, request):
]
}
"""
params = FacilityQueryParamsSerializer(data=request.query_params)

if not params.is_valid():
raise ValidationError(params.errors)

name = request.query_params.get(FacilitiesQueryParams.NAME,
None)
contributors = request.query_params \
.getlist(FacilitiesQueryParams.CONTRIBUTORS)

contributor_types = request \
.query_params \
.getlist(FacilitiesQueryParams.CONTRIBUTOR_TYPES)
Expand Down