mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Research mode
- adds a new link on service settings page to switch service into/out of research mode - platform admin only - shows an indicator in the footer
This commit is contained in:
@@ -285,6 +285,7 @@ def register_errorhandlers(application):
|
||||
|
||||
@application.errorhandler(HTTPError)
|
||||
def render_http_error(error):
|
||||
application.logger.error("API called failed with status {} message {}".format(error.status_code, error.message))
|
||||
error_code = error.status_code
|
||||
if error_code not in [401, 404, 403, 500]:
|
||||
error_code = 500
|
||||
|
||||
@@ -55,10 +55,10 @@ def service_name_change(service_id):
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def service_name_change_confirm(service_id):
|
||||
|
||||
# Validate password for form
|
||||
def _check_password(pwd):
|
||||
return user_api_client.verify_password(current_user.id, pwd)
|
||||
|
||||
form = ConfirmPasswordForm(_check_password)
|
||||
|
||||
if form.validate_on_submit():
|
||||
@@ -94,7 +94,6 @@ def service_name_change_confirm(service_id):
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def service_request_to_go_live(service_id):
|
||||
|
||||
form = RequestToGoLiveForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
@@ -126,7 +125,7 @@ def service_request_to_go_live(service_id):
|
||||
"Deskpro create ticket request failed with {} '{}'".format(
|
||||
resp.status_code,
|
||||
resp.json())
|
||||
)
|
||||
)
|
||||
abort(500, "Request to go live submission failed")
|
||||
|
||||
flash('We’ve received your request to go live', 'default')
|
||||
@@ -152,6 +151,17 @@ def service_switch_live(service_id):
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/research-mode")
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
def service_switch_research_mode(service_id):
|
||||
service_api_client.update_service_with_properties(
|
||||
service_id,
|
||||
{"research_mode": False if current_service['research_mode'] else True}
|
||||
)
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/status", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
@@ -171,6 +181,7 @@ def service_status_change_confirm(service_id):
|
||||
# Validate password for form
|
||||
def _check_password(pwd):
|
||||
return user_api_client.verify_password(current_user.id, pwd)
|
||||
|
||||
form = ConfirmPasswordForm(_check_password)
|
||||
|
||||
if form.validate_on_submit():
|
||||
@@ -195,7 +206,6 @@ def service_status_change_confirm(service_id):
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def service_delete(service_id):
|
||||
|
||||
if request.method == 'GET':
|
||||
return render_template(
|
||||
'views/service-settings/delete.html'
|
||||
@@ -208,10 +218,10 @@ def service_delete(service_id):
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def service_delete_confirm(service_id):
|
||||
|
||||
# Validate password for form
|
||||
def _check_password(pwd):
|
||||
return user_api_client.verify_password(current_user.id, pwd)
|
||||
|
||||
form = ConfirmPasswordForm(_check_password)
|
||||
|
||||
if form.validate_on_submit():
|
||||
|
||||
@@ -6,7 +6,6 @@ from app.notify_client import _attach_current_user
|
||||
|
||||
|
||||
class ServiceAPIClient(NotificationsAPIClient):
|
||||
|
||||
# Fudge assert in the super __init__ so
|
||||
# we can set those variables later.
|
||||
def __init__(self):
|
||||
@@ -81,6 +80,11 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
endpoint = "/service/{0}".format(service_id)
|
||||
return self.post(endpoint, data)
|
||||
|
||||
def update_service_with_properties(self, service_id, properties):
|
||||
_attach_current_user(properties)
|
||||
endpoint = "/service/{0}".format(service_id)
|
||||
return self.post(endpoint, properties)
|
||||
|
||||
def remove_user_from_service(self, service_id, user_id):
|
||||
"""
|
||||
Remove a user from a service
|
||||
@@ -181,7 +185,6 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
|
||||
|
||||
class ServicesBrowsableItem(BrowsableItem):
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return self._item['name']
|
||||
|
||||
@@ -111,6 +111,9 @@
|
||||
<nav class="footer-nav">
|
||||
Built by the <a href="https://www.gov.uk/government/organisations/government-digital-service">Government Digital Service</a>
|
||||
<a href="{{ url_for("main.cookies") }}">Cookies</a>
|
||||
{% if current_service.research_mode %}
|
||||
<span id="research-mode" style="font-weight: bold; display: inline-block; padding: 5px 10px; background: #005EA5; color: #fff; border-radius: 2px;">research mode</span>
|
||||
{% endif %}
|
||||
</nav>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -40,6 +40,14 @@
|
||||
'link': url_for('.service_switch_live', service_id=current_service.id)
|
||||
} if not current_service.restricted and current_user.has_permissions([], admin_override=True) else {
|
||||
},
|
||||
{
|
||||
'title': 'Put service into research mode',
|
||||
'link': url_for('.service_switch_research_mode', service_id=current_service.id)
|
||||
} if not current_service.research_mode and current_user.has_permissions([], admin_override=True) else {
|
||||
'title': 'Take service out of research mode',
|
||||
'link': url_for('.service_switch_research_mode', service_id=current_service.id)
|
||||
} if current_service.research_mode and current_user.has_permissions([], admin_override=True) else {
|
||||
},
|
||||
]) }}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user