Commit Graph

5725 Commits

Author SHA1 Message Date
Pea (Malgorzata Tyczynska)
cd51818dfe Merge pull request #2220 from alphagov/fix_logging_ft
Fix logging for create_nightly_notification_status
2018-11-09 13:27:14 +00:00
Pea Tyczynska
22ad14fcee Fix logging for create_nightly_notification_status 2018-11-09 11:49:49 +00:00
Katie Smith
b1a9c44d2a Merge pull request #2217 from alphagov/delete-template-folders-when-archiving-templates
Remove relationship to folder when archiving a template
2018-11-09 10:18:16 +00:00
Katie Smith
7f918d7c48 Remove relationship to folder when archiving a template
When a template is archived, it should no longer belong to any folder.

If we don’t do this it will make it very hard to delete folders later
(because folders can only be deleted if they have no templates or folders
inside them).

We originally tried to check if the link between a template and folder
should be removed with

`if template.archived and template.folder:`

instead of using `if template.archived:`. However, this caused issues
because checking `template.folder` flushes the session. Since the
session is no longer dirty, the versioning decorator doesn't work as
expected and doesn't create a new row in `TemplateHistory`.
2018-11-08 17:25:45 +00:00
Pea (Malgorzata Tyczynska)
5588ddceb7 Merge pull request #2216 from alphagov/rearrange_nightly_tasks
Rearrange nightly tasks and update ft_notification_status table
2018-11-08 14:30:56 +00:00
Pea Tyczynska
1c4d2c7625 Update existing ft_notification_status data to get rid of repeats 2018-11-08 11:52:40 +00:00
Pea Tyczynska
ca2db56b9d Update ft_notification_status now deletes old version of data
instead of overwriting on top of it
2018-11-08 11:52:40 +00:00
Pea Tyczynska
987445f1bf ft_notification_status now updates data for 4 days back
This was done so when notification is timed out from sending/pending
to temporary_failure, this change has to always be caught
in the ft_notification_status
2018-11-08 11:52:40 +00:00
Rebecca Law
e4476b9869 Merge pull request #2212 from alphagov/add-parent-id-for-create-template
Add parent id for create template
2018-11-08 10:31:16 +00:00
Chris Hill-Scott
8e12ba074e Merge pull request #2215 from alphagov/readme-postgres
Update README.md to reflect Postgres version needed
2018-11-08 09:29:15 +00:00
Rebecca Law
4120525568 Update error from ResultNotFound to InvalidRequest 2018-11-07 17:07:04 +00:00
Pea Tyczynska
992ef259b2 Rearrange nightly tasks to maintain the correct order
Timeout sending notifications updates up to 4 days of notifications
older than 72 hours to correct failure status. It needs to run before
we update ft_notifications_status table. Otherwise the changes
don't get picked up. Notifications deletion tasks have to run
after those jobs in case our users set short data retention
policy.
2018-11-07 16:43:28 +00:00
Rebecca Law
f5de80f195 Fix conflict 2018-11-07 16:39:04 +00:00
Rebecca Law
1e5b990069 Use query to get TemplateFolder by id and service_id 2018-11-07 16:34:51 +00:00
Chris Heathcote
12cbdc550d Update README.md to reflect Postgres version needed
Added note about installing Postgres 9.6
2018-11-07 16:33:22 +00:00
Rebecca Law
1b0b16fa74 Update model and controller to handle parent_folder_id when creating a template.
If the parent_folder_id then check if the folder exists and is for the same service. If it is add the folder to the template model object, the relationship will be persisted when the template is saved. If the folder does not exist or is for a different service, then return a ResultNotFound error.
2018-11-07 16:17:09 +00:00
Rebecca Law
4849ecdf63 Update the template_schema to include a parent_folder_id.
When creating the Tempalte from_json, the folder is passed in. Since some validation should done, as in the folder exists and is for the same service, the folder is passed through to the Tempalte.from_json method.
When the template is persisted so is the relationship to folders.
TODO: If the folder is invalid a specific message should be returned.
2018-11-07 16:17:09 +00:00
Rebecca Law
39198ed67e Using jsonschema for create_template.
Updated jsonschema to Draft7, this allowed a conditional validation on subject, if template_type == 'email' or 'letter' then subject is required.
This version is backward compatible with Draft4.
When creating TempalteRedacted, I've built the dict depending on if the created_by or created_by_id exists.
2018-11-07 16:17:08 +00:00
Rebecca Law
1230495e88 Merge pull request #2213 from alphagov/check-parent-folder-same-service
Check parent folder belongs to the same service
2018-11-07 16:10:39 +00:00
Leo Hemsted
e4ff771ab7 Merge pull request #2214 from alphagov/reqs
bump requirements
2018-11-07 14:46:15 +00:00
Alexey Bezhan
36f41c23e1 Always use both folder and service ID when getting template folder
Currently there aren't any permission checks based on folder IDs in
the admin app or the API, so it's possible for a user to modify the
folder ID to perform operations on folders outside their service.

Our usual way to avoid this is to always use service_id filter when
fetching objects from the database.
2018-11-07 13:51:37 +00:00
Alexey Bezhan
1dbb24065d Ensure that new template folder belongs to the same service as parent
Since template folders are only linked by ID to their parent we need
to check that the parent folder belongs to the same service as the
one being created. Otherwise, admin users could modify parent ID to
create a folder outside their service.

Ideally, this check would be performed by a DB constraint, but since
parent_id can be nullable this is only possible to express using DB
triggers.

Instead, we perform the check in the API endpoint code.
2018-11-07 13:51:37 +00:00
Leo Hemsted
267c4fc07b bump requirements, fix pyflake8 things, unpin botocore/awscli 2018-11-07 13:39:08 +00:00
Pea (Malgorzata Tyczynska)
d46caa184e Merge pull request #2211 from alphagov/fix_notification_statistics_on_dashboard
Fix notification statistics on dashboard
2018-11-06 16:22:00 +00:00
Pea Tyczynska
5d806c2437 Adjust tests to new way of querying for notification stats 2018-11-06 14:40:40 +00:00
Pea Tyczynska
c146b86643 Adjust attribute key names and data types to work with format_statistics 2018-11-06 13:30:37 +00:00
Pea Tyczynska
c37c399741 Add results for notification stats for last 7 days and today 2018-11-06 11:57:08 +00:00
Chris Hill-Scott
d4519544c8 Merge pull request #2207 from alphagov/buckinghamshire-worcestershire
Add Buckinghamshire and Worcestershire letter logos
2018-11-05 10:15:45 +00:00
Chris Hill-Scott
9991b40871 Add Buckinghamshire and Worcestershire letter logos 2018-11-05 10:03:47 +00:00
Rebecca Law
d15de2e753 Merge pull request #2193 from alphagov/fix-failed-statuses
Add new failed stats to statistic counts
2018-11-01 13:19:10 +00:00
Chris Hill-Scott
92dbe86fff Merge pull request #2201 from alphagov/one-off-letters-from-admin-app
Allow the admin app to send one-off letters
2018-11-01 11:40:48 +00:00
Leo Hemsted
51a7a0add7 Merge pull request #2199 from alphagov/template-folder-crud
add template folder CRUD
2018-11-01 10:44:48 +00:00
Chris Hill-Scott
674cdbd265 Allow the admin app to send one-off letters
This commit modifies the code paths the admin app uses to send one off
emails and text messages to also accept letters.

This mostly worked already, the two changes were:
- making sure that one-off letters are processed by the correct task,
  from the correct queue
- one-off letters sent from a service in research mode don’t get put on
  a queue and go straight to `delivered` (because we don’t want to send
  them for real)
2018-10-31 16:48:43 +00:00
Leo Hemsted
fbe34041d6 add template folder CRUD
* create template folder
* rename template folder
* get list of template folders for service (not nested/presented in any
  particular way)
* delete template folder

Also removed `lazy=dynamic` from the `template_folder.templates`
relationship. lazy=dynamic returns a query object (which you can then
filter further). We just want to return the entire fetched list, at
least for now.
2018-10-31 14:28:16 +00:00
Chris Hill-Scott
87017fc3d1 Merge pull request #2197 from alphagov/quis-patch-1
Update description of what the API repo is for
2018-10-31 11:12:55 +00:00
Chris Hill-Scott
f97fa6a31e Merge pull request #2198 from alphagov/quis-patch-2
Document Python version
2018-10-31 11:00:39 +00:00
Pea Tyczynska
8a3dc8e039 Refactor 2018-10-30 17:15:15 +00:00
Pea Tyczynska
9015ffef48 Fetch notification statistics for last 7 days frpm FactNotificationStatus 2018-10-30 16:31:57 +00:00
Rebecca Law
00e7b337df Update unit test to be more realistic with failure types 2018-10-30 16:01:23 +00:00
Chris Hill-Scott
69838919f2 Document Python version 2018-10-30 13:33:56 +00:00
Chris Hill-Scott
f23bd76255 Update description of what the API repo is for 2018-10-30 13:30:46 +00:00
Rebecca Law
a76c2a0695 Merge pull request #2192 from alphagov/exclude-failed-letters-from-billing
Update billing to ignore failed letters.
2018-10-30 09:44:57 +00:00
Rebecca Law
80d02c434b Add validation-failed and virus-scan-failed in the failed counts for stats 2018-10-29 16:57:06 +00:00
Leo Hemsted
f0c61c8f29 Merge pull request #2190 from alphagov/template-folders
add TemplateFolder model
2018-10-29 15:00:49 +00:00
Rebecca Law
8832c6d82f Update billing to ignore failed letters. 2018-10-29 14:02:40 +00:00
Leo Hemsted
7d0fa279a3 eager join folders from the Template object to keep versioning working
The `@version_class` decorator looks at every dirty (modified) model in
the session to work out which new history models to create. However, if
there are dirty items in the session, sqlalchemy might flush to the
database, clearing the whole session.

We ran into problems with the archive service function, which is
versioned for api keys, templates and services. When constructing the
TemplateHistory objects, `history_meta.py::create_history` would call
getattr on `Template.folders`, which would make a database call to join
across to the TemplateFolder objects - this would then flush the dirty
Service object from the session before the ServiceHistory object was
created.

To get around this, we eager load the Template.folder object, joining
on to it automatically when the Template is fetched. That way, it
doesn't make a SELECT mid-way through the version decorator, and the
history is preserved.

Note: This relationship is only on Template, not TemplateHistory - so
we're not doing this join every single time we send a message.
2018-10-29 11:57:24 +00:00
Katie Smith
a86b4bc63b Merge pull request #2191 from alphagov/pyup-update-pytest-3.9.2-to-3.9.3
Update pytest to 3.9.3
2018-10-29 11:10:22 +00:00
Katie Smith
e9909a5026 Merge pull request #2188 from alphagov/bump-utils-30.5.6
Update notifications-utils to 30.5.6
2018-10-29 11:10:05 +00:00
Katie Smith
9ccffb6980 Update notifications-utils to 30.5.6
This brings in the change to email validation which removes obsure white
space from email addresses.
2018-10-29 09:33:55 +00:00
pyup-bot
dd6f4fb64d Update pytest from 3.9.2 to 3.9.3 2018-10-27 19:12:13 +01:00