mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 18:23:01 -04:00
Merge pull request #2851 from alphagov/archive-service
Allow service to be archived if service with the same name has already been archived
This commit is contained in:
@@ -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:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from app.dao.service_user_dao import dao_get_service_users_by_user_id
|
|||||||
from app.dao.dao_utils import transactional
|
from app.dao.dao_utils import transactional
|
||||||
from app.errors import InvalidRequest
|
from app.errors import InvalidRequest
|
||||||
from app.models import (EMAIL_AUTH_TYPE, User, VerifyCode)
|
from app.models import (EMAIL_AUTH_TYPE, User, VerifyCode)
|
||||||
from app.utils import escape_special_characters
|
from app.utils import escape_special_characters, get_archived_db_column_value
|
||||||
|
|
||||||
|
|
||||||
def _remove_values_for_keys_if_present(dict, keys):
|
def _remove_values_for_keys_if_present(dict, keys):
|
||||||
@@ -161,7 +161,7 @@ def dao_archive_user(user):
|
|||||||
user.organisations = []
|
user.organisations = []
|
||||||
|
|
||||||
user.auth_type = EMAIL_AUTH_TYPE
|
user.auth_type = EMAIL_AUTH_TYPE
|
||||||
user.email_address = get_archived_email_address(user.email_address)
|
user.email_address = get_archived_db_column_value(user.email_address)
|
||||||
user.mobile_number = None
|
user.mobile_number = None
|
||||||
user.password = str(uuid.uuid4())
|
user.password = str(uuid.uuid4())
|
||||||
# Changing the current_session_id signs the user out
|
# Changing the current_session_id signs the user out
|
||||||
@@ -185,8 +185,3 @@ def user_can_be_archived(user):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_archived_email_address(email_address):
|
|
||||||
date = datetime.utcnow().strftime("%Y-%m-%d")
|
|
||||||
return '_archived_{}_{}'.format(date, email_address)
|
|
||||||
|
|||||||
@@ -126,3 +126,8 @@ def get_notification_table_to_use(service, notification_type, process_day, has_d
|
|||||||
days_of_retention += 1
|
days_of_retention += 1
|
||||||
|
|
||||||
return Notification if days_ago <= timedelta(days=days_of_retention) else NotificationHistory
|
return Notification if days_ago <= timedelta(days=days_of_retention) else NotificationHistory
|
||||||
|
|
||||||
|
|
||||||
|
def get_archived_db_column_value(column):
|
||||||
|
date = datetime.utcnow().strftime("%Y-%m-%d")
|
||||||
|
return f'_archived_{date}_{column}'
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user