Commit Graph

5740 Commits

Author SHA1 Message Date
Rebecca Law
83d720bb7b Change error message, the folder id is not useful infomation to the user. 2018-11-12 15:25:48 +00:00
Katie Smith
d4506f7825 Merge pull request #2210 from alphagov/update-tasks-for-sender-id-part-2
Get and use sender_id from S3 metadata
2018-11-12 11:38:43 +00:00
Katie Smith
d20e35d075 Get and use sender_id from S3 metadata
The `save_email` and `save_sms` jobs were updated previously to take an
optional `sender_id` and to use this if it was available. This commit
now gets the `sender_id` from the S3 metadata if it exists and passes it
through the the tasks which save the job notifications. This means SMS
and emails sent through jobs can use a specified `sender_id` instead of
the default.
2018-11-12 10:59:48 +00:00
Katie Smith
8b5d48b113 Merge pull request #2209 from alphagov/update-tasks-for-sender-id-part-1
Pass sender_id argument to tasks
2018-11-12 10:59:07 +00:00
Katie Smith
30fe41fd43 Pass sender_id argument to tasks
Started passing `sender_id` to the `save_email`, `save_sms` and
`process_job` tasks, with a default value of `None`.

If `sender_id` is provided, the `save_email` and `save_sms` tasks will
use it to determine the reply-to email address or the SMS sender for the
notifications in the job. The `process_job` task will start using the
value in another commit.
2018-11-12 10:49:39 +00:00
Katie Smith
4b23075488 Delete unused parameters from the save_email and save_sms jobs
These both had default arguments of `api_key_id` and `key_type` which
were never being passed in, so these have been removed.
2018-11-12 10:49:39 +00:00
Rebecca Law
5eb4460b11 Merge pull request #2218 from alphagov/move-folders
Move folders and templates to other folders
2018-11-09 16:52:17 +00:00
Rebecca Law
68cea04210 Fixed error message 2018-11-09 16:40:58 +00:00
Rebecca Law
591a2c897a Fix comments 2018-11-09 16:20:06 +00:00
Rebecca Law
63b305441c Add a check that the folder is not moved into itself.
By the way, the database will not let this happen, but this is a nicer error and is explicit to read as an invalid move.
2018-11-09 16:08:33 +00:00
Rebecca Law
1f86796949 Renamed url to /template-folder/<id>/contents, it's a more restful name.
Updated unit tests
Removed redundant logger
2018-11-09 15:54:39 +00:00
Rebecca Law
5df9a307be Merge branch 'master' into move-folders 2018-11-09 15:26:23 +00:00
Rebecca Law
64f7f4c302 Change status code to 204 when there is no content in response. 2018-11-09 14:55:19 +00:00
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
Leo Hemsted
98de2591a7 change aborts to invalidrequest exceptions 2018-11-08 17:21:58 +00:00
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
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