mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
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:
@@ -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:
|
||||
|
||||
@@ -8,6 +8,7 @@ from sqlalchemy.orm.exc import NoResultFound
|
||||
from marshmallow import ValidationError
|
||||
from jsonschema import ValidationError as JsonSchemaValidationError
|
||||
from app.authentication.auth import AuthError
|
||||
from app.exceptions import ArchiveValidationError
|
||||
|
||||
|
||||
class VirusScanError(Exception):
|
||||
@@ -67,6 +68,11 @@ def register_errors(blueprint):
|
||||
current_app.logger.info(error)
|
||||
return jsonify(json.loads(error.message)), 400
|
||||
|
||||
@blueprint.errorhandler(ArchiveValidationError)
|
||||
def archive_validation_error(error):
|
||||
current_app.logger.info(error)
|
||||
return jsonify(result='error', message=str(error)), 400
|
||||
|
||||
@blueprint.errorhandler(InvalidRequest)
|
||||
def invalid_data(error):
|
||||
response = jsonify(error.to_dict())
|
||||
|
||||
@@ -6,3 +6,7 @@ class DVLAException(Exception):
|
||||
class NotificationTechnicalFailureException(Exception):
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
|
||||
class ArchiveValidationError(Exception):
|
||||
pass
|
||||
|
||||
@@ -52,6 +52,7 @@ from app.dao.service_whitelist_dao import (
|
||||
)
|
||||
from app.dao.service_email_reply_to_dao import (
|
||||
add_reply_to_email_address_for_service,
|
||||
archive_reply_to_email_address,
|
||||
dao_get_reply_to_by_id,
|
||||
dao_get_reply_to_by_service_id,
|
||||
update_reply_to_email_address
|
||||
@@ -594,6 +595,13 @@ def update_service_reply_to_email_address(service_id, reply_to_email_id):
|
||||
return jsonify(data=new_reply_to.serialize()), 200
|
||||
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/email-reply-to/<uuid:reply_to_email_id>/archive', methods=['POST'])
|
||||
def delete_service_reply_to_email_address(service_id, reply_to_email_id):
|
||||
archived_reply_to = archive_reply_to_email_address(service_id, reply_to_email_id)
|
||||
|
||||
return jsonify(data=archived_reply_to.serialize()), 200
|
||||
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/letter-contact', methods=["GET"])
|
||||
def get_letter_contacts(service_id):
|
||||
result = dao_get_letter_contacts_by_service_id(service_id)
|
||||
|
||||
Reference in New Issue
Block a user