Ver código fonte

fix(api): upgrade djoser, django-rest-framework; closes #76

- Followed this migration guide:
      https://djoser.readthedocs.io/en/latest/migration_guide.html
- API URLs to register new users and obtain tokens have changed.  Thus,
  it is required to deploy an updated desec-static app along with this
  commit.
Peter Thomassen 7 anos atrás
pai
commit
f403ec3ee5

+ 2 - 2
api/desecapi/serializers.py

@@ -80,9 +80,9 @@ class UserSerializer(djoserSerializers.UserSerializer):
         )
 
 
-class UserRegistrationSerializer(djoserSerializers.UserRegistrationSerializer):
+class UserCreateSerializer(djoserSerializers.UserCreateSerializer):
 
-    class Meta(djoserSerializers.UserRegistrationSerializer.Meta):
+    class Meta(djoserSerializers.UserCreateSerializer.Meta):
         fields = tuple(User.REQUIRED_FIELDS) + (
             User.USERNAME_FIELD,
             'password',

+ 1 - 1
api/desecapi/settings.py

@@ -118,7 +118,7 @@ DJOSER = {
     'SEND_ACTIVATION_EMAIL': False,
     'SERIALIZERS': {
         'user': 'desecapi.serializers.UserSerializer',
-        'user_registration': 'desecapi.serializers.UserRegistrationSerializer',
+        'user_create': 'desecapi.serializers.UserCreateSerializer',
     },
 }
 

+ 4 - 4
api/desecapi/urls.py

@@ -1,5 +1,4 @@
 from django.conf.urls import include, url
-from django.contrib import admin
 from desecapi.views import *
 from rest_framework.urlpatterns import format_suffix_patterns
 from desecapi import views
@@ -22,7 +21,8 @@ apiurls = [
 apiurls = format_suffix_patterns(apiurls)
 
 urlpatterns = [
-   url(r'^api/v1/auth/register/$', RegistrationView.as_view(), name='register'),
-   url(r'^api/v1/auth/', include('djoser.urls.authtoken')),
-   url(r'^api/v1/', include(apiurls)),
+    url(r'^api/v1/auth/users/create/$', UserCreateView.as_view(), name='register'),
+    url(r'^api/v1/auth/', include('djoser.urls')),
+    url(r'^api/v1/auth/', include('djoser.urls.authtoken')),
+    url(r'^api/v1/', include(apiurls)),
 ]

+ 3 - 3
api/desecapi/views.py

@@ -418,9 +418,9 @@ class DonationList(generics.CreateAPIView):
         sendDonationEmails(obj)
 
 
-class RegistrationView(views.RegistrationView):
+class UserCreateView(views.UserCreateView):
     """
-    Extends the djoser RegistrationView to record the remote IP address of any registration.
+    Extends the djoser UserCreateView to record the remote IP address of any registration.
     """
 
     def create(self, request, *args, **kwargs):
@@ -447,7 +447,7 @@ class RegistrationView(views.RegistrationView):
             )
 
         user = serializer.save(registration_remote_ip=remote_ip, captcha_required=captcha)
-        if captcha:
+        if user.captcha_required:
             send_account_lock_email(self.request, user)
         elif not user.dyn:
             context = {'token': user.get_token()}

+ 2 - 2
api/requirements.txt

@@ -1,7 +1,7 @@
 Django==1.11.*
 mysqlclient==1.3.*
-djangorestframework==3.6.*
-djoser==0.6.*
+djangorestframework==3.7.*
+djoser==1.1.*
 dnspython==1.15.*
 httpretty==0.8.*
 requests==2.18.*

+ 4 - 4
docs/introduction.rst

@@ -25,9 +25,9 @@ User management is handled via Django's djoser library.  For usage, please
 check the `djoser endpoint documentation`_.
 
 .. _djoser endpoint documentation:
-    https://djoser.readthedocs.io/en/latest/endpoints.html
+    https://djoser.readthedocs.io/en/latest/getting_started.html#available-endpoints
 
 Most operations require authentication of the domain owner using a token that
-is returned by djoser's ``login/`` endpoint.  To authenticate, this token is
-transmitted via the HTTP ``Authorization`` header, as shown in the examples in
-this document.
+is returned by djoser's ``token/create/`` endpoint.  To authenticate, this
+token is transmitted via the HTTP ``Authorization`` header, as shown in the
+examples in this document.