Commit Graph

506 Commits

Author SHA1 Message Date
Chris Hill-Scott
c573209d7e Stop guessing notification type
Before the search term was either:
- an email address (or partial email address)
- a phone number (or partial phone number)

Now it can also be:
- a reference (or partial reference)

We can take a pretty good guess, by looking at the search term, whether
the thing the user is searching by email address or phone number. This
helps us:
- only show relevant notifications
- normalise the search term to give the best chance of matching what we
  store in the `normalised_to` field

However we can’t look at a search term and guess whether it’s a
reference, because a reference could take any format. Therefore if the
user hasn’t told us what kind of thing their search term is, we should
stop trying to guess.
2019-12-16 13:43:38 +00:00
Rebecca Law
140cb65554 Return report_at date as a date not datetime. I haven't converted this date from UTC to BST because we always upload the returned-letters during business hours. 2019-12-11 14:41:35 +00:00
Rebecca Law
c8364b4dc4 Add endpoint to return the summary data for returned letters.
Returning the count of letters that are returned for each report date.
2019-12-10 16:21:55 +00:00
Rebecca Law
40a0c62926 New endpoint to return a summary of returned letters for the service. 2019-12-09 17:27:18 +00:00
David McDonald
714c349efd Use existing postage format for validation
Also adds explicit test for checking of postage
2019-10-25 16:13:22 +01:00
David McDonald
d1195dfd5a Use json schema to validate post request to send PDF letter
This approach was suggested as the way to do validation things on
Notify.
2019-10-25 14:36:13 +01:00
David McDonald
7f708153d2 Require 'postage' key when sending a pdf letter 2019-10-24 16:12:47 +01:00
Katie Smith
9b8e0ed856 Check service is not in trial mode for uploaded letters
This adds an api check that the service is not in trial mode when
someone tries to send an uploaded letter.
2019-10-22 09:17:52 +01:00
Pea Tyczynska
6ee7ac6cac Refactor and harmonise metadata for invalid letters with those sent from admin app 2019-10-16 14:11:50 +01:00
Rebecca Law
f234e94572 Change the variable name to make a little more sense. 2019-09-25 13:56:10 +01:00
Rebecca Law
702d8fa85f Refactor the code that figures out what folder and filename to use for the letter pdf files.
Now we consistently use the created_at date, so we can always get the right file location and name.

The previous updates to this code were trying to solve the problem if a pdf being created at 17:29, but not ready to upload until 17:31 after the antivirus and validation check.
But in those cases we would have trouble finding the file.
2019-09-25 13:56:10 +01:00
Katie Smith
8347b86b44 Add endpoint to create pdf letter 2019-09-12 14:58:51 +01:00
Katie Smith
eb73ddb8b4 Add function to send PDF letter
This function checks various permissions, downloads the PDF from the
transient bucket, creates the notification then moves the letter to the
'normal' bucket.
2019-09-12 14:58:51 +01:00
Pea Tyczynska
252be67436 Use serialize instead of marshmallow schema for lighter query
Find services by name feature was timing out for big collections
of results.
2019-08-16 17:30:04 +01:00
Pea Tyczynska
52a1316a7e Find services by partial name 2019-08-13 17:20:37 +01:00
Katie Smith
b4a6aecbb9 Add endpoint to return monthly notification stats per service
This will be used by notifications-admin to create a CSV report.
2019-07-23 10:00:50 +01:00
Pea Tyczynska
d89ef0594f nhs_central is crown org and also we do not update org type while
updating service anymore.
2019-07-18 17:05:24 +01:00
Pea Tyczynska
9dfc550f46 Add org types table 2019-07-18 17:05:22 +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
Pea Tyczynska
669db0b4ca New db query that returns data about live services
This data includes service and org name, consent to research,
contact details and both intended and factual notifications
volumes by notification type.

This query was created to get data for a csv report for our
platform admins.
2019-05-01 15:57:20 +01:00
Chris Hill-Scott
ee966668bd Remove domain columns from branding table
This relationship is via the `Organisation` now; we don’t use this
column to fudge a relationship based on the user’s email address and the
matching something in these columns.
2019-04-12 15:53:17 +01:00
Katie Smith
2aa14bc41c Set folder permissions when adding a user to a service
This sets the folder permissions for a user when adding them to a
service. If a user is being added to a service after accepting an
invite, we need to account for the possibility that the folders we are
trying to add them to have been deleted before they accepted the invite.
2019-03-22 09:30:39 +00:00
Katie Smith
b0d3bd9046 Update add_user_to_service endoint to only handle new data format
Updated the add_user_to_service endpoint to only handle data in the
'new' format (`{"permissions": [...]}` instead of `[permission_1, permission_2]`)
since Admin has been updated to send data the new way.

This change means that we no longer need the Marshmallow Permission
schema, so it can be deleted.
2019-03-22 09:30:39 +00:00
Katie Smith
d4757c9208 Allow add_user_to_service endpoint to accept new data format
The data posted to the `add_user_to_service` endpoint is currently sent as a
list of permissions:
`[{'permission': MANAGE_SETTINGS}, {'permission': MANAGE_TEMPLATES}]`.

This endpoint is going to also be used for folder permissions, so the
data now needs to be nested:

`{'permissions': [{'permission': MANAGE_SETTINGS}, {'permission': MANAGE_TEMPLATES}]}`

This changes the add_user_to_service endpoint to accept data in either
format. Once admin is sending data in the new format, the code can be
simplified.
2019-03-14 16:59:48 +00:00
Leo Hemsted
1efee1fa66 fix constraint name check in service error handler 2019-03-14 12:09:29 +00:00
Rebecca Law
e030c2be88 Removing platform_default as a concept. No service actually wants to send letters with the default hm-government logo so we are going to remove it as a constraint.
However, until we can create a letter without a logo, we will still default to hm-government, because the dvla_organisation is set on the service.
This does simplify the code.
Also removed the inserts to letter_branding in the data migration file, because we can deploy this before the rest of the work is finished. But we will need to do it later.
2019-01-25 15:03:01 +00:00
Rebecca Law
f8eb72a537 Adding rest endpoints for letter-branding 2019-01-24 16:38:52 +00:00
Rebecca Law
f11aa55e0b Adding new data models for letter branding. 2019-01-22 17:27:00 +00:00
Pea (Malgorzata Tyczynska)
276a9a3828 Merge pull request #2293 from alphagov/choose_postage_for_precompiled
Choose postage on POST request for precompiled letters
2019-01-16 14:13:26 +00:00
Pea Tyczynska
5ebeb9937a Avoid call to database to get template in persist_notifications 2019-01-14 17:53:06 +00:00
Rebecca Law
b5a3ef9576 Added order by.
Added more unit tests.
Remove comments.
2019-01-14 15:28:26 +00:00
Rebecca Law
92460fbd38 Merge branch 'master' into use-ft-notification-statu-for-monthly-template-usage 2019-01-11 17:11:23 +00:00
Rebecca Law
c3c9d1eac9 Add unit tests.
Fix data types in result set.
2019-01-11 17:09:42 +00:00
Pea Tyczynska
bd5126481c Remove cancelled from requested statuses in service statistics 2019-01-11 14:27:54 +00:00
Rebecca Law
507138cc94 Create a new query for template monthly stats. 2019-01-10 16:24:51 +00:00
Pea (Malgorzata Tyczynska)
c5e5c86982 Merge pull request #2290 from alphagov/its_not_a_failure_to_cancel
Cancelled notifications don't show as failures in statistics
2019-01-10 15:09:30 +00:00
Alexey Bezhan
1719f31909 Merge pull request #2284 from alphagov/add-count-pages-flag-to-service-notifications
Don't return pagination links for API Message log requests
2019-01-09 14:36:36 +00:00
Leo Hemsted
3e21f57481 fix platform admin stats row-order bug
now that we're reading from two tables (ft_notification_status and
notifications) for stats, we'll get a couple of rows for each
notification type. If a service doesn't have any rows in one of those
tables, the query will return a row with nulls for the notification
types and counts. Some services will have history but no stats from
today, others will have data from today but no history.

This commit acknowledges that any row might have nulls, not just the
first row.
2019-01-09 11:43:40 +00:00
Pea Tyczynska
e3a79e80c9 Cancelled notifications don't show as failures in statistics 2019-01-08 17:50:34 +00:00
Alexey Bezhan
47c403f6ab Don't return pagination links for API Message log requests
Flask-SQLAlchemy paginate function issues a separate query to get
the total count of rows for a given filter. This query (with
filters used by the API integration Message log page) is slow for
services with large number of notifications.

Since Message log page doesn't actually allow users to paginate
through the response (it only shows the last 50 messages) we can
use limit instead of paginate, which requires passing in another
flag from admin to the dao method.

`count` flag has been added to `paginate` in March 2018, however
there was no release of flask-sqlalchemy since then, so we need
to pull the dev version of the package from Github.
2019-01-08 13:22:27 +00:00
Rebecca Law
bd9a6352fd Optimise the query for getting the platform statistics for all services. The page should render for all time after this change.
This is one step closer to eliminating the need to read from NotificationHistory.
2019-01-04 16:45:39 +00:00
Katie Smith
90d9135fcf Return cancelled letters for dashboard
Added cancelled letters to the number of failed letters in the statistics
that get used for the dashboard. At some point, we want to stop
including cancelled letters in the stats, but for now this keeps things
consistent with our current letter failure state, permanent-failure.
2018-12-03 17:51:09 +00:00
Katie Smith
1d67b55b16 Add endpoint for cancelling letters 2018-12-03 17:51:08 +00:00
Chris Hill-Scott
3cfeadcae8 Refactor if statement to be positive 2018-12-03 11:34:14 +00:00
Chris Hill-Scott
f5ea77ffa0 Add reference to one off letters
Letters should always have a reference, because that’s what DVLA use to
tell us when they’ve sent a letter.

If a letter has a reference of `None` then DVLA say they’ve sent a
letter with a reference of `'None'`. This means we can never reconcile
the letter, which means it stays in `created`, which means it never
gets billed.

We don’t think this has affected any real letters yet, just ones that
we’ve sent as tests.
2018-12-03 11:34:14 +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
Pea (Malgorzata Tyczynska)
d46caa184e Merge pull request #2211 from alphagov/fix_notification_statistics_on_dashboard
Fix notification statistics on dashboard
2018-11-06 16:22:00 +00:00
Pea Tyczynska
5d806c2437 Adjust tests to new way of querying for notification stats 2018-11-06 14:40:40 +00:00