mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-29 22:58:21 -04:00
Merge pull request #2759 from alphagov/delete-contact-list
Add an endpoint to delete a contact list
This commit is contained in:
@@ -43,6 +43,13 @@ def get_job_location(service_id, job_id):
|
||||
)
|
||||
|
||||
|
||||
def get_contact_list_location(service_id, contact_list_id):
|
||||
return (
|
||||
current_app.config['CONTACT_LIST_BUCKET_NAME'],
|
||||
FILE_LOCATION_STRUCTURE.format(service_id, contact_list_id),
|
||||
)
|
||||
|
||||
|
||||
def get_job_and_metadata_from_s3(service_id, job_id):
|
||||
obj = get_s3_object(*get_job_location(service_id, job_id))
|
||||
return obj.get()['Body'].read().decode('utf-8'), obj.get()['Metadata']
|
||||
@@ -62,6 +69,10 @@ def remove_job_from_s3(service_id, job_id):
|
||||
return remove_s3_object(*get_job_location(service_id, job_id))
|
||||
|
||||
|
||||
def remove_contact_list_from_s3(service_id, contact_list_id):
|
||||
return remove_s3_object(*get_contact_list_location(service_id, contact_list_id))
|
||||
|
||||
|
||||
def get_s3_bucket_objects(bucket_name, subfolder=''):
|
||||
boto_client = client('s3', current_app.config['AWS_REGION'])
|
||||
paginator = boto_client.get_paginator('list_objects_v2')
|
||||
|
||||
@@ -363,6 +363,7 @@ class Development(Config):
|
||||
SQLALCHEMY_ECHO = False
|
||||
|
||||
CSV_UPLOAD_BUCKET_NAME = 'development-notifications-csv-upload'
|
||||
CONTACT_LIST_BUCKET_NAME = 'development-contact-list'
|
||||
TEST_LETTERS_BUCKET_NAME = 'development-test-letters'
|
||||
DVLA_RESPONSE_BUCKET_NAME = 'notify.tools-ftp'
|
||||
LETTERS_PDF_BUCKET_NAME = 'development-letters-pdf'
|
||||
@@ -406,6 +407,7 @@ class Test(Development):
|
||||
HIGH_VOLUME_SERVICE = ['941b6f9a-50d7-4742-8d50-f365ca74bf27']
|
||||
|
||||
CSV_UPLOAD_BUCKET_NAME = 'test-notifications-csv-upload'
|
||||
CONTACT_LIST_BUCKET_NAME = 'test-contact-list'
|
||||
TEST_LETTERS_BUCKET_NAME = 'test-test-letters'
|
||||
DVLA_RESPONSE_BUCKET_NAME = 'test.notify.com-ftp'
|
||||
LETTERS_PDF_BUCKET_NAME = 'test-letters-pdf'
|
||||
@@ -441,6 +443,7 @@ class Preview(Config):
|
||||
NOTIFY_EMAIL_DOMAIN = 'notify.works'
|
||||
NOTIFY_ENVIRONMENT = 'preview'
|
||||
CSV_UPLOAD_BUCKET_NAME = 'preview-notifications-csv-upload'
|
||||
CONTACT_LIST_BUCKET_NAME = 'preview-contact-list'
|
||||
TEST_LETTERS_BUCKET_NAME = 'preview-test-letters'
|
||||
DVLA_RESPONSE_BUCKET_NAME = 'notify.works-ftp'
|
||||
LETTERS_PDF_BUCKET_NAME = 'preview-letters-pdf'
|
||||
@@ -457,6 +460,7 @@ class Staging(Config):
|
||||
NOTIFY_EMAIL_DOMAIN = 'staging-notify.works'
|
||||
NOTIFY_ENVIRONMENT = 'staging'
|
||||
CSV_UPLOAD_BUCKET_NAME = 'staging-notifications-csv-upload'
|
||||
CONTACT_LIST_BUCKET_NAME = 'staging-contact-list'
|
||||
TEST_LETTERS_BUCKET_NAME = 'staging-test-letters'
|
||||
DVLA_RESPONSE_BUCKET_NAME = 'staging-notify.works-ftp'
|
||||
LETTERS_PDF_BUCKET_NAME = 'staging-letters-pdf'
|
||||
@@ -474,6 +478,7 @@ class Live(Config):
|
||||
NOTIFY_EMAIL_DOMAIN = 'notifications.service.gov.uk'
|
||||
NOTIFY_ENVIRONMENT = 'live'
|
||||
CSV_UPLOAD_BUCKET_NAME = 'live-notifications-csv-upload'
|
||||
CONTACT_LIST_BUCKET_NAME = 'production-contact-list'
|
||||
TEST_LETTERS_BUCKET_NAME = 'production-test-letters'
|
||||
DVLA_RESPONSE_BUCKET_NAME = 'notifications.service.gov.uk-ftp'
|
||||
LETTERS_PDF_BUCKET_NAME = 'production-letters-pdf'
|
||||
@@ -498,6 +503,7 @@ class Sandbox(CloudFoundryConfig):
|
||||
NOTIFY_EMAIL_DOMAIN = 'notify.works'
|
||||
NOTIFY_ENVIRONMENT = 'sandbox'
|
||||
CSV_UPLOAD_BUCKET_NAME = 'cf-sandbox-notifications-csv-upload'
|
||||
CONTACT_LIST_BUCKET_NAME = 'cf-sandbox-contact-list'
|
||||
LETTERS_PDF_BUCKET_NAME = 'cf-sandbox-letters-pdf'
|
||||
TEST_LETTERS_BUCKET_NAME = 'cf-sandbox-test-letters'
|
||||
DVLA_RESPONSE_BUCKET_NAME = 'notify.works-ftp'
|
||||
|
||||
@@ -5,7 +5,8 @@ from app.models import ServiceContactList
|
||||
def dao_get_contact_list_by_id(service_id, contact_list_id):
|
||||
contact_list = ServiceContactList.query.filter_by(
|
||||
service_id=service_id,
|
||||
id=contact_list_id
|
||||
id=contact_list_id,
|
||||
archived=False,
|
||||
).one()
|
||||
|
||||
return contact_list
|
||||
@@ -13,7 +14,8 @@ def dao_get_contact_list_by_id(service_id, contact_list_id):
|
||||
|
||||
def dao_get_contact_lists(service_id):
|
||||
contact_lists = ServiceContactList.query.filter_by(
|
||||
service_id=service_id
|
||||
service_id=service_id,
|
||||
archived=False,
|
||||
).order_by(
|
||||
ServiceContactList.created_at.desc()
|
||||
)
|
||||
@@ -23,3 +25,9 @@ def dao_get_contact_lists(service_id):
|
||||
def save_service_contact_list(service_contact_list):
|
||||
db.session.add(service_contact_list)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def dao_archive_contact_list(service_contact_list):
|
||||
service_contact_list.archived = True
|
||||
db.session.add(service_contact_list)
|
||||
db.session.commit()
|
||||
|
||||
@@ -2135,6 +2135,7 @@ class ServiceContactList(db.Model):
|
||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=True)
|
||||
created_at = db.Column(db.DateTime, nullable=False)
|
||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
||||
archived = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
def serialize(self):
|
||||
created_at_in_bst = convert_utc_to_bst(self.created_at)
|
||||
|
||||
@@ -13,6 +13,7 @@ from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import DATE_FORMAT, DATETIME_FORMAT_NO_TIMEZONE
|
||||
from app.aws import s3
|
||||
from app.config import QueueNames
|
||||
from app.dao import fact_notification_status_dao, notifications_dao
|
||||
from app.dao.dao_utils import dao_rollback
|
||||
@@ -36,8 +37,12 @@ from app.dao.returned_letters_dao import (
|
||||
fetch_returned_letter_summary,
|
||||
fetch_returned_letters,
|
||||
)
|
||||
from app.dao.service_contact_list_dao import dao_get_contact_lists, save_service_contact_list, \
|
||||
dao_get_contact_list_by_id
|
||||
from app.dao.service_contact_list_dao import (
|
||||
dao_archive_contact_list,
|
||||
dao_get_contact_lists,
|
||||
dao_get_contact_list_by_id,
|
||||
save_service_contact_list,
|
||||
)
|
||||
from app.dao.service_data_retention_dao import (
|
||||
fetch_service_data_retention,
|
||||
fetch_service_data_retention_by_id,
|
||||
@@ -1034,6 +1039,18 @@ def get_contact_list_by_id(service_id, contact_list_id):
|
||||
return jsonify(contact_list.serialize())
|
||||
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/contact-list/<uuid:contact_list_id>', methods=['DELETE'])
|
||||
def delete_contact_list_by_id(service_id, contact_list_id):
|
||||
contact_list = dao_get_contact_list_by_id(
|
||||
service_id=service_id,
|
||||
contact_list_id=contact_list_id,
|
||||
)
|
||||
dao_archive_contact_list(contact_list)
|
||||
s3.remove_contact_list_from_s3(service_id, contact_list_id)
|
||||
|
||||
return '', 204
|
||||
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/contact-list', methods=['POST'])
|
||||
def create_contact_list(service_id):
|
||||
service_contact_list = validate(request.get_json(), create_service_contact_list_schema)
|
||||
|
||||
Reference in New Issue
Block a user