Fix logic for showing and hiding checkbox

The ‘make this default’ checkbox should be shown, except when:
- the user is adding their first email reply to address (because the
  first one has to be the default)
- they’re editing the existing default (because they can’t change it
  to be not default)
This commit is contained in:
Chris Hill-Scott
2019-06-05 16:32:08 +01:00
parent d9df3171a0
commit 944a7d302c
3 changed files with 19 additions and 4 deletions

View File

@@ -474,12 +474,17 @@ def get_service_verify_reply_to_address_partials(service_id, notification_id):
first_email_address = current_service.count_email_reply_to_addresses == 0
notification = notification_api_client.get_notification(current_app.config["NOTIFY_SERVICE_ID"], notification_id)
replace = request.args.get('replace', False)
replace = False if replace == "False" else replace
existing_is_default = False
if replace:
existing = current_service.get_email_reply_to_address(replace)
existing_is_default = existing['is_default']
verification_status = "pending"
is_default = True if (request.args.get('is_default', False) == "True") else False
if notification["status"] in DELIVERED_STATUSES:
verification_status = "success"
if notification["to"] not in [i["email_address"] for i in current_service.email_reply_to_addresses]:
if replace and replace != "False":
if replace:
service_api_client.update_reply_to_email_address(
current_service.id, replace, email_address=notification["to"], is_default=is_default
)
@@ -505,6 +510,7 @@ def get_service_verify_reply_to_address_partials(service_id, notification_id):
notification_id=notification_id,
verification_status=verification_status,
is_default=is_default,
existing_is_default=existing_is_default,
form=form,
first_email_address=first_email_address,
replace=replace

View File

@@ -36,7 +36,7 @@
</p>
{% endcall %}
</div>
{% if replace and replace != "False" %}
{% if replace %}
{% set form_url = url_for('.service_edit_email_reply_to', service_id=service_id, reply_to_email_id=replace) %}
{% else %}
{% set form_url = url_for('.service_add_email_reply_to', service_id=service_id) %}
@@ -50,7 +50,7 @@
safe_error_message=True,
hint='This should be a shared inbox managed by your team, not your own email address'
) }}
{% if not first_email_address and not replace %}
{% if not first_email_address and not existing_is_default %}
<div class="form-group">
{{ checkbox(form.is_default) }}
</div>