Merge pull request #949 from GSA/notify-admin-901

Create UI changes to let people know of considerations when using Non-ISO character sets
This commit is contained in:
Carlo Costino
2023-12-04 13:28:53 -05:00
committed by GitHub
3 changed files with 27 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ from functools import partial
from flask import abort, flash, jsonify, redirect, render_template, request, url_for
from flask_login import current_user
from markupsafe import Markup
from notifications_python_client.errors import HTTPError
from notifications_utils import SMS_CHAR_COUNT_LIMIT
@@ -679,8 +680,23 @@ def count_content_length(service_id, template_type):
)
def _is_latin1(s):
return bool(s.encode(encoding="latin-1", errors="strict"))
def _get_content_count_error_and_message_for_template(template):
url = "https://en.wikipedia.org/wiki/ISO/IEC_8859-1"
if template.template_type == "sms":
s1 = f"<html><body>Use of characters outside the <a href='{url}'>IEC_8859-1</a> character set may increase "
s2 = "the message fragment count, resulting in additional charges, and these IEC_8859-1 "
s3 = "characters may not display properly on some older mobile devices.</body></html>"
warning = ""
try:
_is_latin1(template.content)
except UnicodeEncodeError:
warning = f"{s1}{s2}{s3}"
if template.is_message_too_long():
return True, (
f"You have "
@@ -689,11 +705,16 @@ def _get_content_count_error_and_message_for_template(template):
)
if template.placeholders:
return False, (
f"Will be charged as {message_count(template.fragment_count, template.template_type)} "
f"(not including personalization)"
Markup(
f"Will be charged as {message_count(template.fragment_count, template.template_type)} "
f"(not including personalization). {warning}"
)
)
return False, (
f"Will be charged as {message_count(template.fragment_count, template.template_type)} "
# Markup marks html contents safe so that they render properly. Don't use it if there is user input.
Markup(
f"Will be charged as {message_count(template.fragment_count, template.template_type)}. {warning} "
)
)

View File

@@ -50,7 +50,7 @@
</div>
<div class="grid-row">
<div class="grid-col-12">
<div class="template-content-count">
<div class="template-content-count" bg-color="red">
<div data-module="update-status" data-target="template_content"
data-updates-url="{{ url_for('.count_content_length', service_id=current_service.id, template_type='sms') }}"
aria-live="polite">
@@ -69,7 +69,7 @@
</p>
</div>
</div>
<div class="tablet:grid-col-9 mobile-lg:grid-col-12">
<h2 id="help" class="font-body-xl margin-top-2">How to customize your message</h2>
<div class="usa-accordion usa-accordion--bordered usa-accordion--multiselectable maxw-mobile-lg" data-allow-multiple>

View File

@@ -2112,7 +2112,7 @@ def test_content_count_json_endpoint(
html = json.loads(response.get_data(as_text=True))["html"]
snippet = BeautifulSoup(html, "html.parser").select_one("span")
assert normalize_spaces(snippet.text) == expected_message
assert expected_message in normalize_spaces(snippet.text)
if snippet.has_attr("class"):
assert snippet["class"] == [expected_class]