api: pep8ness (#28962)
This commit is contained in:
parent
3f5821aa5f
commit
dabfc180a0
|
@ -1,4 +1,19 @@
|
||||||
'''Views for Authentic2 API'''
|
# authentic2 - versatile identity manager
|
||||||
|
# Copyright (C) 2010-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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import smtplib
|
import smtplib
|
||||||
|
|
||||||
|
@ -121,8 +136,8 @@ class RegistrationSerializer(serializers.Serializer):
|
||||||
User.objects.filter(ou=ou, email__iexact=data['email']).exists():
|
User.objects.filter(ou=ou, email__iexact=data['email']).exists():
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
_('You already have an account'))
|
_('You already have an account'))
|
||||||
if ou.username_is_unique and not \
|
if (ou.username_is_unique and
|
||||||
'username' in data:
|
'username' not in data):
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
_('Username is required in this ou'))
|
_('Username is required in this ou'))
|
||||||
if ou.username_is_unique and User.objects.filter(
|
if ou.username_is_unique and User.objects.filter(
|
||||||
|
@ -200,7 +215,7 @@ class Register(BaseRpcView):
|
||||||
ou=validated_data['ou'],
|
ou=validated_data['ou'],
|
||||||
context=ctx,
|
context=ctx,
|
||||||
**registration_data)
|
**registration_data)
|
||||||
except smtplib.SMTPException, e:
|
except smtplib.SMTPException as e:
|
||||||
response = {
|
response = {
|
||||||
'result': 0,
|
'result': 0,
|
||||||
'errors': {
|
'errors': {
|
||||||
|
@ -387,7 +402,7 @@ class BaseUserSerializer(serializers.ModelSerializer):
|
||||||
context={
|
context={
|
||||||
'data': original_data,
|
'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 '
|
logging.getLogger(__name__).error(u'registration mail could not be sent to user %s '
|
||||||
'created through API: %s', instance, e)
|
'created through API: %s', instance, e)
|
||||||
return instance
|
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:
|
if 'service-slug' in self.request.GET and 'service-ou' in self.request.GET:
|
||||||
service_slug = self.request.GET['service-slug']
|
service_slug = self.request.GET['service-slug']
|
||||||
service_ou = self.request.GET['service-ou']
|
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():
|
if service and service.authorized_roles.all():
|
||||||
qs = qs.filter(roles__in=service.authorized_roles.children())
|
qs = qs.filter(roles__in=service.authorized_roles.children())
|
||||||
qs = qs.distinct()
|
qs = qs.distinct()
|
||||||
|
@ -616,7 +634,8 @@ class UsersAPI(HookMixin, ExceptionHandlerMixin, ModelViewSet):
|
||||||
hooks.call_hooks('api_modify_response', self, 'synchronization', data)
|
hooks.call_hooks('api_modify_response', self, 'synchronization', data)
|
||||||
return Response(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):
|
def password_reset(self, request, uuid):
|
||||||
user = self.get_object()
|
user = self.get_object()
|
||||||
# An user without email cannot receive the token
|
# An user without email cannot receive the token
|
||||||
|
@ -742,7 +761,6 @@ class ValidatePasswordSerializer(serializers.Serializer):
|
||||||
password = serializers.CharField(required=True, allow_blank=True)
|
password = serializers.CharField(required=True, allow_blank=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ValidatePasswordAPI(BaseRpcView):
|
class ValidatePasswordAPI(BaseRpcView):
|
||||||
permission_classes = ()
|
permission_classes = ()
|
||||||
authentication_classes = (CsrfExemptSessionAuthentication,)
|
authentication_classes = (CsrfExemptSessionAuthentication,)
|
||||||
|
|
Loading…
Reference in New Issue