Commit Graph

3246 Commits

Author SHA1 Message Date
Katie Smith
3d01276ce2 Log exception and set precompiled letter to tech-failure if S3 errors
The `process_virus_scan_passed` task now catches S3 errors - if these
occur, it logs an exception and puts the letter in a `technical-failure`
state. We don't retry the task, because the most common reason for
failure would be the letter not being in the expected S3 bucket, in
which case retrying would make no difference.
2019-06-18 10:58:58 +01:00
Chris Hill-Scott
0955403a3b Slim down the /organisations response
At the moment this response returns a list of service IDs for hundreds
of organisations.

The admin app doesn’t use this information, but having to wait for it to
be serialized and sent across the network slows it down all the same.
2019-06-18 10:48:41 +01:00
Chris Hill-Scott
4dd245ca87 Remove deprecated fields from orgs and services
Once the admin app has started using the new fields returned in
https://github.com/alphagov/notifications-api/pull/2539 these fields
won’t be needed any more.
2019-06-18 10:48:41 +01:00
Chris Hill-Scott
8977f5193e Add columns for on whose behalf agreement signed
This is changing because we’re going to introduce accepting contracts
and MoUs online.

Previously
---
We had one column for who signed the agreement, which is foreign keyed
to the user table. This is still relevant, because there will always be
a user who is clicking the button.

Now
---
We add two new fields for the name and email address of the person on
whose behalf the agreement is being accepted. This person:
- is different from the one signing the agreement
- won’t necessarily have a Notify account
2019-06-18 10:41:22 +01:00
Chris Hill-Scott
3cde623ce2 Merge pull request #2539 from alphagov/optimise-orgs-services-for-user
Return all required information about a user’s organisations and services
2019-06-18 10:28:20 +01:00
Chris Hill-Scott
d974ab3b86 Return count of live services on organisations too
This makes it consistent, so the admin app can always rely on that
property being available.
2019-06-12 15:24:11 +01:00
Chris Hill-Scott
b6fdb269e4 Return all required org and services info for user
The admin app now needs to know a few extra things about orgs and
services in order to list them. At the moment it does this by making
multiple API calls.

This commit adds extra fields to the existing response. Once the admin
app is using this fields we’ll be able to remove:
- `reponse['services_without_organisations']`
- `reponse['organisations']['services']`
2019-06-12 15:24:11 +01:00
Rebecca Law
1f9aade749 - Adding test where post_notification can't send to a member outside of the team or whitelist.
- Updating some tests to be pytest4 compliant.
2019-06-11 16:45:35 +01:00
Leo Hemsted
5045590d75 allow you to pass in date to send perf stats
make it easier to replay sending data for a day if it failed the first
time round
2019-06-11 13:57:17 +01:00
Rebecca Law
c8196b0631 Merge pull request #2529 from alphagov/add-expiry-date-to-constraint
Allow api_keys names to be reused
2019-06-07 13:19:28 +01:00
Katie Smith
ffcd731a68 Add endpoint to archive a user
This archives a user if their state is 'active'.
2019-06-05 14:54:52 +01:00
Katie Smith
bef24408d0 Add DAO function to archive a user
For a user to be able to be archived, each service that they are a
member of must have at least one other user who is active and who has
the 'manage-settings' permission.

To archive a user we remove them from all their services and
organisations, remove all permissions that they have and change some of
their details:
- email_address will start with '_archived_<date>'
- the current_session_id is changed (to sign them out of their current
session)
- mobile_number is removed (so we also need to switch their auth type to
email_auth)
- password is changed to a random password
- state is changed to 'inactive'

If any of the steps fail, we rollback all changes.
2019-06-05 14:54:52 +01:00
Katie Smith
844f22bcd0 Remove unused fixture and add test function to create permissions 2019-06-05 14:54:52 +01:00
Leo Hemsted
aab8b99605 Merge pull request #2524 from alphagov/free-allowance-report
Free sms allowance in billing report
2019-06-05 14:34:55 +01:00
Rebecca Law
a1f6a5f78a Update the unique constraint for the name of an api_key so that it only looks at api_keys that are not expired (or expiry_date is null).
This will allow clients to create a new api key with the same name.
2019-06-04 15:30:27 +01:00
Leo Hemsted
7db2b031a2 add free_sms_fragment_limit to platform admin billing report
a little complicated because the free_sms_fragment_limit comes from
the annual_billing table. This relies on there always being at least
one row for every service on annual billing - I checked on prod and
that is true.

Join to the annual billing table, then join to a subquery getting the
latest year for that service to extract only the most recent year.
2019-06-04 11:34:10 +01:00
Leo Hemsted
968d94d350 clean up dao_fetch_live_services
a bit of DRY - use the column definitions to determine what goes into
the dict, and use a `next` iterator rather than a while loop to find
the existing service row. Take advantage of dict mutability to avoid
needing to refer to the list by index.

Also change the tests so if there's an error, the diff is slightly
more readable. But not much
2019-06-04 11:33:19 +01:00
Leo Hemsted
4fc7cc6f2e clean up tests
* remove unnecessary parametrisation where we're not testing
type-specific things
* remove some unused fixtures
* replace len(x.all()) with x.count()
* don't deleted notificationhistory now that we know it's not written
* remove some pre-test function asserts
2019-06-04 11:27:28 +01:00
Leo Hemsted
2ac2cbbd37 don't pass running totals in to functions
or you can easily end up double-counting things. (the test written
previously returned 6)
2019-06-03 17:47:42 +01:00
Leo Hemsted
67f171f2f8 refactor tests
re-order notification dao delete notifications test to move "fixtures"
to the top of the file

changed create_service_data_retention to take an ORM object, not an id.
brings it in line with other db.py test functions
2019-06-03 17:27:08 +01:00
Rebecca Law
cfd42a2eb9 Update subquery to be more efficient.
Update subquery to run again but for test keys. Test data is never inserted in Notifications so they need to be deleted separately now given the join to NotificationHistory.
2019-06-03 15:16:46 +01:00
Rebecca Law
b8399b8b9b Add a where clause to join to NotificationHistory, this is some extra assurance that the Notification will not be deleted unless the history exists. 2019-06-03 11:47:02 +01:00
Rebecca Law
c23ae15f32 Remove insert to NotificationHistory
Fix all test failures
2019-05-31 16:52:22 +01:00
Rebecca Law
4154251970 Addd missing reference to the update statement. 2019-05-30 10:54:47 +01:00
Pea (Malgorzata Tyczynska)
82e27c4064 Merge pull request #2511 from alphagov/verify_new_reply_to_address
Verify new reply to address
2019-05-28 16:16:06 +01:00
Pea Tyczynska
5f1f688c7b Create template to verify service email reply-to addresses
So that template with the same ID is present on all environments
2019-05-28 15:14:09 +01:00
Rebecca Law
2844fa530b Fix a bug introduced when refactoring some code. The notification status happened in the wrong order - this resolved that.
This meant notifications sent with a test key never got a 'delivered' status.
2019-05-23 17:04:55 +01:00
Pea Tyczynska
5692a8596d Code refactors and corrections, details below:
Change method name to be more relevant

Check if verification notification we send is a correct one

pass in notify db session for tests instead of sample_user

Refactor tests by using admin_request instead of client

Refactor all tests for affected reply-to endpoints for good measure

Allow overwriting reply-to address with the same address

Skip checking for duplicates if it's an reply-to email update

Fix refactored tests

Verify duplicates exception not needed
2019-05-23 15:36:09 +01:00
Pea Tyczynska
3c3dde635b Prevent service from adding duplicate reply-to addresses
Check for duplicate reply-to email address has been added on:
-verification endpoint, so we do not send the verifying notification
needlessly
- add reply-to email address and update reply-to email address
endpoints, as those can be hit multiple times after the email address
has been verified (so the same email address could end up being added
multiple times). EDIT: this has now been prevented on admin app,
but it's better to retain double-check for safety.
2019-05-23 15:36:09 +01:00
Pea Tyczynska
615ea6a98a Send verifcation email to a new reply-to email address 2019-05-23 15:36:09 +01:00
Rebecca Law
0a5d39f83d Merge pull request #2496 from alphagov/refactor-update-notifications
Refactor update notifications
2019-05-22 13:38:32 +01:00
Rebecca Law
e731dd96ed Added units test to make sure the complaints work if the notification doesn't exist or if the notification_history doesn't exist 2019-05-22 10:03:07 +01:00
Rebecca Law
3374e03ce9 Prepare to stop inserting NotificationHistory at the time of inserting a notificaiton.
Need to remove foreign key to complaints.
Make sure if getting Notification.id we look to both tables.
2019-05-21 16:08:18 +01:00
Rebecca Law
bde1e751ad Merge pull request #2502 from alphagov/dont-update-notification-history-in-realtime
Stop updating NotificationHistory
2019-05-21 14:46:59 +01:00
Rebecca Law
56800c669d Added some better unit tests 2019-05-17 16:01:46 +01:00
Rebecca Law
198fd21f7e Update Notification history if there is a mismatch in the number of notifications to be updated and the number actually updated. 2019-05-15 15:30:15 +01:00
Rebecca Law
82d8c7014d Merge branch 'master' into dont-update-notification-history-in-realtime 2019-05-15 15:15:26 +01:00
Rebecca Law
e3ee99e70d Reduce the number of days to recalculate billing. It's not necessary to calculate longer than 4 days. 2019-05-15 14:40:53 +01:00
Rebecca Law
43334d63f3 Stop updating NotificationHistory
Doing my bit to remove imports of fixtures.
2019-05-15 10:58:39 +01:00
Katie Smith
84c35cbf67 Add request_to_go_live_notes column to Organisation table
This column will be used to stores extra notes that should go in the
Zendesk ticket when a service belonging to that organisation requests to
go live.
2019-05-13 14:45:01 +01:00
Pea Tyczynska
eec5f5490d Don't require precompiled_letter service permission
Everyone can send precompiled letters now yay
2019-05-13 13:04:29 +01:00
Rebecca Law
fc61fd2086 Remove updating provider on failure - we aren't sure yet who is sending the message the callback code sets that property as a fallback anyway.
Remove debug statements.
2019-05-08 16:31:51 +01:00
Rebecca Law
77c35da5ca Refactor send_email_to_provider
- Remove debug statement
2019-05-08 15:55:45 +01:00
Rebecca Law
53f0e9334a Refactor send_to_providers.
- Remove some redundant code for research mode.
- The international parameter in update_notification_to_sending is not needed.
- Update unit tests and removed duplicates
2019-05-08 15:45:19 +01:00
Katie Smith
ce24b13654 Combine two tests into one 2019-05-08 11:39:01 +01:00
Katie Smith
c809bf2207 Ensure notifications have billable units and provider if sending fails
If we try to send an SMS to the provider and the provider throws an exception
(because they return a 503 status code) the notification should retry. But if
we get the callback from the provider before the notification has been retried, the
notification will have no billable units or provider set.

To avoid this, we now set billable_units and provider even if there has been
an exception from our provider.
2019-05-08 10:54:01 +01:00
Katie Smith
cf7997d925 Change get_providers endpoint to return no of SMS sent by each provider
In addition to the existing provider data, we also want return the number of
billable units (muliplied by the rate multiplier) that each SMS provider sent
this month. This will be used on the platform admin providers page.

Since we can no longer get all the information we need from the provider details
schema, this makes a new DAO function to get all the data for the endpoint.
2019-05-07 08:31:04 +01:00
Pea Tyczynska
689ff57c32 Add organisation type to live services report 2019-05-03 15:09:54 +01:00
Rebecca Law
b89ab0cd87 Merge pull request #2487 from alphagov/dont-update-notification-history-in-realtime
Insert/update NotificationHistory just before we delete from Notifications
2019-05-02 13:57:41 +01:00
Rebecca Law
d5d2b3d2a6 Update insert to use select_from - this allows the insert query to run as a single bulk insert and should be more efficient. 2019-05-02 13:46:15 +01:00