[PATCH v5 05/10] REST: Add Users to the API

Finucane, Stephen stephen.finucane at intel.com
Thu Jun 2 23:05:21 AEST 2016


On 26 May 20:12, Andy Doan wrote:
> This exports user objects via the REST API.
> 
> Security Constraints:
>  * The API is read-only to authenticated users
> 
> Signed-off-by: Andy Doan <andy.doan at linaro.org>

There's some dead code and I'd personally like to rename a field, but
I'm happy to sign off on this. Let me know if you agree with below and
I'll do it at merge time.

Reviewed-by: Stephen Finucane <stephen.finucane at intel.com>

> ---
>  patchwork/rest_serializers.py    | 12 ++++++++--
>  patchwork/tests/test_rest_api.py | 48 ++++++++++++++++++++++++++++++++++++++--
>  patchwork/views/rest_api.py      |  9 +++++++-
>  3 files changed, 64 insertions(+), 5 deletions(-)
> 
> diff --git a/patchwork/rest_serializers.py b/patchwork/rest_serializers.py
> index 0bb8f23..4f22870 100644
> --- a/patchwork/rest_serializers.py
> +++ b/patchwork/rest_serializers.py
> @@ -17,19 +17,27 @@
>  # along with Patchwork; if not, write to the Free Software
>  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
>  
> +from django.contrib.auth.models import User
> +
>  from rest_framework.serializers import HyperlinkedModelSerializer
>  
>  from patchwork.models import Person, Project
>  
>  
> +class UserSerializer(HyperlinkedModelSerializer):
> +    class Meta:
> +        model = User
> +        exclude = ('date_joined', 'groups', 'is_active', 'is_staff',
> +                   'is_superuser', 'last_login', 'password',
> +                   'user_permissions')
> +
> +
>  class PersonSerializer(HyperlinkedModelSerializer):
>      class Meta:
>          model = Person
> -        exclude = ('user',)

I still wonder if this should be represented as 'user_url' in response.
This seems like a more descriptive name, given the data. Seems like an
easy fix that I'd be happy to do, if you agree?

>      def to_representation(self, instance):
>          data = super(PersonSerializer, self).to_representation(instance)
> -        data['username'] = instance.user.username if instance.user else ''
>          return data

This method can be dropped now, I guess (or never created, per comment
on previous patch).


More information about the Patchwork mailing list