Browse Source

DIV-528 Adding intercept for orders page

pull/160/head
Justin Johnson 8 years ago
parent
commit
8d1a382954
15 changed files with 122 additions and 25 deletions
  1. +2
    -0
      .flake8
  2. +14
    -0
      edivorce/apps/core/authenticators.py
  3. +28
    -1
      edivorce/apps/core/decorators.py
  4. +1
    -0
      edivorce/apps/core/middleware/bceid_middleware.py
  5. +19
    -0
      edivorce/apps/core/migrations/0017_bceiduser_has_seen_orders_page.py
  6. +4
    -1
      edivorce/apps/core/models.py
  7. +1
    -1
      edivorce/apps/core/static/css/main.css
  8. +1
    -1
      edivorce/apps/core/static/css/main.css.map
  9. +4
    -0
      edivorce/apps/core/static/css/main.scss
  10. +21
    -8
      edivorce/apps/core/templates/question/01_orders.html
  11. +2
    -3
      edivorce/apps/core/urls.py
  12. +3
    -1
      edivorce/apps/core/utils/user_response.py
  13. +2
    -7
      edivorce/apps/core/views/api.py
  14. +17
    -1
      edivorce/apps/core/views/main.py
  15. +3
    -1
      edivorce/settings/base.py

+ 2
- 0
.flake8 View File

@ -0,0 +1,2 @@
[flake8]
max-line-length = 99

+ 14
- 0
edivorce/apps/core/authenticators.py View File

@ -0,0 +1,14 @@
from rest_framework import authentication
class BCeIDAuthentication(authentication.BaseAuthentication):
"""
Make the DRF user the BCeID user populated in our middleware, to avoid DRF
overwriting our user for API calls.
This relies on our middleware entirely for authentication.
"""
def authenticate(self, request):
request.user = request._user # pylint: disable=protected-access
return (request.user, None)

+ 28
- 1
edivorce/apps/core/decorators.py View File

@ -1,6 +1,8 @@
from django.conf import settings
from django.shortcuts import redirect
base_url = settings.PROXY_BASE_URL + settings.FORCE_SCRIPT_NAME[:-1]
def bceid_required(function=None):
"""
@ -12,7 +14,32 @@ def bceid_required(function=None):
def _dec(view_func):
def _view(request, *args, **kwargs):
if not request.user.is_authenticated():
return redirect(settings.PROXY_BASE_URL + settings.FORCE_SCRIPT_NAME[:-1] + '/login')
return redirect(base_url + '/login')
return view_func(request, *args, **kwargs)
_view.__name__ = view_func.__name__
_view.__dict__ = view_func.__dict__
_view.__doc__ = view_func.__doc__
return _view
return _dec if function is None else _dec(function)
def intercept(function=None):
"""
Decorator to redirect to intercept page
"""
terms = {'question__key': 'want_which_orders'}
def _dec(view_func):
def _view(request, *args, **kwargs):
if (request.user.is_authenticated() and
not request.user.has_seen_orders_page and
not request.user.responses.filter(**terms).exists()):
request.user.has_seen_orders_page = True
request.user.save()
return redirect(base_url + '/intercept')
return view_func(request, *args, **kwargs)
_view.__name__ = view_func.__name__


+ 1
- 0
edivorce/apps/core/middleware/bceid_middleware.py View File

@ -24,6 +24,7 @@ class AnonymousUser():
def is_anonymous(self):
return True
anonymous_user = AnonymousUser()


+ 19
- 0
edivorce/apps/core/migrations/0017_bceiduser_has_seen_orders_page.py View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0016_auto_20171114_2151'),
]
operations = [
migrations.AddField(
model_name='bceiduser',
name='has_seen_orders_page',
field=models.BooleanField(default=False),
),
]

+ 4
- 1
edivorce/apps/core/models.py View File

@ -25,6 +25,9 @@ class BceidUser(models.Model):
last_login = models.DateTimeField(default=timezone.now)
""" Most recent login timestamp """
has_seen_orders_page = models.BooleanField(default=False)
""" Flag for intercept page """
def is_authenticated(self):
return True
@ -57,7 +60,7 @@ class Question(models.Model):
""" 'Required', 'Conditional', or '' [blank = not required] """
conditional_target = models.TextField(blank=True)
""" For conditionally required questions, this is the other question that it is conditional upon """
""" For conditional questions, this is the question it is conditional upon """
reveal_response = models.TextField(blank=True)
""" The value of the other question that makes this question required """


+ 1
- 1
edivorce/apps/core/static/css/main.css
File diff suppressed because it is too large
View File


+ 1
- 1
edivorce/apps/core/static/css/main.css.map
File diff suppressed because it is too large
View File


+ 4
- 0
edivorce/apps/core/static/css/main.scss View File

@ -168,6 +168,10 @@ img {
left: 27px;
}
&.add-top-margin {
margin-top: 20px;
}
&.hard-stop {
background-color: #faebe9;


+ 21
- 8
edivorce/apps/core/templates/question/01_orders.html View File

@ -4,19 +4,26 @@
{% block title %}{{ block.super }}: Prequalification{% endblock %}
{% block progress %}{% include "partials/progress.html" %}{% endblock %}
{% block progress %}
{% if not intercepted %}{% include "partials/progress.html" %}{% endif %}
{% endblock %}
{% block content %}
<h1><small>Step 1:</small>What are you asking for
<span class="tooltip-link" data-toggle="tooltip" data-placement="auto" data-html="true" data-trigger="click"
<h1>
{% if not intercepted %}<small>Step 1:</small>{% endif %}
What are you asking for
(<span class="tooltip-link" data-toggle="tooltip" data-placement="auto"
data-html="true" data-trigger="click"
title="
<p><b>Orders</b></p>
<p>A record of a decision made by a judge or master that tells you or
your spouse what you must do (or not do). For example: The court has
made an order that your spouse must pay you $250 on a monthly basis
to help pay off your combined debt.
">(Orders)<i class="fa fa-question-circle" aria-hidden="true"></i></span>?</h1>
">Orders<i class="fa fa-question-circle" aria-hidden="true"></i>
</span>)?
</h1>
<p class="intro">Please select what you are asking for. Later on you will be
asked to provide details for each request.</p>
@ -136,7 +143,7 @@ asked to provide details for each request.</p>
<div class="checkbox"><label>{% input_field type="checkbox" name="want_which_orders" value="Child support" %}<b>Child support (Out of scope)</b></label></div>
{% endcomment %}
<div class="information-message bg-danger" id="unselected_orders_alert" hidden>
<div class="information-message bg-danger add-top-margin" id="unselected_orders_alert" hidden>
<p>We've noticed that at this point in time you are not applying for
spousal support and/or division of property, debt, or a pension. If you
decide to request these items in the future there are some time limits.</p>
@ -171,7 +178,7 @@ asked to provide details for each request.</p>
not need to appear in court. However a judge needs to review
and approve what you are asking for. Orders allow you to tell
the court what you want (for example division of property
and debt).</p>
and debt, child support, spousal support, etc.).</p>
</div>
<div class="modal-footer">
<a type="button" class="btn btn-primary btn-lg" data-dismiss="modal">Continue</a>
@ -182,9 +189,15 @@ asked to provide details for each request.</p>
{% endblock %}
{% block formBack %}{% url 'overview' %}{% endblock %}
{% block formBack %}{% if not intercepted %}{% url 'overview' %}{% endif %}{% endblock %}
{% block formNext %}{% next_step step='orders' %}{% endblock %}
{% block formNext %}
{% if intercepted %}
{% url 'overview' %}
{% else %}
{% next_step step='orders' %}
{% endif %}
{% endblock %}
{% block nextButtonAttribute %}id="check_order_selected" data-proceed="false" data-show_alert="false"{% endblock %}


+ 2
- 3
edivorce/apps/core/urls.py View File

@ -1,6 +1,6 @@
from django.conf.urls import url
from .views import main, system, styleguide, pdf, api, localdev
from .views import main, system, pdf, api, localdev
handler404 = 'core.views.main.page_not_found'
handler500 = 'core.views.main.server_error'
@ -18,6 +18,7 @@ urlpatterns = [
url(r'^overview', main.overview, name="overview"),
url(r'^success', main.success, name="success"),
url(r'^incomplete', main.incomplete, name="incomplete"),
url(r'^intercept', main.intercept_page, name="intercept"),
url(r'^dashboard/(?P<nav_step>.*)', main.dashboard_nav, name="dashboard_nav"),
url(r'^health$', system.health),
url(r'^legal', main.legal, name="legal"),
@ -29,5 +30,3 @@ urlpatterns = [
url(r'^question/(?P<step>.*)$', main.question, name="question_steps"),
url(r'^$', main.home, name="home"),
]

+ 3
- 1
edivorce/apps/core/utils/user_response.py View File

@ -21,7 +21,9 @@ def get_responses_from_db_grouped_by_steps(bceid_user, hide_failed_conditionals=
Group questions and responses by steps to which they belong
`hide_failed_conditionals` goes through the responses after grouping and
tests their conditionality. If they fail, the response is blanked.
tests their conditionality. If they fail, the response is blanked (this is
to hide conditional responses that are no longer applicable but haven't been
erased, mainly for the question review page).
"""
married, married_questions, responses = __get_data(bceid_user)
responses_dict = {}


+ 2
- 7
edivorce/apps/core/views/api.py View File

@ -21,21 +21,16 @@ class UserResponseHandler(APIView):
# As a result of discussion, decide to escape < and > only
value = request.data['value'].replace('<', '&lt;').replace('>', '&gt;')
if request.user.is_authenticated():
save_to_db(serializer, question, value, request.user.user_guid)
save_to_db(serializer, question, value, request.user)
else:
# only prequalification questions can be answered when you
# aren't logged into BCeID
if not question_key in question_step_mapping['prequalification']:
if question_key not in question_step_mapping['prequalification']:
return Response(data="Not logged in",
status=status.HTTP_511_NETWORK_AUTHENTICATION_REQUIRED)
save_to_session(request, question, value)
except Question.DoesNotExist:
return Response(data="Question: '%s' does not exist" % question_key,
status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
import traceback
traceback.print_exc()
print(e)
return Response(status=status.HTTP_200_OK)

+ 17
- 1
edivorce/apps/core/views/main.py View File

@ -5,7 +5,7 @@ from django.shortcuts import render, redirect, render_to_response
from django.utils import timezone
from django.template import RequestContext
from ..decorators import bceid_required
from ..decorators import bceid_required, intercept
from ..utils.question_step_mapping import list_of_registries
from ..utils.step_completeness import get_step_status, is_complete
from ..utils.template_step_order import template_step_order
@ -138,6 +138,7 @@ def logout(request):
@bceid_required
@intercept
def overview(request):
"""
Dashboard: Process overview page.
@ -217,3 +218,18 @@ def legal(request):
Legal Information page
"""
return render(request, 'legal.html', context={'active_page': 'legal'})
@bceid_required
def intercept_page(request):
"""
On intercept, show the Orders page to get the requested orders before the
user sees the nav on the left, so that it's already customized to their
input.
"""
template = 'question/%02d_%s.html' % (template_step_order['orders'], 'orders')
responses_dict = get_responses_from_db(request.user)
responses_dict['intercepted'] = True
return render(request, template_name=template, context=responses_dict)

+ 3
- 1
edivorce/settings/base.py View File

@ -85,7 +85,9 @@ WSGI_APPLICATION = 'wsgi.application'
# need to disable auth in Django Rest Framework so it doesn't get triggered
# by presence of Basic Auth headers
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': []
'DEFAULT_AUTHENTICATION_CLASSES': [
'edivorce.apps.core.authenticators.BCeIDAuthentication',
]
}
# Internationalization


Loading…
Cancel
Save