Commit Graph

584 Commits

Author SHA1 Message Date
Rebecca Law
2cbcf2b805 Fix merge conflicts 2019-03-11 11:43:16 +00:00
Rebecca Law
d43a274562 Merge branch 'master' into remove-fk-to-users 2019-03-11 11:25:17 +00:00
Chris Hill-Scott
98b389baa2 Fix organisation domain migration
Have to drop constraint before dropping columns.
2019-03-08 15:03:00 +00:00
Chris Hill-Scott
d7e03e00d3 Storing more info about an organisation
Currently we have
- a thing in the database called an ‘organisation’ which we don’t use
- the idea of an organisation which we derive from the user’s email
  address and is used to set the default branding for their service and
  determine whether they’ve signed the MOU

We should make these two things into one thing, by storing everything
we know about an organisation against that organisation in the database.
This will be much less laborious than storing it in a YAML file that
needs a deploy every time it’s updated.

An organisation can now have:
- domains which we can use to automatically associate services with it
  (eg anyone whose email address ends in `dwp.gsi.gov.uk` gets services
  they create associated to the DWP organisation)
- default letter branding for any new services
- default email branding for any new services
2019-03-08 13:30:32 +00:00
Rebecca Law
06facb7576 Removing the foreign from to users from Notification_history.
The relationship is not used and it prevents us from deleting users. It would be good to delete users that are never activated.
2019-03-07 17:20:42 +00:00
Chris Hill-Scott
b27bcc1d80 Make consent_to_research nullable
It should be nullable so we can tell whether someone has answered the
question already or not.

No real users have entered data into this column yet, so it’s fine to
wipe it.
2019-03-01 15:21:49 +00:00
Katie Smith
33166f3fb2 Add migration for user_folder_permissions table
Changed the user_to_service mapping table into a model called
ServiceUser. When looking at users who have permission for a folder
we are only interested in users for a particular service, not all users,
so we can use the ServiceUser model to access folder permissions.

Added a user_folder_permissions table which contains the service_id,
user_id and template_folder_id. There are links between
user_folder_permissions and TemplateFolder, and between
user_folder_permissions and ServiceUser.
2019-02-27 11:50:36 +00:00
Pea Tyczynska
211d3741ba Send confirmation emails to users when team manager edits their
email address  or mobile number.
2019-02-26 16:30:29 +00:00
Alexey Bezhan
1d77310fbd Add folder permissions permission
[#163755302](https://www.pivotaltracker.com/story/show/163755302)

Adds a new temporary service permission for enabling folder permission
editing.
2019-02-19 10:23:40 +00:00
Rebecca Law
34e5e9558d Last commit to remove edit_folders. 2019-02-15 14:44:33 +00:00
Rebecca Law
718626f639 Remove all edit_folder permissions from service_permissions 2019-02-15 14:35:34 +00:00
Chris Hill-Scott
7ca62ce4cf Bump migration version 2019-02-15 10:09:44 +00:00
Chris Hill-Scott
f679731af8 Also store consent to research against a service
It makes most sense to collect this at the same time as the estimated
volumes. Which means we need to store it somewhere; we can’t put it
straight into the ticket.
2019-02-15 10:08:22 +00:00
Chris Hill-Scott
ecdf076506 Store anticipated volumes as integers
This will make it easier to do analysis on the data. Almost all users
are submitting data in a numerical format now anyway, because we ask the
question in a sensible way.
2019-02-15 10:08:22 +00:00
Chris Hill-Scott
17e32fa5f6 Add fields to record a service’s estimated volumes
When a service go live we ask people for their estimated sending
volumes. At the moment we only put this in the ticket, and store it in
a spreadsheet.

This means that a service can
- say they want to go live
- say they are sending 100,000 emails per year
- not have created any email templates
- still see ‘create templates’ as ‘completed’ in the go live checklist

If we store this data against the service we can collect it earlier, and
then use it to determine automatically what kind of templates the user
needs to create before their go live checklist can be considered
complete.
2019-02-15 10:08:22 +00:00
Leo Hemsted
06f9e445f7 remove dvla_organisation from database
downgrade re-populates all static data but leaves all services with 001
(HM Government) branding
2019-02-14 14:27:59 +00:00
Rebecca Law
4ce5724bc7 Fix the downgrade of the migration.
By the way I'm not concerned about fixing service.postage data if we have to rollback.
2019-02-13 15:40:08 +00:00
Pea Tyczynska
97b1e034b8 Remove service.postage and choose_postage permission from database
Also change constraint on template postage so it cannot be null for
letters

Also add postage to all letters in template_history to respect new constraint
2019-02-13 11:50:00 +00:00
Pea Tyczynska
6320882876 Make service postage nullable 2019-02-12 12:15:38 +00:00
Rebecca Law
429997e778 Data migration to populate letter_branding and service_letter_branding.
Only service_letter_branding is added where the service.dvla_org_id is not 001 (hm-government)
2019-02-07 14:28:09 +00:00
Pea Tyczynska
ab5fd972b0 Migrate postage into templates_history table 2019-02-05 15:00:53 +00:00
Chris Hill-Scott
cf2d88c87e Squeeze in some letter logos too 2019-02-01 15:11:51 +00:00
Chris Hill-Scott
a04f41d4d8 Give folders to all existing services
Step 2 of 2 of shipping folders.
2019-02-01 15:04:27 +00:00
Pea Tyczynska
c32fdfa008 Set postage for all existing templates to service default 2019-02-01 12:57:38 +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
f11aa55e0b Adding new data models for letter branding. 2019-01-22 17:27:00 +00:00
Rebecca Law
52a1b534ee Add a new data model LETTER_BRANDING to store the letters. Add a new data model SERVICE_LETTER_BRANDING to map the service to the letter brand.
This will replace services.dvla_organisation_id and dvla_organisation.
2019-01-21 13:59:27 +00:00
Chris Hill-Scott
b238512260 Add 5 new letter logos 2019-01-17 17:06:35 +00:00
Rebecca Law
e148eca6ff Drop stats_template_usage_by_month table as it is no longer needed. 2019-01-15 16:55:56 +00:00
Chris Hill-Scott
3559063b91 Add letter logo for North Somerset council 2019-01-11 14:44:23 +00:00
Pea Tyczynska
52a7dcf86c Add choose_postage service permission and add postage to Template 2018-12-14 18:12:26 +00:00
Chris Hill-Scott
16311a8288 Add letter logo for Neath Port Talbot Council 2018-12-14 10:58:07 +00:00
Rebecca Law
21a67556b8 Add an index on notifications for (service_id, created_at) to improve the performance of the notification queries.
We've already performed this update on production since you need to create the index concurrently, which is not allowed from the alembic script. For that reason we are checking if the index exists.
2018-12-12 12:14:49 +00:00
Alexey Bezhan
452924faaf Update jobs archived flag before setting the default value
Running an update before setting the column default value reduces
the time the table is locked (since most rows don't have a NULL
value anymore), but the migration takes slightly longer to run
overall.
2018-11-28 14:38:59 +00:00
Pea Tyczynska
641cb6ec36 Add archived column to jobs table with default value of false 2018-11-28 14:38:59 +00:00
Chris Hill-Scott
20fedb31a9 Add letter logos for Bournemouth and Hants 2018-11-15 14:44:38 +00:00
Chris Hill-Scott
9991b40871 Add Buckinghamshire and Worcestershire letter logos 2018-11-05 10:03:47 +00:00
Leo Hemsted
936c8489b3 add TemplateFolder model
a TemplateFolder has a service, a name, and a parent. Parent is a
nullable foreign key pointing to another TemplateFolder instance. We
don't do any checks here for cyclical or otherwise invalid folder
structures so keep your data clean, folks!

Unsurprisingly, a Template can be part of a TemplateFolder - there's a
mapping class (template_folder_map to avoid giving it a dumb name) -
this mapping table shouldn't be interacted with directly - rather, you
should use the `Template.folder` or `TemplateFolder.templates`
relationship.
2018-10-26 17:50:31 +01:00
Katie Smith
cbb4a2c3b2 Add ACAS to dvla_org_id table 2018-10-26 10:33:11 +01:00
Katie Smith
4c630ba2e2 Make name and filename fields of DVLAOrganisation non-nullable
If either of these fields are null, previewing a letter template won't
work.
2018-10-25 13:27:44 +01:00
Katie Smith
b2c4fc2787 Add edit_folders service permission
This is a temporary permission to allow some services to see and
edit folders before the feature is turned on for everyone.
2018-10-25 11:19:36 +01:00
Pea Tyczynska
e22e7245fe Use sanitised pdfs for sending and handle invalid pdfs, details below:
- pass new, sanitised pdf for sending
- move invalid pdfs to a newly created bucket
- set status fro notifications that failed pdf validation to a new status validation-failed
- adjust existing tests
2018-10-16 17:30:35 +01:00
Katie Smith
52095c9c8c Add filename to dvla_organisation table
Added a filename column to the dvla_organisation table and populated it
with the filenames that are currently hard-coded in template-preview.
The filenames for letter logos are going to be stored in the database,
instead of in template-preview.
2018-10-15 10:37:34 +01:00
Chris Hill-Scott
8f9ee7f7ad Add letter org for Brighton and Hove 2018-10-12 10:36:41 +01:00
Katie Smith
f41e0f05ec Make postage column part of ft_billing primary key
Now that the postage column is populated and there are no null values,
it can be added to the composite primary key of ft_billing.
2018-09-28 16:19:49 +01:00
Katie Smith
0936060f5d Add postage column to ft_billing
Added a new varchar column, postage, to ft_billing. This is nullable and
not part of the composite primary key for now, but this will change
later.
2018-09-28 13:52:10 +01:00
Katie Smith
45e714e694 Update first class letter rate start dates
We want to bring the start dates for first class letter rates forward by
a month so that we don't see billing errors when sending first class letters now.
(The feature will still go live at the planned time - this is to let us test things
beforehand.)
2018-09-28 10:25:44 +01:00
Leo Hemsted
2b354eb5df separate notification postage constraint into three separate commits
we had an issue where the notification postage constraint command ran
into a deadlock, after trying to acquire two exclusive access locks on
large frequently modified/read tables.

To avoid this happening, we've had to split the upgrade script into
three - one script to apply the not-valid constraint to notifications
table, one for notification_history, and a third to validate the two
constraints.

Note: The first two scripts acquire exclusive access locks, but the
third only needs a row by row lock.

since this involves changing the exsiting alembic upgrades, if you've
upgraded your db you'll need to run the following three commands to
revert your database to a previous good state.

```
alter table notifications drop constraint chk_notifications_postage_null;
alter table notification_history drop constraint chk_notification_history_postage_null;
update alembic_version set version_num = '0229_new_letter_rates';
```
2018-09-27 15:20:28 +01:00
Leo Hemsted
3739c573ea fix null check in constraint
There are two fun quirks of postgres/sql that we need to work around:
* any `x = y` where x or y is NULL returns NULL, rather than false.
* check constraints accept NULL or true values as good.

so, the check `postage in ('first', 'second')` returns `null` rather
than `false` when postage is null itself. This surprisingly passes the
check constraint. To get around this, we have to add an explicit not
null check as well.
2018-09-25 16:10:26 +01:00
Leo Hemsted
17612e5446 add postage constraint to notification history
A not valid constraint only checks against new rows, not existing rows.
We can call VALIDATE CONSTRAINT against this new constraint to check
the old rows (which we know are good, having run the command from
74961781). Adding a normal constraint acquires an ACCESS EXCLUSIVE
lock, but validate constraint only needs a SHARE UPDATE EXCLUSIVE lock.

see 9d4b8961 and 0a50993f for more information on marking constraints
as not valid.
2018-09-25 16:10:16 +01:00