Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove save on signout code #142

Merged
merged 3 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions app/helpers/form_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
logger = get_logger()


def get_form_for_location(
schema, block_json, location, answer_store, metadata, disable_mandatory=False
): # pylint: disable=too-many-locals
def get_form_for_location(schema, block_json, location, answer_store, metadata):
"""
Returns the form necessary for the location given a get request, plus any template arguments

Expand All @@ -21,11 +19,8 @@ def get_form_for_location(
:param location: The location which this form is for
:param answer_store: The current answer store
:param metadata: metadata
:param disable_mandatory: Make mandatory answers optional
:return: form, template_args A tuple containing the form for this location and any additional template arguments
"""
if disable_mandatory:
block_json = disable_mandatory_answers(block_json)

mapped_answers = get_mapped_answers(schema, answer_store, location=location)

Expand All @@ -40,13 +35,7 @@ def get_form_for_location(


def post_form_for_block(
schema,
block_json,
answer_store,
metadata,
request_form,
location,
disable_mandatory=False,
schema, block_json, answer_store, metadata, request_form, location
):
"""
Returns the form necessary for the location given a post request, plus any template arguments
Expand All @@ -57,10 +46,7 @@ def post_form_for_block(
:param metadata: metadata
:param request_form: form, template_args A tuple containing the form for this location and any additional template arguments
:param location: The location in the survey this post is for
:param disable_mandatory: Make mandatory answers optional
"""
if disable_mandatory:
block_json = disable_mandatory_answers(block_json)

question = block_json.get("question")

Expand All @@ -71,19 +57,6 @@ def post_form_for_block(
)


def disable_mandatory_answers(block):
def set_mandatory_to_false(question):
# Here Be Dragons: This loop modifies the input in place.
for answer in question.get("answers", []):
if answer.get("mandatory", True) is True:
answer["mandatory"] = False

if block.get("question"):
set_mandatory_to_false(block["question"])

return block


def clear_detail_answer_field(data, question):
"""
Checks the submitted answers and in the case of both checkboxes and radios,
Expand Down
59 changes: 3 additions & 56 deletions app/routes/questionnaire.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@
import humanize
import simplejson as json
from dateutil.tz import tzutc
from flask import (
Blueprint,
g,
redirect,
request,
url_for,
current_app,
jsonify,
session as cookie_session,
)
from flask import Blueprint, g, redirect, request, url_for, current_app, jsonify
from flask_login import current_user, login_required
from jwcrypto.common import base64url_decode
from sdc.crypto.encrypter import encrypt
Expand Down Expand Up @@ -145,12 +136,6 @@ def get_questionnaire(schema, questionnaire_store):
@with_questionnaire_store
@with_schema
def post_questionnaire(schema, questionnaire_store):
if any(
action in request.form
for action in ("action[save_sign_out]", "action[sign_out]")
):
return redirect(url_for("session.get_sign_out"))

router = Router(
schema,
questionnaire_store.answer_store,
Expand Down Expand Up @@ -226,9 +211,6 @@ def block(schema, questionnaire_store, block_id, list_name=None, list_item_id=No
if block_handler.block["type"] == "RelationshipCollector":
return redirect(block_handler.get_first_location_url())

if "action[sign_out]" in request.form:
return redirect(url_for("session.get_sign_out"))

if "action[clear_radios]" in request.form:
block_handler.clear_radio_answers()
return redirect(request.url)
Expand All @@ -247,10 +229,6 @@ def block(schema, questionnaire_store, block_id, list_name=None, list_item_id=No
page_title=block_handler.page_title,
)

if "action[save_sign_out]" in request.form:
block_handler.save_on_sign_out()
return redirect(url_for("session.get_sign_out"))

if block_handler.block["type"] in END_BLOCKS:
return submit_answers(
schema, questionnaire_store, block_handler.router.full_routing_path()
Expand Down Expand Up @@ -298,10 +276,6 @@ def relationship(schema, questionnaire_store, block_id, list_item_id, to_list_it
page_title=block_handler.page_title,
)

if "action[save_sign_out]" in request.form:
block_handler.save_on_sign_out()
return redirect(url_for("session.get_sign_out"))

block_handler.handle_post()
next_location_url = block_handler.get_next_location_url()
return redirect(next_location_url)
Expand All @@ -327,9 +301,6 @@ def get_thank_you(schema):
timedelta(seconds=schema.json["view_submitted_response"]["duration"])
)

cookie_session.pop("account_service_log_out_url", None)
cookie_session.pop("account_service_url", None)

return render_template(
template="thank-you",
metadata=metadata_context,
Expand All @@ -339,18 +310,10 @@ def get_thank_you(schema):
),
view_submission_url=view_submission_url,
view_submission_duration=view_submission_duration,
hide_signout_button=True,
)


@post_submission_blueprint.route("thank-you/", methods=["POST"])
@login_required
def post_thank_you():
if "action[sign_out]" in request.form:
return redirect(url_for("session.get_sign_out"))

return redirect(url_for("post_submission.get_thank_you"))


@post_submission_blueprint.route("view-submission/", methods=["GET"])
@login_required
@with_schema
Expand Down Expand Up @@ -411,29 +374,13 @@ def get_view_submission(schema):
return redirect(url_for("post_submission.get_thank_you"))


@post_submission_blueprint.route("view-submission/", methods=["POST"])
@login_required
def post_view_submission():
if "action[sign_out]" in request.form:
return redirect(url_for("session.get_sign_out"))

return redirect(url_for("post_submission.get_view_submission"))


def _generate_wtf_form(block_schema, schema, current_location):
answer_store = get_answer_store(current_user)
metadata = get_metadata(current_user)

if request.method == "POST":
disable_mandatory = "action[save_sign_out]" in request.form
return post_form_for_block(
schema,
block_schema,
answer_store,
metadata,
request.form,
current_location,
disable_mandatory,
schema, block_schema, answer_store, metadata, request.form, current_location
)
return get_form_for_location(
schema, block_schema, current_location, answer_store, metadata
Expand Down
7 changes: 6 additions & 1 deletion app/routes/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_session_expired():
return render_template("errors/session-expired")


@session_blueprint.route("/signed-out", methods=["GET"])
@session_blueprint.route("/sign-out", methods=["GET"])
def get_sign_out():
"""
Signs the user first out of eq, then the account service by hitting the account services'
Expand All @@ -133,4 +133,9 @@ def get_sign_out():
if account_service_log_out_url:
return redirect(account_service_log_out_url)

return redirect(url_for(".get_signed_out"))


@session_blueprint.route("/signed-out", methods=["GET"])
def get_signed_out():
return render_template(template="signed-out")
20 changes: 10 additions & 10 deletions app/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2020-06-03 09:10+0100\n"
"POT-Creation-Date: 2020-06-09 13:22+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -584,12 +584,12 @@ msgstr ""
msgid "Save and sign out"
msgstr ""

#: templates/layouts/configs/_save-sign-out-button.html:18
msgid "Sign out"
#: templates/layouts/configs/_save-sign-out-button.html:7
msgid "Save and complete later"
msgstr ""

#: templates/layouts/configs/_save-sign-out-button.html:32
msgid "Save and complete later"
#: templates/layouts/configs/_save-sign-out-button.html:24
msgid "Sign out"
msgstr ""

#: templates/partials/answer-guidance.html:13
Expand All @@ -607,23 +607,23 @@ msgid ""
" of the section</a>"
msgstr ""

#: templates/partials/question.html:39
#: templates/partials/question.html:48
msgid "Selecting this will clear your answer"
msgstr ""

#: templates/partials/question.html:40
#: templates/partials/question.html:49
msgid "cleared"
msgstr ""

#: templates/partials/question.html:43
#: templates/partials/question.html:52
msgid "Selecting this will deselect any selected options"
msgstr ""

#: templates/partials/question.html:44 templates/partials/question.html:52
#: templates/partials/question.html:53 templates/partials/question.html:61
msgid "deselected"
msgstr ""

#: templates/partials/question.html:48
#: templates/partials/question.html:57
msgid "Or"
msgstr ""

Expand Down
6 changes: 0 additions & 6 deletions app/views/handlers/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ def router(self):
metadata=self._questionnaire_store.metadata,
)

def save_on_sign_out(self):
self.questionnaire_store_updater.update_answers(self.form)
# The location needs to be removed as we may have previously completed this location
self.questionnaire_store_updater.remove_completed_location()
self.questionnaire_store_updater.save()

def is_location_valid(self):
return self.router.can_access_location(
self._current_location, self._routing_path
Expand Down
11 changes: 0 additions & 11 deletions app/views/handlers/relationship_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ def get_next_location_url(self):
self.parent_location, self._routing_path, self._return_to_summary
)

def save_on_sign_out(self):
self.questionnaire_store_updater.update_relationship_answer(
self.form.data,
self._current_location.list_item_id,
self._current_location.to_list_item_id,
)

self.questionnaire_store_updater.remove_completed_location(self.parent_location)

self.questionnaire_store_updater.save()

def handle_post(self):
self.questionnaire_store_updater.update_relationship_answer(
self.form.data,
Expand Down
38 changes: 15 additions & 23 deletions templates/layouts/configs/_save-sign-out-button.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
{% if current_user.is_authenticated %}
{% if account_service_log_out_url %}
{% if current_user.is_authenticated and not hide_signout_button %}

{% if save_on_signout %}
ajmaddaford marked this conversation as resolved.
Show resolved Hide resolved
{% if account_service_log_out_url %}
{% set button_text = _("Save and sign out") %}
{% else %}
{% set button_text = _("Save and complete later") %}
{% endif %}
{% do pageConfig | setAttribute("signoutButton", {
"text": _("Save and sign out"),
"name": "action[save_sign_out]",
"text": button_text,
"name": "btn-save-sign-out",
"classes": "js-btn-save",
"url": "/signed-out",
"url": "/sign-out",
"attributes": {
"data-qa": "btn-save-sign-out",
"data-ga": "click",
"data-ga-category": "Navigation",
"data-ga-action": "Save and sign out click"
}
}) %}

{% else %}
{% do pageConfig | setAttribute("signoutButton", {
"text": _("Sign out"),
"name": "action[sign_out]",
"url": "/signed-out",
"name": "btn-sign-out",
"url": "/sign-out",
"attributes": {
"data-qa": "btn-sign-out",
"data-ga": "click",
"data-ga-category": "Navigation",
"data-ga-action": "Sign out click"
}
}) %}

{% endif %}
{% else %}
{% if save_on_signout %}
{% do pageConfig | setAttribute("signoutButton", {
"text": _("Save and complete later"),
"name": "action[save_sign_out]",
"classes": "js-btn-save",
"url": "/signed-out",
"attributes": {
"data-qa": "btn-save-sign-out",
"data-ga": "click",
"data-ga-category": "Navigation",
"data-ga-action": "Save and sign out click"
}
}) %}
{% endif %}
{% endif %}

{% endif %}
20 changes: 0 additions & 20 deletions templates/macros/helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,3 @@
} %}
<a href="mailto:{{email}}{% if subject %}?subject={{ subject|urlencode }}{% endif %}" {{attr|xmlattr}}>{{email}}</a>
{%- endmacro -%}

{%- macro save_signout_button(button_text) -%}
{% set attr = {
"class": "btn btn--ghost print__hidden js-btn-save",
"data-qa": "btn-save-sign-out",
"name": "action[save_sign_out]",
} %}
{% set analytics = track('click', 'Navigation', 'Save and sign out click') %}
<button type="submit" {{attr|xmlattr}} {{analytics}}>{{ button_text }}</button>
{%- endmacro -%}

{%- macro signout_button(button_text) -%}
{% set attr = {
"class": "btn btn--ghost print__hidden",
"data-qa": "btn-sign-out",
"name": "action[sign_out]",
} %}
{% set analytics = track('click', 'Navigation', 'Sign out click') %}
<button type="submit" {{attr|xmlattr}} {{analytics}}>{{ button_text }}</button>
{%- endmacro -%}
Loading