Add DAO function and endpoint for archiving email reply_to addresses

Added a new DAO function which archives email reply_to addresses by
setting archived to True. This raises a new type of error, an
ArchiveValidationError, if trying to archive a default reply_to address.

Added a new endpoint for archiving email reply_to addresses.
This commit is contained in:
Katie Smith
2018-04-25 16:34:36 +01:00
parent 663021e494
commit 5f43fe23a7
6 changed files with 111 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ from sqlalchemy import desc
from app import db
from app.dao.dao_utils import transactional
from app.errors import InvalidRequest
from app.exceptions import ArchiveValidationError
from app.models import ServiceEmailReplyTo
@@ -56,6 +57,22 @@ def update_reply_to_email_address(service_id, reply_to_id, email_address, is_def
return reply_to_update
@transactional
def archive_reply_to_email_address(service_id, reply_to_id):
reply_to_archive = ServiceEmailReplyTo.query.filter_by(
id=reply_to_id,
service_id=service_id
).one()
if reply_to_archive.is_default:
raise ArchiveValidationError("You cannot delete a default email reply to address")
reply_to_archive.archived = True
db.session.add(reply_to_archive)
return reply_to_archive
def _get_existing_default(service_id):
existing_reply_to = dao_get_reply_to_by_service_id(service_id=service_id)
if existing_reply_to: