Commit Graph

4035 Commits

Author SHA1 Message Date
Chris Hill-Scott
b2ba2afbcd List templates in alphabetical order
Currently templates are ordered by the newest created first. This made
sense when, after creating a new template, you were landed on the page
that listed all the templates. In other words, you needed to see
confirmation of the thing that you’ve just done.

Now (since https://github.com/alphagov/notifications-admin/pull/1195)
you get landed on the page for just that template. So you always see
the template you’ve just created, no matter how the list of templates is
ordered. So we are free to change the order of the templates.

Ordering by time created is not great, because it gives users no control
over which templates appear first. For example, our research reported
this from one team:

> One frustration they have is that when you add a new template it
> automatically goes to the top of the list. To get round this, whenever
> they add a new template they delete all of the existing ones and start
> again because they want to keep their templates in numerical order.
> They'd like to be able to control the order of templates in the list.

We _could_ give people some sort of drag-and-drop template ordering
thing. But this feels like overkill. I think that alphabetical order is
better because:

- it’s easily discoverable – anyone who wants to know how a list is
  ordered can quickly tell just by looking at it
- it’s universal – everyone knows how alphabetical ordering works
- it’s familiar – this is how people documents on their computer are
  ordered; there’s no new UI to learn
- it’s what users are doing already – from the same service as above:
  > They number their templates 1,2a, 2b, 3a etc

So this commit changes the ordering from newest created first to
alphabetical.

Previous changes to template order and navigation:
- https://github.com/alphagov/notifications-admin/pull/1163
- https://github.com/alphagov/notifications-admin/pull/1195
- https://github.com/alphagov/notifications-admin/pull/1330

Implementation notes
---

I refactored some of the tests here. I still don’t think they’re great
tests, but they’re a little more Pythonic now at least.

I also added a sort by template type, so that the order is deterministic
when you have, for example, an email template and a text message
template with the same name. If you have two text message templates with
the same name you’re on your own.
2017-11-23 15:11:07 +00:00
Alexey Bezhan
3ad0ac62d4 Merge pull request #1417 from alphagov/fix-template-type-reply-to-order
Fix an intermittent test failure when creating a template with reply_to
2017-11-22 16:27:26 +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
8350a13249 Merge pull request #1415 from alphagov/template-service-letter-contact-id
Allow letter templates to select the default contact block
2017-11-22 15:20:25 +00:00
Alexey Bezhan
7b1f07dd31 Add tests for reading and updating template reply_to through the API 2017-11-22 14:30:44 +00:00
Alexey Bezhan
999afa7e0d Add reply_to to the list of template fields that can change 2017-11-22 14:29:37 +00:00
Alexey Bezhan
dc7bd216bf Add tests for setting reply_to in templates_dao 2017-11-22 14:29:37 +00:00
Alexey Bezhan
f8e1fbe3e6 Add reply_to fields to template schemas
We're hiding the `service_letter_contact_id` column since it should
only be readable and writable using the `.reply_to` wrapper.

Schemas are defined using `fields.Method` since the fields are
represented by a property on the Template model that requires
template type to be set. When creating a template, if `reply_to`
is defined using `fields.String` it gets assigned at the same time
as `template_type` (or the order of assignments is not defined),
so the schema loader attempts to set `.reply_to` on a Template
object with a `None` `template_type`, which raises an exception.

Using `fields.Method` seems to delay `.reply_to` assignment until
the Template object is created, which means it already has a
valid type.
2017-11-22 14:26:04 +00:00
Alexey Bezhan
0be39cc9f9 Add a migration to add template service_letter_contact_id columns 2017-11-22 14:26:04 +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
Alexey Bezhan
559639eb63 Verify that attribute exists on *History model when versioning objects
When createing a history instance of the updated object `create_history`
sets attributes using `setattr`. Since SQLAlchemy model instances are
Python objects they don't prevent new attributes being created by setattr,
which means that if history models are missing some of the columns the
attributes will still be assigned, but their values will not be persisted
by SQLAlchemy since database columns for them do not exist.

To avoid this, we check that the attribute is defined on the `history_cls`
and raise an error if it isn't.
2017-11-22 14:15:58 +00:00
Richard Chapman
a812ae1e6f Merge pull request #1412 from alphagov/rc-monthly-template-usage-endpoint
Template usage always aggregating today's stats
2017-11-22 14:05:58 +00:00
Alexey Bezhan
5279eca052 Merge pull request #1409 from alphagov/add-firetext-inbound-sms-auth
Add FIRETEXT_INBOUND_SMS_AUTH config variable and auth check
2017-11-22 10:41:53 +00:00
Alexey Bezhan
3bcde5437b Add tests for aborting unauthenticated requests
Tests are disabled until aborts are switched on
2017-11-22 09:54:42 +00:00
Alexey Bezhan
5e53d781e0 Add FIRETEXT_INBOUND_SMS_AUTH config variable and auth check
Checks authentication header value on inbound SMS requests from
Firetext against a list of allowed API keys set in the application
config.

At the moment, we're only logging the attempts without aborting the
requests. Once this is rolled out to production and we've checked
the logs we'll switch on the aborts and add the tests for 401 and 403
responses.
2017-11-22 09:54:42 +00:00
Richard Chapman
b453669a7c Added test to ensure todays data isn't aggregated to template usage
The integration tests did test for zero return. Added a method to test
for a year which has no data and also tweaked the existing tests
to ensure they are testing the year more fully.
2017-11-21 16:46:29 +00:00
Richard Chapman
3ac7507f3b Template usage always aggregating today's stats
Added a check to ensure that the current date falls in between the
financial year for the year supplied by the method, so that the todays
stats will only be appended in that situation.
2017-11-21 16:29:20 +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
Richard Chapman
ef9f18a175 Merge pull request #1410 from alphagov/rc-monthly-template-usage-endpoint
Fixed bug in test which was passing but not testing the services_dao properly
2017-11-21 11:33:19 +00:00
Richard Chapman
fa75402a95 Merge pull request #1411 from alphagov/remove-unused-service-columns
Remove email_reply_to and letter_contact_block from Services
2017-11-21 11:33:03 +00:00
Rebecca Law
c80bdbaffe Remove email_reply_to and letter_contact_block from Services 2017-11-21 11:06:07 +00:00
Richard Chapman
f91c0a820f Fixed bug in test which was passing but not testing the services_dao
correctly

The dao_fetch_monthly_historical_usage_by_template_for_service code
wasn't being tested properly due to an bug on the test which created a
notification with the same template and hence was not testing that
a specific service would have a different template id.

- Fixed the bug in the test
- Update services_dao so that the service id check is made
2017-11-21 10:54:08 +00:00
Rebecca Law
adaadefed5 Merge pull request #1408 from alphagov/remove-unused-code
Remove unused code
2017-11-21 10:38:41 +00:00
Rebecca Law
e9db7a1561 Need to do the db migration in the next deploy 2017-11-21 10:22:38 +00:00
Sakis
680487eb20 Merge pull request #1405 from alphagov/bump_utils_2301
Bump utils to 23.0.1
2017-11-21 09:09:28 +00:00
Athanasios Voutsadakis
73dfc67400 Merge branch 'master' into bump_utils_2301 2017-11-20 17:40:45 +00:00
Rebecca Law
1bfc22bbb5 Fix merge conflict for db migration 2017-11-20 17:05:46 +00:00
Rebecca Law
785763a172 Merge branch 'master' into remove-unused-code 2017-11-20 16:56:52 +00:00
Alexey Bezhan
cb92ab7107 Merge pull request #1397 from alphagov/validate-template-history-fk-constraint
Validate notifcations.template_history foreign key constraints
2017-11-20 15:33:45 +00:00
Alexey Bezhan
0a50993fc2 Validate notifcations.template_history foreign key constraints
Removes "NOT VALID" mark from the notifications -> template_history
foreign key constraint by validating existing records.

From postgres docs:

> This form validates a foreign key or check constraint that was
> previously created as NOT VALID, by scanning the table to ensure there
> are no rows for which the constraint is not satisfied. Nothing happens
> if the constraint is already marked valid.

> Validation can be a long process on larger tables. The value of
> separating validation from initial creation is that you can defer
> validation to less busy times, or can be used to give additional time
> to correct pre-existing errors while preventing new errors. Note also
> that validation on its own does not prevent normal write commands
> against the table while it runs.

> Validation acquires only a SHARE UPDATE EXCLUSIVE lock on the table
> being altered. If the constraint is a foreign key then a ROW SHARE
> lock is also required on the table referenced by the constraint.
2017-11-20 15:23:27 +00:00
Rebecca Law
d5a1ec0fe3 Remove unused methods 2017-11-20 14:45:11 +00:00
Rebecca Law
c2648d5c9e Remove Services.reply_to_email_address and Services.letter_contact_block 2017-11-20 14:40:24 +00:00
Rebecca Law
33aab4e1b5 Merge branch 'master' into remove-unused-code 2017-11-20 14:34:52 +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
Rebecca Law
f4ca658d04 Merge pull request #1407 from alphagov/remove-unused-objects
Remove notification_statistics and Service.sms_sender
2017-11-20 14:26:58 +00:00
Rebecca Law
93f19956b8 Remove notification_statistics and Service.sms_sender 2017-11-20 13:13:13 +00:00
Richard Chapman
f3f8225dfe Merge pull request #1406 from alphagov/rc-monthly-template-usage-endpoint
Template usage stats updates for FY usage and bug fix
2017-11-20 11:45:30 +00:00
Athanasios Voutsadakis
a0beb190f3 Merge branch 'master' into bump_utils_2301 2017-11-20 11:16:29 +00:00
Chris Hill-Scott
42bf329593 Merge pull request #1388 from alphagov/pyup-update-sqlalchemy-utils-0.32.19-to-0.32.21
Update sqlalchemy-utils to 0.32.21
2017-11-20 10:26:22 +00:00
Chris Hill-Scott
3f7aca5f78 Merge pull request #1372 from alphagov/sms-prefix-non-nullable
Make SMS prefix setting non-nullable
2017-11-20 10:15:07 +00:00
Richard Chapman
58b0658a13 Return financial year not calendar and ensure double precision values
are not returned from queries

- Updated stats_template_usage_by_month_dao.py to return the results for
financial year not calendar, as the report os for FY only and hence
only the FY data is required
- Updated services_dao.py to ensure double precision values are converted
to an int as the 'exact' function returns double precision from the
database query, as the admin code requires the value for month to be an
int
2017-11-20 10:01:45 +00:00
Venus Bailey
10f3bc24f0 Merge pull request #1404 from alphagov/vb-test-token
Inbound sms pre-implementation test 1
2017-11-20 09:30:50 +00:00
Athanasios Voutsadakis
b0546f4886 Remove unused variable 2017-11-17 16:22:36 +00:00
Chris Hill-Scott
32e19b6552 Bump utils to 23.0.0
Changes arguments to `SMSMessageTemplate` to better describe what they
do.
2017-11-17 16:20:48 +00:00
venusbb
d70fdbb5c2 no auth check 2017-11-17 15:57:41 +00:00
Athanasios Voutsadakis
69e42b7a74 Bump utils to 23.0.1 2017-11-17 15:00:26 +00:00
Leo Hemsted
354d68de88 Merge pull request #1403 from alphagov/fix-research-mode-email-callbacks
Fix research mode email callbacks
2017-11-17 14:48:37 +00:00
venusbb
12a99f9a7f Verify authorisation header being send 2017-11-17 14:36:28 +00:00