Commit Graph

3954 Commits

Author SHA1 Message Date
Ken Tsang
df98f0dec1 Update schema to allow include_jobs on get_notis 2017-11-16 14:44:28 +00:00
Venus Bailey
bf5e6db666 Merge pull request #1398 from alphagov/migration-data-rename-version
Free sms allowance change db migration version
2017-11-16 13:54:25 +00:00
venusbb
7ac0346961 change migration version 2017-11-16 13:44:55 +00:00
Venus Bailey
bb0c8090c5 Merge pull request #1389 from alphagov/vb-sms-allowance-data-migration
migrate data from service table to annual billing
2017-11-16 13:16:15 +00:00
Chris Hill-Scott
8cb4659701 Merge pull request #1396 from alphagov/pyup-update-pytest-3.2.3-to-3.2.5
Update pytest to 3.2.5
2017-11-16 11:36:16 +00:00
Richard Chapman
38e8451627 Merge pull request #1390 from alphagov/rc-monthly-template-usage-endpoint
Added new endpoint to get the new template stats
2017-11-15 16:20:04 +00:00
Richard Chapman
424f87cb68 Removed unused import
Removed an import which is no longer required.
2017-11-15 16:12:03 +00:00
Richard Chapman
17d1cfe758 Reverted Config on SQLALCHEMY_ECHO
Used for debugging not needed for production so reverted.
2017-11-15 16:00:13 +00:00
Richard Chapman
1e4850b70f Add Template name to response and filter by year
The template name should be returned for the response and the user will
pick a year, so ths adds those two features to the
notifications/templates_usage/monthly endpoint and added some tests to
test the functionality.
2017-11-15 15:55:00 +00:00
Rebecca Law
8f3f6ebffd Merge pull request #1380 from alphagov/remove-initial-update-sms-sender
Remove unused methods for sms sender
2017-11-15 14:41:24 +00:00
Richard Chapman
618c7676e6 Code style fixes
A few code style fixes which were making tests to fail.
2017-11-15 12:58:39 +00:00
Richard Chapman
c27edf5e3c Added new endpoint to get the new template stats
Added a new endpoint which combines the usage of the stats table and the
data from the notifications tables, instead of using all the data from
the notification_history table. This should speed up the query times
and improve the page performance.

- Updated to make the stats create and update function transactional as
it actually wasn't committing the data to the table
- Added the get from the stats table
- Add a a method to combine the two results
- Added the endpoint
2017-11-15 12:58:39 +00:00
Rebecca Law
9fa59c9407 Fix merge conflict 2017-11-15 12:42:49 +00:00
Rebecca Law
fd217e67f5 Merge branch 'master' into remove-initial-update-sms-sender 2017-11-15 12:33:38 +00:00
pyup-bot
46f55bf884 Update pytest from 3.2.3 to 3.2.5 2017-11-15 12:23:10 +00:00
venusbb
e903257156 version change because of other commits 2017-11-15 11:25:27 +00:00
Alexey Bezhan
d9f885b881 Merge pull request #1394 from alphagov/fix-migration-order-0136
Fix migration numbers after #1383
2017-11-15 11:07:11 +00:00
Rebecca Law
fc5dae8ec2 refactored create_service_with_defined_sms_sender 2017-11-15 11:04:33 +00:00
Alexey Bezhan
d2a220a418 Fix migration numbers after #1383 2017-11-15 11:03:55 +00:00
Rebecca Law
45bf7e1938 Fix db migration merge conflict
Update create_service_with_inbound_number
2017-11-15 11:00:56 +00:00
venusbb
fcfea6844d Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-sms-allowance-data-migration 2017-11-15 10:54:22 +00:00
Alexey Bezhan
bc54d34a22 Merge pull request #1384 from alphagov/notifications-template-history
Fix notifications template history relationship
2017-11-15 10:51:56 +00:00
Venus Bailey
34de0924e6 Merge pull request #1392 from alphagov/vb-free-sms-bridging-code
Bridging API to update annual_billing table
2017-11-15 10:33:14 +00:00
venusbb
f2a9f39ce2 Added an extra test 2017-11-15 09:18:39 +00:00
Rebecca Law
e3f9dab884 Merge branch 'master' into remove-initial-update-sms-sender 2017-11-14 16:27:10 +00:00
venusbb
c111458168 Bridging API to update annual_billing table 2017-11-14 16:15:36 +00:00
venusbb
4e487e708b Bridging API to update annual_billing table 2017-11-14 16:11:59 +00:00
Leo Hemsted
0dd372bada Merge pull request #1382 from alphagov/migration-fix
remove trailing underscore, which is sometimes created by alembic
2017-11-14 15:59:43 +00:00
Leo Hemsted
27bf927f43 Merge pull request #1383 from alphagov/user-mobile-optional
User mobile optional
2017-11-14 15:59:31 +00:00
venusbb
7c0c2a9a0f migrate data from service table to annual billing 2017-11-14 09:43:28 +00:00
Leo Hemsted
834eecd0f1 make sure you can't edit password 2017-11-10 15:24:37 +00:00
Alexey Bezhan
9d4b8961cb Add a migration to replace notifications_template foreign key
Removes notifications.template_id foreign key and replaces it with
a composite foreign key constraint to TemplateHistory using the
existing notification columns for template ID and template version.

Foreign key constraint is created as NOT VALID to avoid locking the
notifications table while postgres verifies that existing records
don't break the constraint. From postgres docs:

> If the constraint is marked NOT VALID, the potentially-lengthy initial
> check to verify that all rows in the table satisfy the constraint is
> skipped. The constraint will still be enforced against subsequent
> inserts or updates (that is, they'll fail unless there is a matching
> row in the referenced table, in the case of foreign keys; and they'll
> fail unless the new row matches the specified check constraints). But
> the database will not assume that the constraint holds for all rows
> in the table, until it is validated by using the VALIDATE CONSTRAINT
> option.

VALIDATE CONSTRAINT will be issued as a separate migration in a
follow-up PR.
2017-11-10 15:13:55 +00:00
Alexey Bezhan
0825177f2d Add tests for notification.template returning the right version
Adds test for:
* checking the template version foreign key constraint
* checking that template changes don't affect existing notifications
* notification statistics aren't affected by different template versions
* notification stats always return the current template name
2017-11-10 15:13:55 +00:00
Alexey Bezhan
db1c647873 Remove NotificationHistory.template relationship
Relationship attribute is not used by the application code, so we
can remove it without replacing it with a TemplateHistory one.

This also updates the foreign key constraint to refer to the composite
primary key for the TemplateHistory records.
2017-11-10 15:13:55 +00:00
Alexey Bezhan
bdcc89b403 Add TemplateHistory.redact_personalisation attribute
TemplateHistory objects need to be connected to the template's
TemplateRedacted record. This requires setting up a new SQLAlchemy
relationship to allow accessing redact_personalisation from
TemplateHistory instances.

We can avoid creating a foreign key in this case by setting up an
explicit `primaryjoin` expression. Since TemplateHistory.id is
created from Template.id and TemplateRedacted.template_id is
already a foreign key to Template.id the foreign key should always
be valid even without a DB constraint.
2017-11-10 15:13:55 +00:00
Alexey Bezhan
79d417f13b Add TemplateHistory.get_link method
Notifications.serialize calls `Notifications.template.get_link`, so
we need TemplateHistory objects to generate their API URLs.

This generates a link to the `/v2/` version of the endpoint.
2017-11-10 15:13:55 +00:00
Alexey Bezhan
c62f2a3f7c Update create_custom_template test helper to create history object
`create_custom_template` is not using `dao_create_template` since
it explicitly sets a template id. Notifications.template relationship
now refers to a TemplateHistory objects, so we need to make sure that
`create_custom_template` creates a matching TemplateHistory record
when it creates a Template.
2017-11-10 15:13:55 +00:00
Rebecca Law
62629e4eae Merge pull request #1387 from alphagov/fix-post-notification-response
Update the from number in the response of post notification.
2017-11-10 15:12:16 +00:00
Alexey Bezhan
94dae42902 Avoid assigning notification.template when creating test objects
`Notification.template` changed from being a Template relationship
to TemplateHistory. When a relationship attribute is being assigned,
SQLAlchemy checks that the assigned value type matches the relationship
type. Since most tests at the moment create a notification using a
Template instance this check fails.

Rewriting the tests to use TemplateHistory objects would require
changes to the majority of tests. Instead, when creating a notification
objects we assign the foreign key attributes directly. This skips the
SQLAlchemy type check, but we still get the constraint check on the
foreign keys, so a matching TemplateHistory object needs to exist in
the database.
2017-11-10 15:12:07 +00:00
Alexey Bezhan
e73513f519 Update Notification schema to preserve template_history attribute
`Notification.template_history` relationship has been removed but
we want to keep the `template_history` key in existing notification
serializations, so we serialize it from `Notifications.template`.

This keeps the data format the same, but both `template` and
`template_history` keys will now contain data from the `TemplateHistory`
instance.
2017-11-10 15:12:07 +00:00
Alexey Bezhan
a5ca66a01b Update notification queries with new TemplateHistory join
Changes the queries to use `Notification.template` relationship instead
of `.template_history` and TemplateHistory model insteaad of Template.
2017-11-10 15:12:07 +00:00
Alexey Bezhan
52e0367a13 Replace Notifications.template_history with Notifications.template
Each notification instance is connected to a specific version of the
template that was used to generate notification content. Template
versions are stored in TemplateHistory, so that's the table we need
to use for Notifications.template relationship.

Currently, using Notifications.template returns the latest template
version, which leads to incorrect content being returned by the API
if the template has been updated.

This change removes Notifications.template_history attribute and
replaces template relationship to refer to TemplateHistory instance
based on the notification's template ID and version.
2017-11-10 15:12:07 +00:00
Richard Chapman
1ace1b59a1 Merge pull request #1386 from alphagov/rc-monthly-template-usage
Handling Null template_id for monthly stats
2017-11-10 15:08:34 +00:00
Rebecca Law
fe6bafcfb2 Update the from number in the response of post notification. 2017-11-10 14:17:29 +00:00
Richard Chapman
28287abbd8 Added test to handle Null template_id
There are some Null template_ids in the production database which was
causing a failure as the stats_template_usage_by_month has a constraint
that it should not be null. This update only adds populated template_ids

- Updated Celery task
- Add a new test to test for null template_ids and not try to add them
to the stats
2017-11-10 13:49:58 +00:00
Rebecca Law
24b7acf671 Merge pull request #1385 from alphagov/fix-ip-restrictions
Change to fix ip restrictions
2017-11-10 12:16:15 +00:00
Rebecca Law
9e9642f6e9 Change to fix ip restrictions 2017-11-10 12:05:06 +00:00
Leo Hemsted
6332058781 remove PUT /user/<id> 2017-11-10 10:49:44 +00:00
kentsanggds
34aa8dfd01 Merge pull request #1373 from alphagov/ken-get-inbound_sms-api
Get inbound SMS API
2017-11-10 10:25:02 +00:00
Leo Hemsted
15bf888624 make user mobile num nullable if user has email_auth enabled 2017-11-09 19:07:44 +00:00