mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05: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,
|
||||
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 = [
|
||||
SMS_TYPE,
|
||||
@@ -260,8 +266,8 @@ def dao_archive_service(service_id):
|
||||
).filter(Service.id == service_id).one()
|
||||
|
||||
service.active = False
|
||||
service.name = '_archived_' + service.name
|
||||
service.email_from = '_archived_' + service.email_from
|
||||
service.name = get_archived_db_column_value(service.name)
|
||||
service.email_from = get_archived_db_column_value(service.email_from)
|
||||
|
||||
for template in service.templates:
|
||||
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.errors import InvalidRequest
|
||||
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):
|
||||
@@ -161,7 +161,7 @@ def dao_archive_user(user):
|
||||
user.organisations = []
|
||||
|
||||
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.password = str(uuid.uuid4())
|
||||
# Changing the current_session_id signs the user out
|
||||
@@ -185,8 +185,3 @@ def user_can_be_archived(user):
|
||||
return False
|
||||
|
||||
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
|
||||
|
||||
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}'
|
||||
|
||||
Reference in New Issue
Block a user