Commit Graph

573 Commits

Author SHA1 Message Date
Pea Tyczynska
d36c4d8a78 Remove now unused methods that populated template usage redis cache 2019-01-15 14:38:45 +00:00
Pea Tyczynska
5ebeb9937a Avoid call to database to get template in persist_notifications 2019-01-14 17:53:06 +00:00
Pea Tyczynska
56bae2b077 Allow users to set postage per precompiled letter 2019-01-09 17:49:19 +00:00
Leo Hemsted
2355ee011f log more info when we receive multiple delivery callbacks for one notification
Previously, we logged a warning containing the notification reference
and new status. However it wasn't a great message - this new one
includes the notification id, the old status, the time difference and
more.

This separates out logs for callbacks for notifications we don't know
(error level) and duplicates (info level).
2019-01-03 17:08:16 +00:00
Pea Tyczynska
e6524af89c Choose postage when persisting a notification 2018-12-21 16:37:52 +00:00
Alexey Bezhan
462c8db4c3 Lower service rate limit log level to INFO
Services reaching rate limits are triggering our alerts and make it
hard to find actual exceptions in the logs.

As far as the API is concerned this is not an exceptional state,
so we shouldn't log it as such.
2018-11-27 15:50:51 +00:00
Katie Smith
ff06d120e8 Bump notifications-utils to 3.7.0
Bumped notifications-utils to 3.7.0. Version 3.7.0 includes the
`convert_utc_to_bst` and `convert_bst_to_utc` functions and the
`LETTER_PROCESSING_DEADLINE` constant, so these have been removed from
this repo and anywhere using these has now been updated to get these
from `notifications-utils`.

Also bumped pytest by a patch version to bring in a bug fix.
2018-11-26 12:53:39 +00:00
Rebecca Law
d0cbdce6c4 Update the error message when a service does not have permission to send a notification type. 2018-11-20 11:01:48 +00:00
Chris Hill-Scott
674cdbd265 Allow the admin app to send one-off letters
This commit modifies the code paths the admin app uses to send one off
emails and text messages to also accept letters.

This mostly worked already, the two changes were:
- making sure that one-off letters are processed by the correct task,
  from the correct queue
- one-off letters sent from a service in research mode don’t get put on
  a queue and go straight to `delivered` (because we don’t want to send
  them for real)
2018-10-31 16:48:43 +00:00
Rebecca Law
00f04c33c8 Some minor refactoring.
- Updated notifications_dao.update_notification_status_by_id with an optional parameter to set the sent_by, this will eliminate a separate update to notifcaitons.
- Added the callback url to the log message, that way we can see if it's the same url failing.
- Stop sending the status callbacks for PENDING status.
2018-10-24 11:24:53 +01:00
Rebecca Law
bb97a9038f Merge branch 'master' into reduce-updates-to-notification 2018-09-20 14:48:40 +01:00
Rebecca Law
b00308d122 Removed an update statement to notifications.
It's a small change, but we should remove any db operations that are not necessary.
2018-09-20 14:47:24 +01:00
Leo Hemsted
4dc3f829e3 give letter notifications the postage from their service 2018-09-19 17:23:17 +01:00
Katie Smith
a87be9b74a Use new value of SMS_CHAR_COUNT_LIMIT from utils
Admin, API and utils were all defining a value for SMS_CHAR_COUNT_LIMIT.
This value has been updated in notifications-utils to allow text
messages to be 4 fragments long and notifications-api now gets the value of
SMS_CHAR_COUNT_LIMIT from notifications-utils instead of defining it in
config.

Also updated some tests to check for the higher limit.
2018-08-16 16:34:34 +01:00
Pea Tyczynska
812f4d20dd Send complaints on to service callback APIs using an async task 2018-07-19 16:59:39 +01:00
Pea Tyczynska
86978c225a Filter 'get_service_callback_api_for_service' to only get status updates
Also rename it to 'get_service_delivery_status_callback_api_for_service'
2018-07-18 11:36:39 +01:00
Rebecca Law
2381850d05 Refactor - extract common code into a method. 2018-06-07 14:54:40 +01:00
Rebecca Law
56c6d5101c Add some useful information to the log.
Fix unit test to actually test the right thing
2018-06-07 12:30:04 +01:00
Rebecca Law
e353a058e0 We'd like to see what the bounce message is from SES.
If there is a bounce we update the email to failed.
However, there is more than one reason for the failed message. Adding this logging will give us more details about the failure message.
2018-06-07 10:36:04 +01:00
Rebecca Law
4966da8289 Fix to handle_complaints.
The json we were getting from SES was not quite as expected, the test data now reflects what we get.
New test added, fix a test that was passing regardless.
2018-06-06 10:37:31 +01:00
Rebecca Law
c5524a3fe9 [WIP] 2018-06-05 17:23:24 +01:00
Rebecca Law
7fa42c2cc5 When SES callback is for a complaint save that to the new complaints table.
When handling the complaint we don't want to throw an exception if the message is missing fields. Only log an exception if we are unable to tie a complaint to a notification.
2018-06-04 17:29:58 +01:00
Rebecca Law
1faba916b2 New complaints model to persist complaints from SES.
If a someone gets an email from one of our services and then complain about it (mark as spam or otherwise), we get a callback from SES.
The service needs to know about these complaints so they can remove that email from their mailing list.
2018-05-31 14:43:49 +01:00
Rebecca Law
23e6b57c26 Remove email from the log message 2018-05-30 16:45:18 +01:00
Rebecca Law
621c81a9d8 Small refactor to reduce complexity and satisfy codestyle.
This module could do with a look to check if we can simplify it. But at the moment we just want to record the complaint.
2018-05-30 16:25:49 +01:00
Rebecca Law
e82fa2c8d4 Added a way to handle complaint responses from SES.
At this point we are just logging the message so that we can confirm the contents of the SES message.

refer to: https://www.pivotaltracker.com/story/show/157969699
2018-05-30 16:16:36 +01:00
Leo Hemsted
8e73961f65 add new redis template usage per day key
We've run into issues with redis expiring keys while we try and write
to them - short lived redis TTLs aren't really sustainable for keys
where we mutate the state. Template usage is a hash contained in redis
where we increment a count keyed by template_id each time a message is
sent for that template. But if the key expires, hincrby (redis command
for incrementing a value in a hash) will re-create an empty hash.

This is no good, as we need the hash to be populated with the last
seven days worth of data, which we then increment further. We can't
tell whether the hincrby created the key, so a different approach
entirely was needed:

* New redis key: <service_id>-template-usage-<YYYY-MM-DD>. Note: This
  YYYY-MM-DD is BTC time so it lines up nicely with ft_billing table
* Incremented to from process_notification - if it doesn't exist yet,
  it'll be created then.
* Expiry set to 8 days every time it's incremented to.

Then, at read time, we'll just read the last eight days of keys from
Redis, and sum them up. This works because we're only ever incrementing
from that one place - never setting wholesale, never recreating the
data from scratch. So we know that if the data is in redis, then it is
good and accurate data.

One thing we *don't* know and *cannot* reason about is what no key in
redis means. It could be either of:

* This is the first message that the service has sent today.
* The key was deleted from redis for some reason.

Since we set the TTL to so long, we'll never be writing to a key that
previously expired. But if there is a redis (or operator) error and the
key is deleted, then we'll have bad data - after any data loss we'll
have to rebuild the data.
2018-04-03 16:12:54 +01:00
Ken Tsang
c272d023c4 Lowercase the client name when sent_by is empty 2018-03-22 16:12:33 +00:00
Ken Tsang
ffa093d8c7 Set sent_by if not set during sms provider callback
- refactored argument reference to provider_reference to make it clearer
2018-03-21 18:11:10 +00:00
Rebecca Law
c9477a7400 When a notification is timed out in the scheduled task that may happen because the notification has not been sent.
Which means the sent_at date for the notification could be empty causing the service callback to fail.

- Allow code to work if notification.sent_at or updated_at is None
- Update calls to send_delivery_status_to_service to send the data encrypted so that the task does not need to use the db.
2018-03-16 14:47:56 +00:00
Katie Smith
7f2e9f507e Delete functions which call the job statistics tasks
The JobStatistics table is going to be deleted. There are currently
3 tasks which use the JobStatistics model via the Statistics DAO, so we
need to make sure that these tasks aren't being used before they are
deleted in a separate PR.

This commit deletes:
* The `create_initial_notification_statistic_tasks` function which gets
used to call the `record_initial_job_statistics` task.
* The `create_outcome_notification_statistic_tasks` function which gets
used to call the `record_outcome_job_statistics` task.
* And the scheduling of the `timeout-job-statistics` scheduled task.
2018-03-07 09:23:29 +00:00
Rebecca Law
fa8cd780b0 Make the errors in the process_sms_client_reponse more obvious by changing variable name.
Added a missing test if mmg sends a CID (or reference) that is not a UUID.

NB: All client specific tests are in test_callbacks.
2018-02-12 12:06:43 +00:00
Rebecca Law
e68604a600 Merge branch 'master' into remove-failed-as-a-status 2018-02-09 10:58:25 +00:00
Rebecca Law
b2dfa59b1b We are not handling the case of an unknown status code sent by the SMS provider. This PR attempts to fix that.
- If the SMS client sends a status code that we do not recognize raise a ClientException and set the notification status to technical-failure
- Simplified the code in process_client_response, using a simple map.
2018-02-07 17:49:15 +00:00
Rebecca Law
dce79832ff As Notify matures we probably need less logging, especially to report happy path events.
This PR is a proposal to reduce the average messages we see for a single notification from about 7 messages to 2.

Messaging would change to something like this:
February 2nd 2018, 15:39:05.885	Full delivery response from Firetext for notification: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
{'status': ['0'], 'reference': ['8eda51d5-cd82-4569-bfc9-d5570cdf2126'], 'time': ['2018-02-02 15:39:01'], 'code': ['000']}
February 2nd 2018, 15:39:05.885	Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:57.727	SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to provider firetext at 2018-02-02 15:38:56.716814
February 2nd 2018, 15:38:56.727	Starting sending SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 to provider at 2018-02-02 15:38:56.408181
February 2nd 2018, 15:38:56.727	Firetext request for 8eda51d5-cd82-4569-bfc9-d5570cdf2126 finished in 0.30376038211397827
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to the priority-tasks queue for delivery

To somthing like this:
February 2nd 2018, 15:39:05.885	Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
2018-02-02 15:55:25 +00:00
Richard Chapman
eee572276f Removed the imports for statsd as the decorators are no longer being
used.
2018-01-26 09:39:11 +00:00
Richard Chapman
083bfb9ea5 Removed the performance testing statsd calls as they are no longer
needed for monitoring the performance of the v2 endpoints. They were put
in as a temporary measure whilst sustained performance testing was
taking place.
2018-01-26 09:08:45 +00:00
Ken Tsang
6a3c2734ca Update callback handling to process DVLA response files
- handle `RS.TXT` and `RSP.TXT` files
2018-01-23 08:59:01 +00:00
Chris Hill-Scott
01cf175cb2 Don’t respect the whitelist for one off sending
The whitelist was built to help developers and designers making
prototypes to do realistic usability testing of them, without having to
go through the whole go live process.

These users are sending messages using the API. The whitelist wasn’t
made available to users uploading spreadsheets. The users sending one
off messages are similar to those uploading spreadsheets, not those
using the API. Therefore they shouldn’t be able to use the whitelist to
expand the range of recipients they can send to.

Passing the argument through three methods doesn’t feel that great, but
can’t think of a better way without major refactoring…
2018-01-22 11:42:37 +00:00
venusbb
a90596fa1b Merge branch 'master' of https://github.com/alphagov/notifications-api into raise-alert-when-no-ack-file 2018-01-16 16:20:40 +00:00
Katie Smith
7b4abd076b Add validation to check that sms recipient is not None
Previously, if the SMS recipient was None there would be a 500 error
with no message displayed to the user. We now check if the recipient is
None and raise a BadRequestError if this is the case.
2018-01-15 09:20:46 +00:00
venusbb
a016b3f8d6 Added a new sns callback for testing old dvla response file type.
Merge branch 'raise-alert-when-no-ack-file' of https://github.com/alphagov/notifications-api into raise-alert-when-no-ack-file
2018-01-12 16:11:06 +00:00
venusbb
24b785e7e0 Added process for dvla acknowledgement file
Daily schedule task to check ack file against zip file lists
if we haven't receive ack for a zip file, raise a 500 exception
2018-01-12 15:44:00 +00:00
venusbb
e1d150a882 Added process for dvla acknowledgement file
Daily schedule task to check ack file against zip file lists
if we haven't receive ack for a zip file, raise a 500 exception
2018-01-12 15:10:42 +00:00
Rebecca Law
9c4e43bfac Some pseudo code and notes of how to implement a check for the letter acknowledgement file. 2018-01-11 16:37:39 +00:00
Katie Smith
b07db16cd1 Get rate limit from service.rate_limit column (not config)
PR #1550 added the rate_limit column to the Service table.

This PR removes the rate limits from the config and uses rate_limit from
the Service model instead. Rate limits are still separated into 'team',
'normal' and 'test', but these values are the same for a service.

Pivotal story https://www.pivotaltracker.com/story/show/153992529
2018-01-11 10:28:11 +00:00
Rebecca Law
a052020f84 - simplify if statement
- use the template.get_reply_to_text() in send_notification, it's already using the right thing.
2018-01-08 16:54:19 +00:00
venusbb
a35b04f5e7 Enable MMG inbound blocking 2017-12-19 15:00:51 +00:00
Alexey Bezhan
509441f1d9 Add validators for service_letter_contact_id and reply_to
Validators check that service_letter_contact_id belongs to the
same service as the notification/template.

Generic reply_to validator calls the correct function for the given
type (for either notification or template). It can be used by the
template API endpoints to verify that given reply_to ID has the same
service_id as the template itself.

The original approach was to create a DB foreign key constraint,
but this caused issues with the `version_class` decorator saving
related Service objects without creating a history record.
2017-12-19 10:23:24 +00:00
venusbb
ab66f5c0ac Change MMG username to look at env variable 2017-12-15 12:19:58 +00:00