Archive, don’t delete contact lists

So we keep a record of who first uploaded a list it’s better to archive
a list than completely delete it.

The list in the database doesn’t contain any recipient info so this
isn’t a change to what data we’re retaining.

This means updating the endpoints that get contact lists to exclude ones
that are archived.
This commit is contained in:
Chris Hill-Scott
2020-03-26 11:38:04 +00:00
parent 4a6143aeb1
commit 5fe0fafadf
9 changed files with 77 additions and 25 deletions

View File

@@ -135,14 +135,6 @@ def dao_update_job(job):
db.session.commit()
def dao_unlink_jobs_from_contact_list_id(contact_list_id):
Job.query.filter(
Job.contact_list_id == contact_list_id,
).update({
'contact_list_id': None,
})
def dao_get_jobs_older_than_data_retention(notification_types):
flexible_data_retention = ServiceDataRetention.query.filter(
ServiceDataRetention.notification_type.in_(notification_types)

View File

@@ -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()
)
@@ -25,6 +27,7 @@ def save_service_contact_list(service_contact_list):
db.session.commit()
def dao_delete_contact_list(service_contact_list):
db.session.delete(service_contact_list)
def dao_archive_contact_list(service_contact_list):
service_contact_list.archived = True
db.session.add(service_contact_list)
db.session.commit()

View File

@@ -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)

View File

@@ -30,7 +30,6 @@ from app.dao.fact_notification_status_dao import (
fetch_stats_for_all_services_by_date_range, fetch_monthly_template_usage_for_service
)
from app.dao.inbound_numbers_dao import dao_allocate_number_for_service
from app.dao.jobs_dao import dao_unlink_jobs_from_contact_list_id
from app.dao.organisation_dao import dao_get_organisation_by_service_id
from app.dao.returned_letters_dao import (
fetch_most_recent_returned_letter,
@@ -39,10 +38,10 @@ from app.dao.returned_letters_dao import (
fetch_returned_letters,
)
from app.dao.service_contact_list_dao import (
dao_archive_contact_list,
dao_get_contact_lists,
save_service_contact_list,
dao_get_contact_list_by_id,
dao_delete_contact_list,
save_service_contact_list,
)
from app.dao.service_data_retention_dao import (
fetch_service_data_retention,
@@ -1046,8 +1045,7 @@ def delete_contact_list_by_id(service_id, contact_list_id):
service_id=service_id,
contact_list_id=contact_list_id,
)
dao_unlink_jobs_from_contact_list_id(contact_list.id)
dao_delete_contact_list(contact_list)
dao_archive_contact_list(contact_list)
s3.remove_contact_list_from_s3(service_id, contact_list_id)
return '', 204