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

Changed validation when creating email #1827

Merged
merged 5 commits into from
May 1, 2024
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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ format:
flake8 ./app ./tests
isort --check-only ./app ./tests
mypy ./
npx prettier --write app/assets/javascripts app/assets/stylesheets
npx prettier --write app/assets/javascripts app/assets/stylesheets

.PHONY: tailwind
tailwind:
amazingphilippe marked this conversation as resolved.
Show resolved Hide resolved
npm run tailwind
2 changes: 1 addition & 1 deletion app/assets/stylesheets/index.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion app/main/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def validate_email_from(form, field):
if email_safe(field.data) != field.data.lower():
# fix their data instead of only warning them
field.data = email_safe(field.data)
raise ValidationError(_l("Make sure we formatted your email address correctly."))
if len(field.data) > 64:
raise ValidationError(_l("This cannot exceed 64 characters in length"))
# this filler is used because service id is not available when validating a new service to be created
Expand Down
5 changes: 5 additions & 0 deletions app/templates/components/confirmation-preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% macro confirmation_preview() %}
<div class="bg-gray-100 border-l-2 border-gray-400 p-gutterHalf space-y-gutterHalf">
{{ caller() }}
</div>
jzbahrai marked this conversation as resolved.
Show resolved Hide resolved
{% endmacro %}
16 changes: 12 additions & 4 deletions app/templates/partials/add-service/step-create-service.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% from "components/confirmation-preview.html" import confirmation_preview %}

<p>{{ _("You can change the name and email address later in Settings.") }}</p>
<p>{{ _("When GC Notify sends your emails, the ‘From’ field shows the name followed by the email address.") }}</p>

Expand Down Expand Up @@ -26,10 +28,16 @@ <h2 class="heading-medium">{{ _("Email address") }}</h2>

{{ textbox(form.email_from, hint=hint_txt, suffix=suffix_txt, width='1-2', maxlength=64) }}

<span id="preview" style="display: none">
{{ _("Your service’s email address will be:") }}
<b><span id="fixed-email-address"></span>@notification.canada.ca</b>
</span>
<div id="preview" class="focus:outline-yellow" style="display: none" tabindex="0" >
{% call confirmation_preview() %}
<p class="m-0">{{_("Make sure we have formatted your email address correctly.")}}</p>
<p class="m-0">
{{_("Your service’s email address will be: ")}}
<b><span id='fixed-email-address'></span>@notification.canada.ca</b>
</p>
{% endcall %}
jzbahrai marked this conversation as resolved.
Show resolved Hide resolved
</div>

</p>
<p>{{ _("This email address cannot receive replies. In Settings, you can enter a different email for replies. Currently your service is set to prevent replies.") }}</p>

Expand Down
3 changes: 2 additions & 1 deletion app/translations/csv/fr.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@
"Enter bilingual service name","Saisissez le nom bilingue du service"
"Maximum 64 characters with no spaces. Characters can include letters, numbers, dots, dashes, and underscores.","64 caractères au maximum, sans espaces. Les caractères peuvent comprendre des lettres, des chiffres, des points, des tirets et des traits de soulignement."
"This email address cannot receive replies. In Settings, you can enter a different email for replies. Currently your service is set to prevent replies.","Cette adresse courriel ne peut pas recevoir de réponses. Vous pouvez saisir une adresse courriel différente pour les réponses via les paramètres. Votre service est actuellement configuré pour empêcher les réponses."
"Your service’s email address will be:","L’adresse courriel de votre service sera&nbsp;:"
"Your service’s email address will be: ","L’adresse courriel de votre service sera&nbsp;: "
"You can change the order later in Settings.","Vous pourrez changer l’ordre ultérieurement via les paramètres."
"The email address always ends with ‘@notification.canada.ca’.","L’adresse courriel se termine toujours par « @notification.canada.ca »."
"Enter the part before ‘@notification.canada.ca’","Saisissez la partie précédant « @notification.canada.ca »."
Expand Down Expand Up @@ -1858,3 +1858,4 @@
"Select a priority queue","Sélectionnez une file de sécurité"
"Select a folder","Sélectionnez un dossier"
"Select template","Sélectionner un gabarit"
"Make sure we have formatted your email address correctly.","Assurez-vous que nous avons correctement formaté votre courriel."
22 changes: 18 additions & 4 deletions tests/app/main/views/test_add_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,29 @@ def test_wizard_flow_with_step_2_should_correct_invalid_email_from(
):
with client_request.session_transaction() as session:
session["add_service_form"] = dict(default_branding=FieldWithLanguageOptions.ENGLISH_OPTION_VALUE)
page = client_request.post(
client_request.post(
"main.add_service",
_data={"name": "testing the post", "email_from": "[Health Canada! - Sante&&Canada]"},
current_step="choose_service_name",
_expected_status=200,
_expected_status=302,
_expected_redirect=url_for(
"main.service_dashboard",
service_id=101,
),
)

# ensure email has spaces and special characters removed
assert page.find(id="email_from")["value"] == "health.canada-santecanada"
assert mock_create_service.called is True
mock_create_service.assert_called_once_with(
service_name="testing the post",
organisation_type="central",
message_limit=50,
sms_daily_limit=50,
restricted=True,
user_id="6ce466d0-fd6a-11e5-82f5-e0accb9d11a6",
email_from="health.canada-santecanada",
default_branding_is_french=False,
organisation_notes=None,
)
jzbahrai marked this conversation as resolved.
Show resolved Hide resolved


# TODO: remove this test after the CRM integration is released
Expand Down
Loading