This is the first PR in the story to create a suspend service feature.

- Renaming /service/<id>/deactivate to /service/<id>/archive to match language on the UI.
  - Will need to update admin before deleting the deactive service method
- Created dao and endpoint methods to suspend and resume a service.
- I confirm the use of suspend and resume with a couple people on the team, seems to be the right choice.

The idea is that if you archive a service there is no coming back from that.
To suspend a service is marking it as inactive and revoking the api keys. To resume a service is to mark the service as active, the service will need to create new API keys.
It makes sense that if a service is under threat that the API keys should be renewed.

The next PR will update the code to check that the service is active before sending the request or allowing any actions by the service.
This commit is contained in:
Rebecca Law
2017-01-30 16:32:44 +00:00
parent 1d734d3b28
commit 87556687ab
6 changed files with 309 additions and 9 deletions

View File

@@ -22,8 +22,9 @@ from app.dao.services_dao import (
dao_fetch_weekly_historical_stats_for_service,
fetch_todays_total_message_count,
dao_fetch_todays_stats_for_all_services,
fetch_stats_by_date_range_for_all_services
)
fetch_stats_by_date_range_for_all_services,
dao_suspend_service,
dao_resume_service)
from app.dao.users_dao import save_model_user
from app.models import (
NotificationStatistics,
@@ -656,3 +657,25 @@ def test_fetch_stats_by_date_range_for_all_services(notify_db, notify_db_session
assert len(results) == 1
assert results[0] == ('sms', 'created', result_one.service_id, 2)
def test_dao_suspend_service_marks_service_as_inactive_and_expires_api_keys(sample_service, sample_api_key):
dao_suspend_service(sample_service.id)
service = Service.query.get(sample_service.id)
assert not service.active
assert service.name == sample_service.name
api_key = ApiKey.query.get(sample_api_key.id)
assert api_key.expiry_date.date() == datetime.utcnow().date()
def test_dao_resume_service_marks_service_as_active_and_api_keys_are_still_revoked(sample_service, sample_api_key):
dao_suspend_service(sample_service.id)
service = Service.query.get(sample_service.id)
assert not service.active
dao_resume_service(service.id)
assert Service.query.get(service.id).active
api_key = ApiKey.query.get(sample_api_key.id)
assert api_key.expiry_date.date() == datetime.utcnow().date()