[RFC 11/11] REST: Add States to the API

Finucane, Stephen stephen.finucane at intel.com
Tue May 10 00:10:50 AEST 2016


On 15 Apr 13:24, Andy Doan wrote:
> This exports patch States via the REST API.
> 
> Security Constraints:
>  * Anyone (logged in or not) can read all objects.
>  * No one can create/update/delete
> 
> Signed-off-by: Andy Doan <andy.doan at linaro.org>

I'd like to drop the whole customisable states feature in favour of an
enum [1]. Unless you've a good reason to include this, can we avoid
putting it into the API?

[1] https://github.com/getpatchwork/patchwork/issues/4

> ---
>  patchwork/views/rest_api.py | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/patchwork/views/rest_api.py b/patchwork/views/rest_api.py
> index e2ec616..15a75c7 100644
> --- a/patchwork/views/rest_api.py
> +++ b/patchwork/views/rest_api.py
> @@ -19,7 +19,7 @@
>  
>  from django.conf.urls import url, include
>  
> -from patchwork.models import Check, Patch, Person, Project
> +from patchwork.models import Check, Patch, Person, Project, State
>  from patchwork.views.patch import mbox
>  
>  from rest_framework import permissions
> @@ -29,7 +29,8 @@ from rest_framework.response import Response
>  from rest_framework.routers import DefaultRouter
>  from rest_framework.serializers import (
>      CurrentUserDefault, HiddenField, ModelSerializer, PrimaryKeyRelatedField)
> -from rest_framework.viewsets import GenericViewSet, ModelViewSet
> +from rest_framework.viewsets import (
> +    GenericViewSet, ModelViewSet, ReadOnlyModelViewSet)
>  
>  from rest_framework_nested.routers import NestedSimpleRouter
>  
> @@ -200,10 +201,18 @@ class MboxViewSet(GenericViewSet):
>          return mbox(request, patch_pk)
>  
>  
> +class StateViewSet(ReadOnlyModelViewSet):
> +    serializer_class = create_model_serializer(State)
> +
> +    def get_queryset(self):
> +        return self.serializer_class.Meta.model.objects.all()
> +
> +
>  router = DefaultRouter()
>  router.register('patches', PatchViewSet, 'patch')
>  router.register('people', PeopleViewSet, 'person')
>  router.register('projects', ProjectViewSet, 'project')
> +router.register('states', StateViewSet, 'state')
>  
>  patches_router = NestedSimpleRouter(router, r'patches', lookup='patch')
>  patches_router.register(r'checks', ChecksViewSet, base_name='patch-checks')
> -- 
> 2.7.4
> 
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork


More information about the Patchwork mailing list