Commit Graph

407 Commits

Author SHA1 Message Date
Leo Hemsted
28d5f9b87f flake8 - remove unused imports and ensure they're always at the top of the file 2017-11-28 14:28:01 +00:00
Rebecca Law
86098041fa Add reply_to_text to Notification model.
This was missed out of the previous PR and needs to be there before the next PR is merged.
2017-11-27 13:39:35 +00:00
Alexey Bezhan
e8ce408f6a Fix an intermittent test failure when creating a template with reply_to
reply_to requires template_type to be already set, but the order
of attribute assignment is not defined when a model object is created
from a dictionary.

This adds a constructor to Template model that makes sure that
template_type is set first when multiple arguments are passed to the
constructor at once.

The problem might still exist when the template is created through the
API, so this is a temporary fix to unblock the release.
2017-11-22 16:13:45 +00:00
Alexey Bezhan
cbce610098 Add template.service_letter_contact_id and reply_to wrapper property
Adds a relationship between Template models and service letter contact
blocks.

Depending on template type, we can have a reference to either a letter
contact block, email reply-to address or SMS sender record. This means
that in order to enforce foreign key constraints we need to define three
separate foreign key columns on the template model.

To hide this implementation detail and make it easier to access the
sender/reply-to information we define a wrapper property that returns
the value from the correct column.

The relationship and the property are only defined for letter templates
at the moment.

The setter raises an error when trying to assign a reply_to value for
non-letter templates. The exception isn't raised if the value being
assigned is `None` since it can get assigned by marshmallow schemas
and as it matches the value returned for other template types it
doesn't need to be written anywhere.
2017-11-22 14:20:53 +00:00
Alexey Bezhan
4c253bf3b9 Move common Template/TemplateHistory attributes to a base class
This allows us to avoid duplication between Template and TemplateHistory
classes and makes it easier to ensure that all columns are copied
to the TemplateHistory objects.
2017-11-22 14:15:58 +00:00
Chris Hill-Scott
22ec134668 Merge pull request #1376 from alphagov/remove-computed-sms-prefix
Remove computed SMS prefix
2017-11-21 14:29:33 +00:00
Chris Hill-Scott
ac885dd4e6 Remove computed SMS prefix
This is no longer used no that the column in the table (`prefix_sms`) is
populated.
2017-11-21 14:12:35 +00:00
Rebecca Law
577463b0ac Remove create_or_update_email_reply_to and create_or_update_letter_contact - no longer needed.
Remove Services.reply_to_email_address and Services.letter_contact_block
2017-11-20 14:33:15 +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
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
fd217e67f5 Merge branch 'master' into remove-initial-update-sms-sender 2017-11-15 12:33:38 +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
Rebecca Law
e3f9dab884 Merge branch 'master' into remove-initial-update-sms-sender 2017-11-14 16:27:10 +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
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
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
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
Ken Tsang
cd4637a1d7 Removed provider_reference and provider_date from serialize 2017-11-09 15:22:27 +00:00
Rebecca Law
d3fcba621b Remove sms_sender from Service model.
Remove unused dao method.
2017-11-09 14:01:02 +00:00
Rebecca Law
3713cc2353 Merge branch 'master' into remove-initial-update-sms-sender 2017-11-09 11:53:29 +00:00
Richard Chapman
8973e42b86 Added a new table ‘stats_template_usage_by_month’
Currently the 'See templates used by month' report is timing out for
some services due to the query time of the data from notification_history
This is a stats table which will hold the data and will be updated by a
scheduled celery task once a day. This data will be combined with the
'live' data from notifications tables (which will be considerably less)
to form the data of the new report.
2017-11-09 10:34:49 +00:00
Rebecca Law
0054361044 Refactor the sms sender code to remove any unused methods.
Refactor tests/db/create_service() to behave more like the real world.
Created new create_service_with_inbound_number and create_service_with_defined_sms_sender() test/db methods.
2017-11-07 14:26:18 +00:00
Ken Tsang
85b8e24e17 Add V2 inbound_sms API
- had to update the serialization in the model so that the date time is appended with the UTC timezone
- test has been added to ensure that the schema will validate the response correctly
2017-11-07 13:29:40 +00:00
Chris Hill-Scott
812090b104 Default new services to prefixing text messages
We want new services, when they do the tour, to see how the service name
they just made shows up in the messages. This is how it (should) work
at the moment (although got broken because of the multiple senders
stuff).

Need to do this before we do the migration now otherwise a new service
could sneak in with this setting still set to `null`.
2017-11-03 15:52:56 +00:00
Chris Hill-Scott
cccffdd2ac Add a column for a service to set SMS prefixing
In future changes, services will be able to control whether their text
messages will be prefixed with the name of their service.

This commit:
- adds a column to store the value of that setting
- makes the service model take notice of it, if it were to have a value
  set

It doesn’t:
- provide a way of setting the value of this column

Currently the column can have three values:
- `None` – ignore it (this is what all current services will start as)
  and continue to determine whether to prefix messages by looking at the
  sender
- `True` – always the service name to the start of text messages
- `False` – never add the service name to the start of text messages

In the future we’ll migrate all services to be either `True` or `False`,
the `None` will go away and all services will have direct control over
the setting.
2017-11-03 12:53:06 +00:00
Chris Hill-Scott
92b605833f Add prefix SMS with service name to service model
If the service is sending messages from GOVUK, then its messages should
be prefixed with the service name. Right now this logic is:
- worked out separately in the admin app and API
- isn’t aware of multiple senders

This commit moves the logic to one place (the service model). It does
this in a slightly naive way, in that it only looks at the default
sender, not the actual sender of the message.

In the future this will go away because we’ll move it to being a setting
that’s controlled independently of the service name. But this is the
first step towards that.

fixup! Add prefix SMS with service name to service model
2017-11-03 12:28:35 +00:00
Rebecca Law
f5e79302cd Remove NotificationStatistics
NotificationStatistics was added as a spike but didn't work out as expected. This is finally removing all that unused code.
I'll drop the table in the next PR
2017-11-01 15:02:50 +00:00
Leo Hemsted
c39ec90727 add auth type table, currently contains sms_auth and email_auth 2017-10-30 11:11:37 +00:00
venusbb
b648c2e632 Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-free-sms-limit-history 2017-10-30 09:34:23 +00:00
Leo Hemsted
46f5896b3b add new email_auth service permission 2017-10-27 14:28:20 +01:00
venusbb
6f02ee516c Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-free-sms-limit-history 2017-10-27 10:47:20 +01:00
Rebecca Law
4f65ca5447 Create a new table to map a notification to a SMS sender.
There is also some minor db model updates here so that the python db model match the db
2017-10-26 15:25:38 +01:00
venusbb
c10cde6b22 modified serialized method and schema 2017-10-26 13:25:11 +01:00
venusbb
e88b311c8e Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-free-sms-limit-history 2017-10-26 11:56:14 +01:00
kentsanggds
d39bf96324 Merge pull request #1333 from alphagov/ken-handle-dvla-response-file
Handle DVLA response file
2017-10-26 11:09:09 +01:00
Ken Tsang
b40cab0c5d Refactored models to make const consistent 2017-10-25 15:38:58 +01:00
venusbb
8ad98f2806 create entry when creating a new service 2017-10-25 11:35:13 +01:00
Ken Tsang
a2b42194cd Add letter status received to data model
- in order to reduce the number of statuses in the database the letter status `received` will be mapped to `delivered` internally
2017-10-25 10:48:35 +01:00
venusbb
b9b0814853 Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-free-sms-limit-history 2017-10-24 14:44:32 +01:00
Rebecca Law
8d6c38e1fe Now that we allow multiple SMS senders for a service, update the sender for SMS to be the default SMS sender, regardless if it is inbound number or not 2017-10-24 13:37:17 +01:00
venusbb
59dd343254 Added free_sms_fragment_limit model, schema, dao and Rest 2017-10-24 13:23:24 +01:00
Rebecca Law
954a80649e Merge branch 'master' into add-update-multiple-sms-sender 2017-10-19 14:34:58 +01:00
venusbb
b0872d9466 add unique service_id&year constraint 2017-10-19 14:21:10 +01:00
venusbb
7e78e19500 Unique constrain and db.relationship 2017-10-19 12:00:01 +01:00
Rebecca Law
709e24e267 Added endpoints to get sms senders for a service 2017-10-19 10:43:49 +01:00
Rebecca Law
6dc41c3b47 New endpoints to add and update multiple SMS sender for a service. 2017-10-19 09:58:23 +01:00