]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: Explicitly define fields
authorStephen Finucane <stephen@that.guru>
Wed, 23 Nov 2016 19:41:12 +0000 (19:41 +0000)
committerStephen Finucane <stephen@that.guru>
Fri, 23 Dec 2016 23:37:51 +0000 (23:37 +0000)
Explicitly define included fields (using 'Meta.fields') rather than
those that should be excluded (using 'Meta.exclude'). This ensure fields
that are exposed by the API don't change unless we explicitly change
them

The only side-effect of this change should be a consistent ordering of
the output - the ordering used in the 'Meta.fields' will be consistently
used, thus ordering is now important and some fields are moved around
to reflect this.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
patchwork/api/check.py
patchwork/api/patch.py
patchwork/api/person.py
patchwork/api/project.py
patchwork/api/user.py

index 26a25958ec0e383dab8d04cc15803257256ddc0f..2fd681a1fe1d1b2a0a9f0a5034fe6eee5bd1f1ad 100644 (file)
@@ -63,7 +63,7 @@ class CheckSerializer(ModelSerializer):
     class Meta:
         model = Check
         fields = ('patch', 'user', 'date', 'state', 'target_url',
-                  'description', 'context',)
+                  'context', 'description')
         read_only_fields = ('date',)
 
 
index 3f464b26c0d066676e75b6f35eefea640a9e6802..3af5994fcd2a7ce1e9491d8c6cff402424e676ac 100644 (file)
@@ -72,11 +72,12 @@ class PatchSerializer(HyperlinkedModelSerializer):
     class Meta:
         model = Patch
         list_serializer_class = PatchListSerializer
+        fields = ('url', 'project', 'msgid', 'date', 'name', 'commit_ref',
+                  'pull_url', 'state', 'archived', 'hash', 'submitter',
+                  'delegate', 'mbox', 'check', 'checks', 'tags', 'headers',
+                  'content', 'diff')
         read_only_fields = ('project', 'name', 'date', 'submitter', 'diff',
                             'content', 'hash', 'msgid')
-        # there's no need to expose an entire "tags" endpoint, so we custom
-        # render this field
-        exclude = ('tags',)
 
 
 class PatchViewSet(PatchworkViewSet):
index 758b21d46101913535b52c5a1622d73081f1c962..fe1e3b766496dd51e34c7807a8c7de3f95e18aac 100644 (file)
@@ -27,7 +27,7 @@ from patchwork.models import Person
 class PersonSerializer(HyperlinkedModelSerializer):
     class Meta:
         model = Person
-        fields = ('email', 'name', 'user')
+        fields = ('url', 'name', 'email', 'user')
 
 
 class PeopleViewSet(PatchworkViewSet):
index b4debb61c10e35b946f354779189951e15ede0ca..2f636948522057bde0bc32177c52d10440717fcd 100644 (file)
@@ -34,7 +34,8 @@ class ProjectSerializer(HyperlinkedModelSerializer):
 
     class Meta:
         model = Project
-        exclude = ('send_notifications', 'use_tags')
+        fields = ('url', 'name', 'linkname', 'listid', 'listemail', 'web_url',
+                  'scm_url', 'webscm_url')
 
 
 class ProjectViewSet(PatchworkViewSet):
index b25054fe40609af1f6fb762db31d9627f2993e91..3a4ae1a609dae1711aa0d05d5665784aaa553fae 100644 (file)
@@ -27,9 +27,7 @@ from patchwork.api.base import PatchworkViewSet
 class UserSerializer(HyperlinkedModelSerializer):
     class Meta:
         model = User
-        exclude = ('date_joined', 'groups', 'is_active', 'is_staff',
-                   'is_superuser', 'last_login', 'password',
-                   'user_permissions')
+        fields = ('url', 'username', 'first_name', 'last_name', 'email')
 
 
 class UserViewSet(PatchworkViewSet):