Commit Graph

5717 Commits

Author SHA1 Message Date
Leo Hemsted
d9aa220aa6 move folders and templates to other folders
new endpoints:
/services/<service_id>/move-to-folder
/services/<service_id>/move-to-folder/<target_template_folder_id>

* takes in a dict containing lists of `templates` and `folders` uuids.
* sets parent of templates and folders to the folder specified in the
  URL. Or None, if there was no id specified.
* if any template or folder has a differen service id, then the whole
  update fails
* if any folder is an ancestor of the target folder, then the whole
  update fails (as that would cause a cyclical folder structure).
* the whole function is wrapped in a single `transactional` decorator,
  so in case of error nothing will be saved.
2018-11-08 17:13:00 +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
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
Leo Hemsted
0d5f8cc7df add status endpoint to '/'
paas were trying to ascertain if notify was up by looking at '/', for cert
renewal. This commit adds the status endpoint to '/', so we're not mistakenly
left for our cert to expire
2018-10-26 18:02:41 +01:00
Leo Hemsted
ac5c19c3d5 remove some pytest warnings 2018-10-26 17:54:53 +01:00
Leo Hemsted
5693d1181e add notify_db_session to test funcs that hit db 2018-10-26 17:51:50 +01: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
6bd3cb1f27 Merge pull request #2189 from alphagov/more-letter-logos
Add ACAS to dvla_org_id table
2018-10-26 15:49:48 +01:00
Katie Smith
cbb4a2c3b2 Add ACAS to dvla_org_id table 2018-10-26 10:33:11 +01:00
Katie Smith
0ce1365305 Merge pull request #2186 from alphagov/make-dvla-table-fields-required
Make name and filename fields of DVLAOrganisation non-nullable
2018-10-25 14:32:12 +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