[PATCH v3 06/10] REST: Add Patch Checks to the API

Finucane, Stephen stephen.finucane at intel.com
Thu May 19 20:42:26 AEST 2016


On 19 May 10:26, Finucane, Stephen wrote:
> On 18 May 22:30, Andy Doan wrote:
> > This exports patch checks via the REST API.
> > 
> > The drf-nested-routers package is used to handle the fact Checks are
> > nested under a Patch.
> > 
> > Security Constraints:
> >  * Anyone (logged in or not) can read all objects.
> >  * No one can update/delete objects.
> >  * Project maintainers and patch owners may create objects.
> > 
> > Signed-off-by: Andy Doan <andy.doan at linaro.org>
> 
> Generally OK with this, but some questions before sign off.

Actually, one more thing.

Stephen

> > ---
> >  patchwork/rest_serializers.py    | 32 +++++++++++++++--
> >  patchwork/tests/test_rest_api.py | 77 +++++++++++++++++++++++++++++++++++++++-
> >  patchwork/urls.py                |  6 ++--
> >  patchwork/views/rest_api.py      | 39 ++++++++++++++++++--
> >  requirements-test.txt            |  1 +
> >  5 files changed, 147 insertions(+), 8 deletions(-)
> > 
> > diff --git a/patchwork/rest_serializers.py b/patchwork/rest_serializers.py
> > index 9558d45..5f16954 100644
> > --- a/patchwork/rest_serializers.py
> > +++ b/patchwork/rest_serializers.py
> > @@ -21,10 +21,11 @@ import email.parser
> >  
> >  from django.core.urlresolvers import reverse
> >  
> > -from patchwork.models import Patch, Person, Project
> > +from patchwork.models import Check, Patch, Person, Project
> >  
> >  from rest_framework.serializers import (
> > -    ListSerializer, ModelSerializer)
> > +    CurrentUserDefault, HiddenField, ListSerializer, ModelSerializer,
> > +    PrimaryKeyRelatedField)
> >  
> >  
> >  class PersonSerializer(ModelSerializer):
> > @@ -71,3 +72,30 @@ class PatchSerializer(ModelSerializer):
> >          if headers:
> >              data['headers'] = email.parser.Parser().parsestr(headers, True)
> >          return data
> > +
> > +
> > +class CurrentPatchDefault(object):
> > +    def set_context(self, serializer_field):
> > +        self.patch = serializer_field.context['request'].patch
> > +
> > +    def __call__(self):
> > +        return self.patch
> > +
> > +
> > +class ChecksSerializer(ModelSerializer):
> > +    class Meta:
> > +        model = Check
> > +    user = PrimaryKeyRelatedField(read_only=True, default=CurrentUserDefault())

I'm not sure if we need to include this (it's part of the parent
'patch' object), but if we do it should probably read 'username' and be
a URL rather than an integer. HyperlinkedModelSerializer would help
here again.


More information about the Patchwork mailing list