Let users archive their own trial mode services

At the moment we have a blanket rule that users can’t archive their own
services, to prevent someone accidentally deleting a real live service,
because that would be Very Bad.

But the tickets we get from users asking us to delete services are for
services they set up when they were just trying out Notify. There’s not
much harm in letting users delete these services, the consequences of
doing so are much lower than those of deleting a live service. And it
should mean fewer support tickets for us to deal with.
This commit is contained in:
Chris Hill-Scott
2019-05-29 16:51:25 +01:00
parent 5e9f70c62c
commit 954f43ae48
6 changed files with 96 additions and 45 deletions

View File

@@ -83,7 +83,7 @@ def test_service_setting_toggles_show(get_service_settings_page, service_one, se
@pytest.mark.parametrize('service_fields, endpoint, index, text', [
({'active': True}, '.archive_service', 0, 'Archive service'),
({'active': True}, '.archive_service', 0, 'Delete this service'),
({'active': True}, '.suspend_service', 1, 'Suspend service'),
({'active': False}, '.resume_service', 0, 'Resume service'),
pytest.param(

View File

@@ -3621,38 +3621,72 @@ def test_service_switch_can_upload_document_lets_contact_details_be_added_and_sh
assert normalize_spaces(page.h1.text) == 'Uploading documents'
@pytest.mark.parametrize('user', (
platform_admin_user,
active_user_with_permissions,
pytest.param(active_user_no_settings_permission, marks=pytest.mark.xfail),
))
def test_archive_service_after_confirm(
logged_in_platform_admin_client,
service_one,
client_request,
mocker,
mock_get_inbound_number_for_service,
mock_get_organisations_and_services_for_user,
user,
fake_uuid,
):
mocked_fn = mocker.patch('app.service_api_client.post', return_value=service_one)
mocked_fn = mocker.patch('app.service_api_client.post')
client_request.login(user(fake_uuid))
page = client_request.post(
'main.archive_service',
service_id=SERVICE_ONE_ID,
_follow_redirects=True,
)
response = logged_in_platform_admin_client.post(url_for('main.archive_service', service_id=service_one['id']))
assert response.status_code == 302
assert response.location == url_for('main.service_settings', service_id=service_one['id'], _external=True)
assert mocked_fn.call_args == call('/service/{}/archive'.format(service_one['id']), data=None)
mocked_fn.assert_called_once_with('/service/{}/archive'.format(SERVICE_ONE_ID), data=None)
assert normalize_spaces(page.select_one('h1').text) == 'Choose service'
assert normalize_spaces(page.select_one('.banner-default-with-tick').text) == (
'service one was deleted'
)
@pytest.mark.parametrize('user', (
platform_admin_user,
active_user_with_permissions,
pytest.param(active_user_no_settings_permission, marks=pytest.mark.xfail),
))
def test_archive_service_prompts_user(
logged_in_platform_admin_client,
service_one,
client_request,
mocker,
single_reply_to_email_address,
single_letter_contact_block,
mock_get_service_organisation,
single_sms_sender,
mock_get_service_settings_page_common,
fake_uuid,
user,
):
mocked_fn = mocker.patch('app.service_api_client.post')
client_request.login(user(fake_uuid))
response = logged_in_platform_admin_client.get(url_for('main.archive_service', service_id=service_one['id']))
settings_page = client_request.get(
'main.archive_service',
service_id=SERVICE_ONE_ID
)
delete_link = settings_page.select('.page-footer-delete-link a')[0]
assert normalize_spaces(delete_link.text) == 'Delete this service'
assert delete_link['href'] == url_for(
'main.archive_service',
service_id=SERVICE_ONE_ID,
)
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert 'Are you sure you want to archive this service?' in page.find('div', class_='banner-dangerous').text
delete_page = client_request.get(
'main.archive_service',
service_id=SERVICE_ONE_ID,
)
assert normalize_spaces(delete_page.select_one('.banner-dangerous').text) == (
'Are you sure you want to delete service one? '
'Theres no way to undo this. '
'Yes, delete'
)
assert mocked_fn.called is False
@@ -3671,7 +3705,7 @@ def test_cant_archive_inactive_service(
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert 'Archive service' not in {a.text for a in page.find_all('a', class_='button')}
assert 'Delete service' not in {a.text for a in page.find_all('a', class_='button')}
def test_suspend_service_after_confirm(