Commit Graph

8781 Commits

Author SHA1 Message Date
Ben Thorner
015152bab2 Add boilerplate for sending SMS via Reach
This works in conjunction with the new SMS provider stub [^1].

Local testing:

- Run the migrations to add Reach as an inactive provider.
- Activate the Reach provider locally and deactivate the others.

      update provider_details set priority = 100, active = false where notification_type = 'sms';
      update provider_details set active = true where identifier = 'reach';

- Tweak your local environment to point at the SMS stub.

      export REACH_URL="http://host.docker.internal:6300/reach"

- Start / restart Celery to pick up the config change.
- Send a SMS via the Admin app and see the stub log it.
- Reset your environment so you can send normal SMS.

      update provider_details set active = true where notification_type = 'sms';
      update provider_details set active = false where identifier = 'reach';

[^1]: https://github.com/alphagov/notifications-sms-provider-stub/pull/10
2022-03-30 13:38:46 +01:00
Ben Thorner
27ddc4501e DRY-up overriding shortcode with sender
This avoids duplicating the logic when we add a new provider.
2022-03-30 13:37:01 +01:00
Ben Thorner
3b082477f0 DRY-up logging and metrics for sending SMS
This avoids duplicating it as we add a new provider and means we
can test it all in one place (although it wasn't tested before).

I'm not sure why the previous code did "super(..)__init__" in a
non-init function - it's a bit late! - so I've just replaced it
with a call to the new "init_app" function in the parent class.
2022-03-30 13:37:00 +01:00
Ben Thorner
84578e8a1d Make provider tests agnostic to actual data
The provider tests are coupled to actual data in the DB, but we
shouldn't have to overhaul the tests when this changes.

Assuming we don't delete old providers, just testing a subset of
the fixture data should give us enough confidence in the code.
2022-03-30 13:36:59 +01:00
Ben Thorner
22e055f4d1 DRY-up recording the outcome of SMS sending
This reduces the code to copy when we add a new provider. I don't
think we need to log the URL or status code each time:

- The URL is always the same.
- A "200" status code is implicit in "success".
- Other status codes will be reported as exceptions.

Removing these specific elements means "record_outcome" is generic
and can be de-duplicated in the base class.
2022-03-30 13:36:58 +01:00
Ben Thorner
35f710bdf3 Remove redundant "multi" parameter for MMG client
This is never overridden and can't be used in practie because all
SMS clients have to use the same interface. Removing it will make
it possible to DRY-up some of the code in this method.
2022-03-30 13:36:57 +01:00
Ben Thorner
3988a6cd07 Include exception info in SMS warning log
This makes it easier to debug failures when adding a new provider.
2022-03-30 13:36:56 +01:00
Ben Thorner
e6e16a81d0 Simplify getting name of email / sms providers
Previously we used a combination of "provider.name" and "get_name()"
which was confusing. Using a non-property function also gave me the
impression that the name was more dynamic than it actually is.
2022-03-30 13:36:55 +01:00
Ben Thorner
eef4868651 Merge pull request #3492 from alphagov/reach-basics-181665654
Add boilerplate for Reach SMS callbacks
2022-03-29 16:32:12 +01:00
Ben Thorner
13245f74d4 Merge pull request #3491 from alphagov/fix-broadcast-perm-command
Fix missing permission for dev broadcast users
2022-03-28 14:03:54 +01:00
Ben Thorner
b439fd0718 Add boilerplate for Reach SMS callbacks
This is enough to update a notification in DB:

1. First create a notification in the UI and sent it.

2. Then reset its attributes to pretend it's for Reach.

    update notifications set
      sent_at = null,
      sent_by = null,
      notification_status='sending'
    where id='some-uuid';

3. Change "notification_id" to "<some-uuid>" in the code.

4. Call the boilerplate endpoint for Reach callbacks.

    curl -X POST localhost:6011/notifications/sms/reach

Interestingly there's no foreign key constraint on "sent_by" in the
DB, so this just works: the notification is updated.
2022-03-24 16:56:33 +00:00
Ben Thorner
a962721915 Move SMS client response tests to match their app/
This makes them easier to find and removes ambiguity with other
files related to "processing" in the app.
2022-03-24 16:47:30 +00:00
Ben Thorner
5bab84144a Split and rename tests for SMS / letter callbacks
These were hard to find by searching as the filename doesn't refer
to SMS or letters. Ideally our tests should be organised to reflect
the structure of files in app/, so this does that.
2022-03-24 16:47:29 +00:00
Ben Thorner
32434999f5 Remove redundant header in provider test data
X-Forwarded-For isn't used for anything since [^1].

[^1]: https://github.com/alphagov/notifications-api/pull/1315
2022-03-24 16:47:28 +00:00
Ben Thorner
0b6f1d818b Remove redundant debug logs for providers
We don't log at this level and can always add them in manually if
we need to debug something locally.
2022-03-24 16:47:27 +00:00
Ben Thorner
3b519a2188 Fix missing permission for dev broadcast users
This is normally added automatically [^1].

[^1]: b145a29935/app/dao/broadcast_service_dao.py (L69)
2022-03-24 12:36:23 +00:00
Ben Thorner
b145a29935 Merge pull request #3488 from alphagov/fix-provider-adjustment-bug-181574489
Fix SMS priority adjustment if only 1 provider
2022-03-22 16:21:53 +00:00
Rebecca Law
f5f860a34b Merge pull request #3487 from alphagov/set-free-allowance-to-zero
Set free allowance to zero if previous year is zero in command to set free allowance for a year
2022-03-22 10:45:45 +00:00
Rebecca Law
1e473fd216 Unit test for command 2022-03-22 10:33:05 +00:00
Ben Thorner
f64e60d941 Merge pull request #3489 from alphagov/log-dup-receipt-service
Log Service ID when we get a duplicate receipt
2022-03-22 10:30:13 +00:00
Rebecca Law
926eb5b48f Update app.commands.populate_annual_billing_with_defaults so that if the
service has zero free allowance in the previous year, set this year to
zero as well.
2022-03-22 10:02:32 +00:00
Ben Thorner
7bffe9ee50 Log Service ID when we get a duplicate receipt
This will make it easier to group these logs if a service complains
about the issue.
2022-03-21 15:43:08 +00:00
Ben Thorner
b4d4133b1f Fix SMS priority adjustment if only 1 provider
Fixes:

    >       reduced_provider = providers[identifier]
    E       KeyError: 'firetext'

Note that the mock return value in the other test was wrong [^1].

[^1]: bff97f0bbe/app/dao/provider_details_dao.py (L73)
2022-03-17 17:09:13 +00:00
Ben Thorner
bff97f0bbe Merge pull request #3485 from alphagov/mac-m1-dev-fixes-181498273
Replace pycurl guidance with psycopg2
2022-03-17 11:31:14 +00:00
Ben Thorner
c0f60a5c21 Replace pycurl guidance with psycopg2
Since we moved to Dockerised Celery the pycurl guidance should no
longer be necessary and doesn't work on newer Mac M1 machines.

This also adds new guidance for psycopg2, which will hopefully be
temporary (see issue comment).
2022-03-15 15:58:18 +00:00
Rebecca Law
4b6de79dae Merge pull request #3484 from alphagov/update-free-allowance-2022
Free allowance rates for 2022
2022-03-15 14:00:09 +00:00
Rebecca Law
8402e7c97b Free allowance rates for 2022
Update the map for determine the free allowance (aka: free sms fragments) for services.
2022-03-15 12:35:39 +00:00
Ben Thorner
6cd3650b3f Merge pull request #3482 from alphagov/fix-docker-host-181498273
Fix letter functional tests to work in Docker
2022-03-15 12:32:54 +00:00
Leo Hemsted
2fbe9e85ac Merge pull request #3479 from alphagov/auto-retry-stuck-av-letters
automatically retry letters stuck in pending-virus-scan
2022-03-15 11:43:42 +00:00
Leo Hemsted
9e8df8b623 remove "letters stuck pending av" runbook
there's not anything we know we need to do now that we resolve stuck
letters automatically. Letters couuld still get into this state, so it's
worth alerting us. However, we don't have anything concrete that we know
how to fix these letters, so we should just remove the runbook entirely.
2022-03-10 14:10:01 +00:00
Katie Smith
907e270b2e Merge pull request #3483 from alphagov/pyup-scheduled-update-2022-03-09
Scheduled weekly dependency update for week 10
2022-03-10 08:27:06 +00:00
Katie Smith
d32ebe1147 Update werkzeug from 2.0.2 to 2.0.3 2022-03-09 17:22:11 +00:00
Katie Smith
d93f1e3e95 Update beautifulsoup4 from 4.9.3 to 4.10.0 2022-03-09 17:19:49 +00:00
Katie Smith
5fd014eb14 Update sqlalchemy from 1.4.10 to 1.4.32 2022-03-09 16:52:44 +00:00
Katie Smith
97c4ccfdce Update pyjwt from 2.0.1 to 2.3.0 2022-03-09 16:34:42 +00:00
Katie Smith
7fabc9d0c5 Bump test dependencies 2022-03-09 16:21:58 +00:00
Rebecca Law
cd78361be1 Merge pull request #3477 from alphagov/volume-stat-report
Report for total notifications sent per day for each channel.
2022-03-09 13:42:00 +00:00
Rebecca Law
29ebf0eb9a Move the casting the column as an int to the the endpoint, we need to
convert the Decimal data type to datatype json can work with.
2022-03-09 12:29:58 +00:00
Ben Thorner
3fab7a0ca9 Fix letter functional tests to work in Docker
Currently "test_send_letter_notification_via_api" fails at the final
stage in create-fake-letter-response-file [^1]:

        requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=6011): Max retries exceeded with url: /notifications/letter/dvla (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xffff95ffc460>: Failed to establish a new connection: [Errno 111] Connection refused'))

This only applies when running in Docker so the default should still
be "localhost" for the Flask app itself.

[^1]: 5093064533/app/celery/research_mode_tasks.py (L57)
2022-03-09 11:07:50 +00:00
David McDonald
5093064533 Merge pull request #3481 from alphagov/service-callback-timeout
Reduce timeout for service callback attempt to 5 seconds
2022-03-08 14:11:33 +00:00
Ben Thorner
8a8db654c9 Merge pull request #3480 from alphagov/benthorner-patch-1
Fix incorrect code block formatting in README
2022-03-08 14:09:07 +00:00
David McDonald
0d952b4d8c Reduce timeout for service callback attempt to 5 seconds
It is currently 60 seconds but we have had two incidents in the
past week where there is a connection error talking to a service
and the request takes up to 60 seconds before failing. When this
happens, if there are a few of these callbacks then all of them
will completely hog the service callback worker and build up a big
queue of all the other service callbacks.

5 seconds has been chosen as that is still a pretty decent length
time for a simple web request that should just be giving them a
little bit of information for them to store. 5 seconds should be a
sufficient enough reduction that we dramatically reduce this problem
for the moment.

Open to this number
being changed in the future based on how we see it perform.
2022-03-08 13:05:32 +00:00
Ben Thorner
ae41075151 Fix incorrect code block formatting in README 2022-03-08 12:42:14 +00:00
Leo Hemsted
00259893f1 automatically retry letters stuck in pending-virus-scan
Since sept 2019 we've had to log on to production around once every
twenty days to restart the virus scan task for a letter. Most of the
time this is just a case of making sure the file is in the scan bucket,
and then triggering the task. If the file isn't in the scan bucket we'd
need to do some more manual investigation to find out exactly where the
file got stuck, but I can only remember times when it's been in the scan
bucket.

So if the file is in the scan bucket, we can just check that with code
and kick the task off automatically.
2022-03-07 18:31:46 +00:00
Chris Hill-Scott
eb383004fb Merge pull request #3478 from alphagov/custom-base-url-register-email
Allow admin app to specify domain for registration email
2022-03-07 15:17:38 +00:00
Chris Hill-Scott
c2b6a9df80 Allow admin app to specify domain for registration email
This follows the pattern for invite emails where the admin app tells the
API which domain to use when generating the link.

This will starting working once the admin change is merged:
- [ ] TBC

It won’t break anything if it’s merged before the admin change.
2022-03-07 15:03:46 +00:00
Rebecca Law
466b7fa341 Report for total notifications sent per day for each channel.
Daily volumes report: total volumes across the platform aggregated by whole business day (bst_date)
Volumes by service report: total volumes per service aggregated by the date range given.

NB: start and end dates are inclusive
2022-03-07 10:44:49 +00:00
Katie Smith
520d621893 Merge pull request #3476 from alphagov/upgrade-some-dependencies
Upgrade some dependencies
2022-03-03 15:06:27 +00:00
Katie Smith
faec6083fa Update notifications-python-client from 6.0.2 to 6.3.0 2022-03-03 14:17:32 +00:00
Katie Smith
7943010bfb Update lxml from 4.7.1 to 4.8.0 2022-03-03 14:15:16 +00:00