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.
This commit is contained in:
Leo Hemsted
2018-11-08 16:44:57 +00:00
parent e4476b9869
commit d9aa220aa6
6 changed files with 257 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ from app.dao.service_inbound_api_dao import save_service_inbound_api
from app.dao.service_permissions_dao import dao_add_service_permission
from app.dao.service_sms_sender_dao import update_existing_sms_sender_with_inbound_number, dao_update_service_sms_sender
from app.dao.services_dao import dao_create_service
from app.dao.templates_dao import dao_create_template
from app.dao.templates_dao import dao_create_template, dao_update_template
from app.dao.users_dao import save_model_user
from app.models import (
ApiKey,
@@ -137,7 +137,9 @@ def create_template(
subject='Template subject',
content='Dear Sir/Madam, Hello. Yours Truly, The Government.',
reply_to=None,
hidden=False
hidden=False,
archived=False,
folder=None,
):
data = {
'name': template_name or '{} Template Name'.format(template_type),
@@ -146,12 +148,18 @@ def create_template(
'service': service,
'created_by': service.created_by,
'reply_to': reply_to,
'hidden': hidden
'hidden': hidden,
'folder': folder,
}
if template_type != SMS_TYPE:
data['subject'] = subject
template = Template(**data)
dao_create_template(template)
if archived:
template.archived = archived
dao_update_template(template)
return template