mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 10:03:21 -04:00
Add email auth platform admin toggle
also added tests to check visibility, url, and button content
This commit is contained in:
@@ -302,6 +302,14 @@ def service_switch_can_send_sms(service_id):
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/email-auth")
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
def service_switch_email_auth(service_id):
|
||||
switch_service_permissions(service_id, 'email_auth')
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/archive", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
|
||||
@@ -261,6 +261,11 @@
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="bottom-gutter">
|
||||
<a href="{{ url_for('.service_switch_email_auth', service_id=current_service.id) }}" class="button">
|
||||
{{ 'Stop email auth' if 'email_auth' in current_service.permissions else 'Allow email auth' }}
|
||||
</a>
|
||||
</li>
|
||||
{% if current_service.active %}
|
||||
<li class="bottom-gutter">
|
||||
<a href="{{ url_for('.archive_service', service_id=current_service.id) }}" class="button">
|
||||
@@ -272,8 +277,7 @@
|
||||
Suspend service
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if not current_service.active %}
|
||||
{% else %}
|
||||
<li class="bottom-gutter">
|
||||
<a href="{{ url_for('.resume_service', service_id=current_service.id) }}" class="button">
|
||||
Resume service
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import pytest
|
||||
from flask import url_for
|
||||
|
||||
from tests.conftest import client_request as client_request_factory
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platform_admin_request(logged_in_platform_admin_client):
|
||||
return client_request_factory(logged_in_platform_admin_client)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('service_fields, endpoint, kwargs, text', [
|
||||
({'restricted': True}, '.service_switch_live', {}, 'Make service live'),
|
||||
({'restricted': False}, '.service_switch_live', {}, 'Revert service to trial mode'),
|
||||
|
||||
({'research_mode': True}, '.service_switch_research_mode', {}, 'Take service out of research mode'),
|
||||
({'research_mode': False}, '.service_switch_research_mode', {}, 'Put into research mode'),
|
||||
|
||||
({'permissions': ['email']}, '.service_switch_can_send_email', {}, 'Stop sending emails'),
|
||||
({'permissions': []}, '.service_switch_can_send_email', {}, 'Allow to send emails'),
|
||||
|
||||
({'permissions': ['letter']}, '.service_switch_can_send_letters', {}, 'Stop sending letters'),
|
||||
({'permissions': []}, '.service_switch_can_send_letters', {}, 'Allow to send letters'),
|
||||
|
||||
({'permissions': ['sms']}, '.service_switch_can_send_sms', {}, 'Stop sending sms'),
|
||||
({'permissions': []}, '.service_switch_can_send_sms', {}, 'Allow to send sms'),
|
||||
|
||||
({'permissions': ['sms', 'inbound_sms']}, '.service_set_inbound_number', {'set_inbound_sms': False}, 'Stop inbound sms'), # noqa
|
||||
({'permissions': ['sms']}, '.service_set_inbound_number', {'set_inbound_sms': True}, 'Allow inbound sms'),
|
||||
|
||||
({'active': True}, '.archive_service', {}, 'Archive service'),
|
||||
({'active': True}, '.suspend_service', {}, 'Suspend service'),
|
||||
({'active': False}, '.resume_service', {}, 'Resume service'),
|
||||
])
|
||||
def test_service_setting_toggles_show(platform_admin_request, service_one, service_fields, endpoint, kwargs, text):
|
||||
button_url = url_for(endpoint, **kwargs, service_id=service_one['id'])
|
||||
service_one.update(service_fields)
|
||||
page = platform_admin_request.get('main.service_settings', service_id=service_one['id'])
|
||||
assert page.find('a', {'class': 'button', 'href': button_url}).text.strip() == text
|
||||
|
||||
|
||||
@pytest.mark.parametrize('permissions', [
|
||||
['inbound_sms'], []
|
||||
])
|
||||
def test_service_settings_doesnt_show_inbound_options_if_sms_disabled(platform_admin_request, service_one, permissions):
|
||||
service_one['permissions'] = permissions
|
||||
page = platform_admin_request.get('main.service_settings', service_id=service_one['id'])
|
||||
toggles = page.find_all('a', {'class': 'button'})
|
||||
assert not any(button for button in toggles if 'inbound sms' in button.text)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('service_fields, hidden_button_text', [
|
||||
# if no sms permission, inbound sms shouldn't show
|
||||
({'permissions': ['inbound_sms']}, 'Stop inbound sms'),
|
||||
({'permissions': []}, 'Allow inbound sms'),
|
||||
|
||||
# can't archive or suspend inactive service. Can't resume active service.
|
||||
({'active': False}, 'Archive service'),
|
||||
({'active': False}, 'Suspend service'),
|
||||
({'active': True}, 'Resume service'),
|
||||
])
|
||||
def test_service_setting_toggles_dont_show(platform_admin_request, service_one, service_fields, hidden_button_text):
|
||||
service_one.update(service_fields)
|
||||
page = platform_admin_request.get('main.service_settings', service_id=service_one['id'])
|
||||
toggles = page.find_all('a', {'class': 'button'})
|
||||
assert not any(button for button in toggles if hidden_button_text in button.text)
|
||||
Reference in New Issue
Block a user