Commit Graph

2285 Commits

Author SHA1 Message Date
Leo Hemsted
27bf927f43 Merge pull request #1383 from alphagov/user-mobile-optional
User mobile optional
2017-11-14 15:59:31 +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
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
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
Richard Chapman
e14275c19a Merge pull request #1377 from alphagov/rc-monthly-template-usage
Added scheduled task to get stats for template usage
2017-11-09 16:28:30 +00:00
Venus Bailey
43ecb4e574 Merge pull request #1379 from alphagov/vb-annual-billing-schema
remove check to financial_year_start in schema as it can be None
2017-11-09 15:49:48 +00:00
Ken Tsang
36fb2fb28c Remove user_number from inbound sms dao 2017-11-09 15:23:16 +00:00
Ken Tsang
61a9f6e950 Removed provider_date and provider_reference from schema 2017-11-09 15:22:53 +00:00
Ken Tsang
cd4637a1d7 Removed provider_reference and provider_date from serialize 2017-11-09 15:22:27 +00:00
Richard Chapman
15e86170d9 Changed timezone back
Reverted back the timezoe change that was made in error and was making
two tests fail.
2017-11-09 14:55:45 +00:00
Leo Hemsted
048ddbb2a4 add separate activate user endpoint 2017-11-09 14:27:24 +00:00
Richard Chapman
b78d989d4e Updates after review
- Modified the services_dao to return an int instead of a datetime to
make usage easier and removed the BST function on year as it is not
relevant for year
- Improved tests do there is less logic by ordering the result so there
is less reliance on the template id
- Renamed variable in stats_template_usage_by_month_dao.py to make it
consistent with the method
2017-11-09 14:13:42 +00:00
venusbb
23d8d54e0b remove check to financial_year_start in schema as it can be None 2017-11-09 11:07:11 +00:00
Richard Chapman
ff911c30d6 Added Scheduled task to get stats for template usage
Currently some pages are timing out due to the time it takes to perform
database queries. This is an attempt to improve the performance by
performing the query against the notification history table once a day
and use the notification table for a delta between midnight and the when
the page is run and combine the results.

- Added Celery task for doing the work
- Added a dao to handle the insert and update of the stats table
- Updated tests to test the new functionality
2017-11-09 10:34:49 +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
Richard Chapman
a77c316d2f Added stats annotation to a few more methods to track which methods need to be improved to increase billing performance 2017-11-09 10:34:49 +00:00
Chris Hill-Scott
4761d852e9 Fix escaping in inbound text messages from MMG
One of our providers gives us messages with special characters escaped,
ie a newline comes through as `\n`, not a literal newline. We shouldn’t
be showing these backslashes to any of our users. We also have examples
of real inbound messages containing `👍` and `’`, so we should continue
to display these properly.

It’s a bit tricky, because the strings we get from this provider are a
mixture of escape sequences (eg `\n`) and unicode characters (eg `😨`).
So we have to first convert the unicode character `😨` into an escape
sequence, `\U0001f628` in this example. We do this by encoding with
the `raw_unicode_escape` codec:

> Latin-1 encoding with \uXXXX and \UXXXXXXXX for other code points.
> Existing backslashes are not escaped in any way. It is used in the
> Python pickle protocol.

– https://docs.python.org/3/library/codecs.html#text-encodings

Then we turn this back into a string using the `unicode_escape` codec,
which transforms all escape sequences into their literal representations
(eg `\U0001f628` becomes `😨` and `\n` becomes a newline).
2017-11-08 13:32:30 +00:00
Ken Tsang
874ca5a8af Refactored code to remove user number handling 2017-11-08 11:02:02 +00:00
Leo Hemsted
0146e2d935 attempt to reduce code duplication 2017-11-07 16:47:40 +00:00
Leo Hemsted
67ae1fdb7b PR changes - some comment clarification and code simplifying 2017-11-07 16:47:40 +00:00
Leo Hemsted
a231918317 put secret code in email url token 2017-11-07 16:47:26 +00:00
Leo Hemsted
6af616eb83 add name to personalisation and urlencode next param
also add tests
2017-11-07 16:47:26 +00:00
Leo Hemsted
dd326ec1d3 add new template to config
and rename existing new user email verification template for clarity
2017-11-07 16:47:26 +00:00
Leo Hemsted
b2756ac99d add email code verification
by hitting POST /<user_id>/email-code, we create an email two factor
code to send to the user. That email contains a link with a token that
will sign the user in when opened.

Also some other things:

"email verification" (aka when you first create an account) doesn't
hit the API anymore

refactor 2fa code verification and sending to use jsonschema, and share code between sms and email

Die marshmallow die!
2017-11-07 16:45:49 +00:00
Ken Tsang
dca331e3ea Refactor to use query string rather than path params 2017-11-07 16:39:11 +00:00
Ken Tsang
ac15e7fd8b Renamed inbound_sms_list key name to received_text_messages 2017-11-07 13:29:40 +00:00
Ken Tsang
2e66fe5e38 Removed page from get paginated args as not used 2017-11-07 13:29:40 +00:00
Ken Tsang
0350c99a3e Updated inbound sms API endpoints
- from `/v2/inbound_sms` to `/v2/received-text-messages`
- use paginated results
2017-11-07 13:29:40 +00:00
Ken Tsang
02ee072251 Refactor inbound sms dao
Added function for paginated results
2017-11-07 13:29:40 +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
6e8202522e Merge pull request #1369 from alphagov/default-sms-prefix-true
Default new services to prefixing text messages
2017-11-07 10:46:16 +00:00
Venus Bailey
7aa0976bec Merge pull request #1368 from alphagov/vb-route-secret
initial logging for route protection
2017-11-06 16:31:48 +00:00
venusbb
cae42fe862 Changed logging way 2017-11-06 13:40:20 +00:00
Rebecca Law
c0f7809819 Merge pull request #1366 from alphagov/downgrade-error-msg
Downgrade error message
2017-11-06 13:26:49 +00:00
venusbb
f81b6e9d99 add protection if the parameter route-secret does not exist 2017-11-06 12:27:48 +00:00
venusbb
03fc781b8c create new method to validate secret header, new tests 2017-11-06 11:56:57 +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
venusbb
f4d005c7fb initial logging for route protection 2017-11-03 14:43:56 +00:00
Chris Hill-Scott
ab583c0bc6 Merge pull request #1364 from alphagov/put-sms-prefix-on-model
Work out SMS message prefixing in a way that is aware of multiple SMS senders
2017-11-03 13:35:38 +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
e1239bea06 Use model to work out whether to prefix message
`service.sms_sender` has been deprecated; we should be looking at which
of the service’s SMS senders is default to work out if the message
has been sent from GOVUK or not (and if it has, then prefix the message
with the service name).

The arguments to `SMSMessageTemplate` are _super_ badly named – `sender`
isn’t really used as a string, it’s a boolean that effectively means
‘is this a custom sender (`True`) or the platform default (`False`)’. We
should rename it once this bug is fixed.
2017-11-03 12:28:43 +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
168231f3ce Downgrade the error message to a warning. 2017-11-03 12:09:20 +00:00
venusbb
bdc24dbf0e Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-free-sms-limit-history 2017-11-03 11:50:22 +00:00
venusbb
0f0110a1d1 removed printout of route secret 2017-11-03 10:41:53 +00:00
Rebecca Law
efe0f3b99b Downgrade error to warning 2017-11-03 10:15:09 +00:00