From b0abb3dc2470c59de7668a59e370a8e08e8fec22 Mon Sep 17 00:00:00 2001
From: Dan Braghis <dan.braghis@torchbox.com>
Date: Thu, 25 Jan 2018 15:30:48 +0000
Subject: [PATCH] Tweaks based on feedback

---
 opentech/apply/funds/blocks.py |  5 +++++
 opentech/apply/funds/models.py | 18 +++++++++++++---
 opentech/apply/users/views.py  | 39 +++++++++++-----------------------
 3 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/opentech/apply/funds/blocks.py b/opentech/apply/funds/blocks.py
index 6942a19fa..2fe74b168 100644
--- a/opentech/apply/funds/blocks.py
+++ b/opentech/apply/funds/blocks.py
@@ -153,10 +153,15 @@ class EmailBlock(MustIncludeFieldBlock):
     description = 'The applicant email address'
     widget = forms.EmailInput
 
+    class Meta:
+        icon = 'user'
+
 
 class FullNameBlock(MustIncludeFieldBlock):
     name = 'full_name'
     description = 'Full name'
 
+    class Meta:
+        icon = 'mail'
 
 REQUIRED_BLOCK_NAMES = [block.name for block in MustIncludeFieldBlock.__subclasses__()]
diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py
index 2ec4d4248..0e9c76394 100644
--- a/opentech/apply/funds/models.py
+++ b/opentech/apply/funds/models.py
@@ -19,10 +19,13 @@ from wagtail.wagtailadmin.edit_handlers import (
     FieldRowPanel,
     InlinePanel,
     MultiFieldPanel,
+    ObjectList,
     StreamFieldPanel,
+    TabbedInterface
 )
+
 from wagtail.wagtailcore.fields import StreamField
-from wagtail.wagtailcore.models import Orderable
+from wagtail.wagtailcore.models import Orderable, Page
 from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormSubmission
 
 from opentech.apply.stream_forms.models import AbstractStreamForm
@@ -125,6 +128,9 @@ class DefinableWorkflowStreamForm(AbstractEmailForm, AbstractStreamForm):
     content_panels = AbstractStreamForm.content_panels + [
         FieldPanel('workflow'),
         InlinePanel('forms', label="Forms"),
+    ]
+
+    email_confirmation_panels = [
         MultiFieldPanel(
             [
                 FieldRowPanel([
@@ -135,10 +141,16 @@ class DefinableWorkflowStreamForm(AbstractEmailForm, AbstractStreamForm):
                 FieldPanel('confirmation_text_extra'),
             ],
             heading="Confirmation email",
-            classname="collapsible collapsed"
-        ),
+        )
     ]
 
+    edit_handler = TabbedInterface([
+        ObjectList(content_panels, heading='Content'),
+        ObjectList(email_confirmation_panels, heading='Confirmation email'),
+        ObjectList(Page.promote_panels, heading='Promote'),
+        ObjectList(Page.settings_panels, heading='Settings', classname="settings"),
+    ])
+
 
 class FundType(DefinableWorkflowStreamForm):
     class Meta:
diff --git a/opentech/apply/users/views.py b/opentech/apply/users/views.py
index 0b7ad0a7b..dad852905 100644
--- a/opentech/apply/users/views.py
+++ b/opentech/apply/users/views.py
@@ -34,44 +34,31 @@ def oauth(request):
 
 
 class ActivationView(TemplateView):
-    """
-    Inspired by https://github.com/ubernostrum/django-registration
-    """
-
     def get(self, request, *args, **kwargs):
-        user = self.activate(*args, **kwargs)
-        if user:
+        user = self.get_user(kwargs.get('uidb64'))
+
+        if self.valid(user, kwargs.get('token')):
+            user.is_active = True
+            user.save()
+
             user.backend = 'django.contrib.auth.backends.ModelBackend'
             login(request, user)
             return redirect('users:activate_password')
 
         return render(request, 'users/activation/invalid.html')
 
-    def activate(self, *args, **kwargs):
-        user = self.validate_token(kwargs.get('uidb64'), kwargs.get('token'))
-        if user:
-            user.is_active = True
-            user.save()
-            return user
-        return False
 
-    def validate_token(self, uidb64, token):
+    def valid(self, user, token):
         """
-        Verify that the activation key is valid and within the
-        permitted activation time window, returning the username if
-        valid or ``None`` if not.
+        Verify that the activation token is valid and within the
+        permitted activation time window.
         """
 
-        uid = force_text(urlsafe_base64_decode(uidb64))
-        user = self.get_user(uid)
         token_generator = PasswordResetTokenGenerator()
+        return user is not None and token_generator.check_token(user, token)
 
-        if user is not None and token_generator.check_token(user, token):
-            return user
-
-        return False
 
-    def get_user(self, uid):
+    def get_user(self, uidb64):
         """
         Given the verified uid, look up and return the
         corresponding user account if it exists, or ``None`` if it
@@ -81,7 +68,7 @@ class ActivationView(TemplateView):
 
         try:
             user = User.objects.get(**{
-                'pk': uid,
+                'pk': force_text(urlsafe_base64_decode(uidb64)),
                 'is_active': False
             })
             return user
@@ -93,8 +80,6 @@ def create_password(request):
     """
     A custom view for the admin password change form used for account activation.
     """
-    if request.user.is_active:
-        raise PermissionDenied
 
     if request.method == 'POST':
         form = AdminPasswordChangeForm(request.user, request.POST)
-- 
GitLab