Add the date to the service name and email_reply_to when archiving

This copies what we do to a user's email address when archiving the user
by prefixing it with `_archived_{date}`. We already prefixed the
service name and email_reply_to with `_archived`, but this didn't allow
a service with the same name to be archived more than once.
This commit is contained in:
Katie Smith
2020-05-22 09:37:45 +01:00
parent 13f7fecd5b
commit 64cd8f39c2
2 changed files with 19 additions and 7 deletions

View File

@@ -53,7 +53,13 @@ from app.models import (
LETTER_TYPE, LETTER_TYPE,
UPLOAD_LETTERS, UPLOAD_LETTERS,
) )
from app.utils import email_address_is_nhs, escape_special_characters, get_london_midnight_in_utc, midnight_n_days_ago from app.utils import (
email_address_is_nhs,
escape_special_characters,
get_archived_db_column_value,
get_london_midnight_in_utc,
midnight_n_days_ago,
)
DEFAULT_SERVICE_PERMISSIONS = [ DEFAULT_SERVICE_PERMISSIONS = [
SMS_TYPE, SMS_TYPE,
@@ -260,8 +266,8 @@ def dao_archive_service(service_id):
).filter(Service.id == service_id).one() ).filter(Service.id == service_id).one()
service.active = False service.active = False
service.name = '_archived_' + service.name service.name = get_archived_db_column_value(service.name)
service.email_from = '_archived_' + service.email_from service.email_from = get_archived_db_column_value(service.email_from)
for template in service.templates: for template in service.templates:
if not template.archived: if not template.archived:

View File

@@ -6,7 +6,7 @@ from freezegun import freeze_time
from app import db from app import db
from app.models import Service from app.models import Service
from app.dao.services_dao import dao_archive_service from app.dao.services_dao import dao_archive_service, dao_fetch_service_by_id
from app.dao.api_key_dao import expire_api_key from app.dao.api_key_dao import expire_api_key
from app.dao.templates_dao import dao_update_template from app.dao.templates_dao import dao_update_template
@@ -50,9 +50,15 @@ def archived_service(client, notify_db, sample_service):
return sample_service return sample_service
def test_deactivating_service_changes_name_and_email(archived_service): @freeze_time('2018-07-07 12:00:00')
assert archived_service.name == '_archived_Sample service' def test_deactivating_service_changes_name_and_email(client, sample_service):
assert archived_service.email_from == '_archived_sample.service' auth_header = create_authorization_header()
client.post('/service/{}/archive'.format(sample_service.id), headers=[auth_header])
archived_service = dao_fetch_service_by_id(sample_service.id)
assert archived_service.name == '_archived_2018-07-07_Sample service'
assert archived_service.email_from == '_archived_2018-07-07_sample.service'
def test_deactivating_service_revokes_api_keys(archived_service): def test_deactivating_service_revokes_api_keys(archived_service):