POST /service/{id}/deactivate deactivates a service:

* set active=False on the service
* renames service to "_archived_{old_name}"
* archives all templates for the service
* revokes all api keys for the service
This commit is contained in:
Leo Hemsted
2016-11-01 16:09:55 +00:00
parent da2fa5b4bc
commit 089ac099f3
2 changed files with 101 additions and 0 deletions

View File

@@ -32,6 +32,9 @@ from app.dao.service_whitelist_dao import (
dao_add_and_commit_whitelisted_contacts,
dao_remove_service_whitelist
)
from app.dao.templates_dao import (
dao_update_template
)
from app.dao import notifications_dao
from app.dao.provider_statistics_dao import get_fragment_count
from app.dao.users_dao import get_model_users
@@ -312,6 +315,29 @@ def update_whitelist(service_id):
return '', 204
@service_blueprint.route('/<uuid:service_id>/deactivate', methods=['POST'])
def deactivate_service(service_id):
service = dao_fetch_service_by_id(service_id)
if not service.active:
# assume already inactive, don't change service name
return '', 204
service.active = False
service.name = '_archived_' + service.name
service.email_from = '_archived_' + service.email_from
dao_update_service(service)
for template in service.templates:
template.archived = True
dao_update_template(template)
for api_key in service.api_keys:
expire_api_key(service.id, api_key.id)
return '', 204
@service_blueprint.route('/<uuid:service_id>/billable-units')
def get_billable_unit_count(service_id):
try: