From 70e3b07308ab94541174ab4d8a41d291e89fa6b3 Mon Sep 17 00:00:00 2001 From: Alexey Bezhan Date: Wed, 17 Jan 2018 16:38:07 +0000 Subject: [PATCH 1/2] Disable Deskpro letters still sending alert in preview and staging Since preview and staging environments don't have a full DVLA integration they're likely to contain letter notifications in a 'sending' state. To avoid spamming Deskpro we skip the check unless we're in a production or test environment. --- app/celery/scheduled_tasks.py | 21 ++++++++++++++------- tests/app/celery/test_scheduled_tasks.py | 6 +++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index 6ebaec87a..471cef23d 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -337,6 +337,7 @@ def delete_dvla_response_files_older_than_seven_days(): @notify_celery.task(name="raise-alert-if-letter-notifications-still-sending") @statsd(namespace="tasks") def raise_alert_if_letter_notifications_still_sending(): + today = datetime.utcnow().date() # Do nothing on the weekend @@ -356,15 +357,21 @@ def raise_alert_if_letter_notifications_still_sending(): ).count() if still_sending: - deskpro_client.create_ticket( - subject="Letters still sending", - message="There are {} letters in the 'sending' state from {}".format( - still_sending, - (today - timedelta(days=offset_days)).strftime('%A %d %B') - ), - ticket_type="alert" + message = "There are {} letters in the 'sending' state from {}".format( + still_sending, + (today - timedelta(days=offset_days)).strftime('%A %d %B') ) + # Only send alerts in production + if current_app.config['NOTIFY_ENVIRONMENT'] in ['production', 'test']: + deskpro_client.create_ticket( + subject="[{}] Letters still sending".format(current_app.config['NOTIFY_ENVIRONMENT']), + message=message, + ticket_type="alert" + ) + else: + current_app.logger.info(message) + @notify_celery.task(name="populate_monthly_billing") @statsd(namespace="tasks") diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index 0eb25f2a9..466be14a0 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -642,7 +642,7 @@ def test_alert_if_letter_notifications_still_sending(sample_letter_template, moc raise_alert_if_letter_notifications_still_sending() mock_celery.assert_called_once_with( - subject="Letters still sending", + subject="[test] Letters still sending", message="There are 1 letters in the 'sending' state from Tuesday 16 January", ticket_type='alert' ) @@ -660,7 +660,7 @@ def test_alert_if_letter_notifications_still_sending_only_alerts_sending(sample_ raise_alert_if_letter_notifications_still_sending() mock_celery.assert_called_once_with( - subject="Letters still sending", + subject="[test] Letters still sending", message="There are 1 letters in the 'sending' state from Tuesday 16 January", ticket_type='alert' ) @@ -703,7 +703,7 @@ def test_monday_alert_if_letter_notifications_still_sending_reports_friday_lette raise_alert_if_letter_notifications_still_sending() mock_celery.assert_called_once_with( - subject="Letters still sending", + subject="[test] Letters still sending", message="There are 2 letters in the 'sending' state from Friday 12 January", ticket_type='alert' ) From d70fc958f69c510da8663cd68c5c3e3f06a09f45 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 17 Jan 2018 16:09:03 +0000 Subject: [PATCH 2/2] Backfill redaction for pre-seeded templates Will specifically affect the email auth template, which was seeded without a matching row in the `template_redacted` table. Effectively re-runs c24edcf38825c694fdc14e5a8e3888f136650506 > add historical redaction data > > every current template gets a row in the template_redacted table - > this inserts one for any template that doesn't already have a row, > with redact set to false, the user set to NOTIFY_USER since it was > just a script, and the updated_at set to the time the script is run --- .../versions/0159_add_historical_redact.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 migrations/versions/0159_add_historical_redact.py diff --git a/migrations/versions/0159_add_historical_redact.py b/migrations/versions/0159_add_historical_redact.py new file mode 100644 index 000000000..16ea747ab --- /dev/null +++ b/migrations/versions/0159_add_historical_redact.py @@ -0,0 +1,42 @@ +"""empty message + +Revision ID: 0159_add_historical_redact +Revises: 0158_remove_rate_limit_default +Create Date: 2017-01-17 15:00:00.000000 + +""" + +# revision identifiers, used by Alembic. +revision = '0159_add_historical_redact' +down_revision = '0158_remove_rate_limit_default' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql +from flask import current_app + +def upgrade(): + op.execute( + """ + INSERT INTO template_redacted + ( + template_id, + redact_personalisation, + updated_at, + updated_by_id + ) + SELECT + templates.id, + false, + now(), + '{notify_user}' + FROM + templates + LEFT JOIN template_redacted on template_redacted.template_id = templates.id + WHERE template_redacted.template_id IS NULL + """.format(notify_user=current_app.config['NOTIFY_USER_ID']) + ) + + +def downgrade(): + pass