-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Email the "contact us" form data instead of sending to Freshdesk for …
…sensitive services (#2416) This PR does the following: - adds a check when form data is submitted to our "contact us" form (this could be a go live request, branding request, help request, etc.). If the user submitting the form is logged in and belongs to at least one sensitive service, then we do not send their form data to Freshdesk, we email it to an inbox - adds a feature flag (FF_PT_SERVICE_SKIP_FRESHDESK) to switch this feature on and off - adds a db migration to create a new template for this email, to make it more obvious why the data was sent to email
- Loading branch information
Showing
6 changed files
with
222 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,6 +333,7 @@ class Config(object): | |
REACHED_DAILY_SMS_LIMIT_TEMPLATE_ID = "a646e614-c527-4f94-a955-ed7185d577f4" | ||
DAILY_SMS_LIMIT_UPDATED_TEMPLATE_ID = "6ec12dd0-680a-4073-8d58-91d17cc8442f" | ||
CONTACT_FORM_DIRECT_EMAIL_TEMPLATE_ID = "b04beb4a-8408-4280-9a5c-6a046b6f7704" | ||
CONTACT_FORM_SENSITIVE_SERVICE_EMAIL_TEMPLATE_ID = "4bf8c15b-7393-463f-b6fe-e3fd1e99a03d" | ||
NEAR_DAILY_EMAIL_LIMIT_TEMPLATE_ID = "9aa60ad7-2d7f-46f0-8cbe-2bac3d4d77d8" | ||
REACHED_DAILY_EMAIL_LIMIT_TEMPLATE_ID = "ee036547-e51b-49f1-862b-10ea982cfceb" | ||
DAILY_EMAIL_LIMIT_UPDATED_TEMPLATE_ID = "97dade64-ea8d-460f-8a34-900b74ee5eb0" | ||
|
@@ -559,6 +560,7 @@ class Config(object): | |
AWS_SEND_SMS_BOTO_CALL_LATENCY = os.getenv("AWS_SEND_SMS_BOTO_CALL_LATENCY", 0.06) # average delay in production | ||
|
||
CONTACT_FORM_EMAIL_ADDRESS = os.getenv("CONTACT_FORM_EMAIL_ADDRESS", "[email protected]") | ||
SENSITIVE_SERVICE_EMAIL = os.getenv("SENSITIVE_SERVICE_EMAIL", "[email protected]") | ||
|
||
FROM_NUMBER = "development" | ||
|
||
|
@@ -635,6 +637,7 @@ class Config(object): | |
FF_CLOUDWATCH_METRICS_ENABLED = env.bool("FF_CLOUDWATCH_METRICS_ENABLED", False) | ||
FF_SALESFORCE_CONTACT = env.bool("FF_SALESFORCE_CONTACT", False) | ||
FF_ANNUAL_LIMIT = env.bool("FF_ANNUAL_LIMIT", False) | ||
FF_PT_SERVICE_SKIP_FRESHDESK = env.bool("FF_PT_SERVICE_SKIP_FRESHDESK", False) | ||
|
||
# SRE Tools auth keys | ||
SRE_USER_NAME = "SRE_CLIENT_USER" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
""" | ||
Revision ID: 0472_add_direct_email_2 | ||
Revises: 0471_edit_limit_emails2 | ||
Create Date: 2025-01-13 00:00:00 | ||
""" | ||
from datetime import datetime | ||
|
||
from alembic import op | ||
from flask import current_app | ||
|
||
revision = "0472_add_direct_email_2" | ||
down_revision = "0471_edit_limit_emails2" | ||
|
||
contact_us_template_id = current_app.config["CONTACT_FORM_SENSITIVE_SERVICE_EMAIL_TEMPLATE_ID"] | ||
template_ids = [contact_us_template_id] | ||
|
||
|
||
def upgrade(): | ||
template_insert = """ | ||
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, | ||
created_by_id, version, process_type, hidden) | ||
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false) | ||
""" | ||
template_history_insert = """ | ||
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, | ||
created_by_id, version, process_type, hidden) | ||
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false) | ||
""" | ||
|
||
contact_us_content = "\n".join( | ||
[ | ||
"Skipping Freshdesk: The user submitting the Contact Us form belongs to a sensitive Service. Contact us form data:", | ||
"((contact_us_content))", | ||
"", | ||
"___", | ||
"", | ||
"[FR] Skipping Freshdesk: The user submitting the Contact Us form belongs to a sensitive Service. Contact us form data:", | ||
"", | ||
"((contact_us_content))", | ||
] | ||
) | ||
|
||
templates = [ | ||
{ | ||
"id": contact_us_template_id, | ||
"name": "Contact form direct email - sensitive service", | ||
"subject": "Notify Contact us form for sensitive service", | ||
"content": contact_us_content, | ||
}, | ||
] | ||
|
||
for template in templates: | ||
op.execute( | ||
template_insert.format( | ||
template["id"], | ||
template["name"], | ||
"email", | ||
datetime.utcnow(), | ||
template["content"], | ||
current_app.config["NOTIFY_SERVICE_ID"], | ||
template["subject"], | ||
current_app.config["NOTIFY_USER_ID"], | ||
"priority", | ||
) | ||
) | ||
|
||
op.execute( | ||
template_history_insert.format( | ||
template["id"], | ||
template["name"], | ||
"email", | ||
datetime.utcnow(), | ||
template["content"], | ||
current_app.config["NOTIFY_SERVICE_ID"], | ||
template["subject"], | ||
current_app.config["NOTIFY_USER_ID"], | ||
"priority", | ||
) | ||
) | ||
|
||
|
||
def downgrade(): | ||
for template_id in template_ids: | ||
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(template_id)) | ||
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(template_id)) | ||
op.execute("DELETE FROM template_redacted WHERE template_id = '{}'".format(template_id)) | ||
op.execute("DELETE FROM templates_history WHERE id = '{}'".format(template_id)) | ||
op.execute("DELETE FROM templates WHERE id = '{}'".format(template_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,7 +326,40 @@ def test_email_freshdesk_ticket(self, mocker, notify_api: Flask, contact_form_em | |
with set_config_values(notify_api, {"CONTACT_FORM_EMAIL_ADDRESS": "[email protected]"}): | ||
with notify_api.app_context(): | ||
freshdesk_object = freshdesk.Freshdesk(ContactRequest(email_address="[email protected]")) | ||
content = {"data": "data"} | ||
freshdesk_object.email_freshdesk_ticket(content) | ||
freshdesk_object.email_freshdesk_ticket_freshdesk_down() | ||
mock_persist_notification.assert_called_once() | ||
mock_send_notification_to_queue.assert_called_once() | ||
|
||
|
||
class TestEmailFreshdeskSensitiveService: | ||
def test_email_freshdesk_ticket_pt_service_success(self, mocker, notify_api): | ||
"""Test successful sending of sensitive service email""" | ||
mock_email_ticket = mocker.patch.object(freshdesk.Freshdesk, "email_freshdesk_ticket") | ||
|
||
with set_config_values( | ||
notify_api, | ||
{ | ||
"SENSITIVE_SERVICE_EMAIL": "[email protected]", | ||
"CONTACT_FORM_SENSITIVE_SERVICE_EMAIL_TEMPLATE_ID": "template-123", | ||
}, | ||
): | ||
with notify_api.app_context(): | ||
freshdesk_client = freshdesk.Freshdesk(ContactRequest(email_address="[email protected]")) | ||
freshdesk_client.email_freshdesk_ticket_pt_service() | ||
|
||
mock_email_ticket.assert_called_once_with("[email protected]", "template-123") | ||
|
||
def test_email_freshdesk_ticket_pt_service_no_email(self, mocker, notify_api): | ||
"""Test handling when sensitive service email not configured""" | ||
mock_email_ticket = mocker.patch.object(freshdesk.Freshdesk, "email_freshdesk_ticket") | ||
mock_logger = mocker.patch("app.clients.freshdesk.current_app.logger.error") | ||
|
||
with set_config_values( | ||
notify_api, {"SENSITIVE_SERVICE_EMAIL": None, "CONTACT_FORM_SENSITIVE_SERVICE_EMAIL_TEMPLATE_ID": "template-123"} | ||
): | ||
with notify_api.app_context(): | ||
freshdesk_client = freshdesk.Freshdesk(ContactRequest(email_address="[email protected]")) | ||
freshdesk_client.email_freshdesk_ticket_pt_service() | ||
|
||
mock_logger.assert_called_once_with("SENSITIVE_SERVICE_EMAIL not set") | ||
mock_email_ticket.assert_called_once_with(None, "template-123") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters