From 2e2c1b2fec9b5bfa411280f152a61d94a539ff50 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 13 Dec 2018 22:58:31 +0100 Subject: [PATCH 2/4] api: pep8ness (#28962) --- src/authentic2/api_views.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/authentic2/api_views.py b/src/authentic2/api_views.py index d582a28f..e0fbcdbe 100644 --- a/src/authentic2/api_views.py +++ b/src/authentic2/api_views.py @@ -1,4 +1,19 @@ -'''Views for Authentic2 API''' +# authentic2 - Authentic2 OIDC IdP plugin +# Copyright (C) 2018 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import logging import smtplib @@ -121,8 +136,8 @@ class RegistrationSerializer(serializers.Serializer): User.objects.filter(ou=ou, email__iexact=data['email']).exists(): raise serializers.ValidationError( _('You already have an account')) - if ou.username_is_unique and not \ - 'username' in data: + if (ou.username_is_unique and + 'username' not in data): raise serializers.ValidationError( _('Username is required in this ou')) if ou.username_is_unique and User.objects.filter( @@ -200,7 +215,7 @@ class Register(BaseRpcView): ou=validated_data['ou'], context=ctx, **registration_data) - except smtplib.SMTPException, e: + except smtplib.SMTPException as e: response = { 'result': 0, 'errors': { @@ -387,7 +402,7 @@ class BaseUserSerializer(serializers.ModelSerializer): context={ 'data': original_data, }) - except smtplib.SMTPException, e: + except smtplib.SMTPException as e: logging.getLogger(__name__).error(u'registration mail could not be sent to user %s ' 'created through API: %s', instance, e) return instance @@ -565,7 +580,10 @@ class UsersAPI(HookMixin, ExceptionHandlerMixin, ModelViewSet): if 'service-slug' in self.request.GET and 'service-ou' in self.request.GET: service_slug = self.request.GET['service-slug'] service_ou = self.request.GET['service-ou'] - service = Service.objects.filter(slug=service_slug, ou__slug=service_ou).prefetch_related('authorized_roles').first() + service = Service.objects.filter( + slug=service_slug, + ou__slug=service_ou + ).prefetch_related('authorized_roles').first() if service and service.authorized_roles.all(): qs = qs.filter(roles__in=service.authorized_roles.children()) qs = qs.distinct() @@ -616,7 +634,8 @@ class UsersAPI(HookMixin, ExceptionHandlerMixin, ModelViewSet): hooks.call_hooks('api_modify_response', self, 'synchronization', data) return Response(data) - @detail_route(methods=['post'], url_path='password-reset', permission_classes=(DjangoPermission('custom_user.reset_password_user'),)) + @detail_route(methods=['post'], url_path='password-reset', + permission_classes=(DjangoPermission('custom_user.reset_password_user'),)) def password_reset(self, request, uuid): user = self.get_object() # An user without email cannot receive the token @@ -742,7 +761,6 @@ class ValidatePasswordSerializer(serializers.Serializer): password = serializers.CharField(required=True, allow_blank=True) - class ValidatePasswordAPI(BaseRpcView): permission_classes = () authentication_classes = (CsrfExemptSessionAuthentication,) -- 2.18.0