diff --git a/app/main/__init__.py b/app/main/__init__.py index 4475482c1..adda9f715 100644 --- a/app/main/__init__.py +++ b/app/main/__init__.py @@ -24,5 +24,6 @@ from app.main.views import ( manage_users, invites, all_services, - tour + tour, + feedback ) diff --git a/app/main/forms.py b/app/main/forms.py index 48fe081f5..81bcb869d 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -313,3 +313,10 @@ class Feedback(Form): name = StringField('Name') email_address = StringField('Email address') feedback = TextAreaField(u'', validators=[DataRequired(message="Can’t be empty")]) + + +class RequestToGoLiveForm(Form): + usage = TextAreaField( + '', + validators=[DataRequired(message="Can’t be empty")] + ) diff --git a/app/main/views/feedback.py b/app/main/views/feedback.py new file mode 100644 index 000000000..3c8a1f080 --- /dev/null +++ b/app/main/views/feedback.py @@ -0,0 +1,42 @@ +import markdown +import requests +from flask import render_template, url_for, redirect, flash, current_app, abort +from app.main import main +from flask_login import login_required +from app.main.forms import Feedback + +from flask.ext.login import current_user + + +@main.route('/feedback', methods=['GET', 'POST']) +def feedback(): + form = Feedback() + if form.validate_on_submit(): + data = { + 'person_email': current_app.config.get('DESKPRO_PERSON_EMAIL'), + 'department_id': current_app.config.get('DESKPRO_TEAM_ID'), + 'subject': 'Notify feedback', + 'message': '{}\n{}\n{}'.format( + form.name.data, + form.email_address.data, + form.feedback.data) + } + headers = { + "X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'), + 'Content-Type': "application/x-www-form-urlencoded" + } + resp = requests.post( + current_app.config.get('DESKPRO_API_HOST') + '/api/tickets', + data=data, + headers=headers) + if resp.status_code != 201: + current_app.logger.error( + "Deskpro create ticket request failed with {} '{}'".format( + resp.status_code, + resp.json()) + ) + abort(500, "Feedback submission failed") + flash("Your feedback has been submitted") + return redirect(url_for('.feedback')) + + return render_template('views/feedback.html', form=form) diff --git a/app/main/views/index.py b/app/main/views/index.py index 198c77913..2c4b7135b 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -1,11 +1,8 @@ import markdown import os -import requests -import json -from flask import (render_template, url_for, redirect, Markup, flash, current_app, abort) +from flask import (render_template, url_for, redirect, Markup, current_app, abort) from app.main import main from flask_login import login_required -from app.main.forms import Feedback from flask.ext.login import current_user from mdx_gfm import GithubFlavoredMarkdownExtension @@ -44,40 +41,6 @@ def terms(): return render_template('views/terms-of-use.html') -@main.route('/feedback', methods=['GET', 'POST']) -def feedback(): - form = Feedback() - if form.validate_on_submit(): - data = { - 'person_email': current_app.config.get('DESKPRO_PERSON_EMAIL'), - 'department_id': current_app.config.get('DESKPRO_TEAM_ID'), - 'subject': 'Notify feedback', - 'message': '{}\n{}\n{}'.format( - form.name.data, - form.email_address.data, - form.feedback.data) - } - headers = { - "X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'), - 'Content-Type': "application/x-www-form-urlencoded" - } - resp = requests.post( - current_app.config.get('DESKPRO_API_HOST') + '/api/tickets', - data=data, - headers=headers) - if resp.status_code != 201: - current_app.logger.error( - "Deskpro create ticket request failed with {} '{}'".format( - resp.status_code, - resp.json()) - ) - abort(500, "Feedback submission failed") - flash("Your feedback has been submitted") - return redirect(url_for('.feedback')) - - return render_template('views/feedback.html', form=form) - - @main.route('/documentation') def documentation(): curr_dir = os.path.dirname(os.path.realpath(__file__)) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index ef8cb6f95..7d68ea6a2 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -1,10 +1,13 @@ +import requests from flask import ( render_template, redirect, request, url_for, session, - flash + flash, + abort, + current_app ) from flask_login import ( @@ -16,7 +19,7 @@ from notifications_python_client.errors import HTTPError from app import service_api_client from app.main import main from app.utils import user_has_permissions, email_safe -from app.main.forms import ConfirmPasswordForm, ServiceNameForm +from app.main.forms import ConfirmPasswordForm, ServiceNameForm, RequestToGoLiveForm from app import user_api_client from app import current_service @@ -86,15 +89,45 @@ 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): - if request.method == 'GET': - return render_template( - 'views/service-settings/request-to-go-live.html' + + form = RequestToGoLiveForm() + + if form.validate_on_submit(): + + data = { + 'person_email': current_app.config.get('DESKPRO_PERSON_EMAIL'), + 'department_id': current_app.config.get('DESKPRO_TEAM_ID'), + 'subject': 'Request to go live', + 'message': "From {} <{}> on behalf of {} ({})\n\nUsage estimate\n---\n\n{}".format( + current_user.name, + current_user.email_address, + current_service['name'], + current_service['id'], + form.usage.data + ) + } + headers = { + "X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'), + 'Content-Type': "application/x-www-form-urlencoded" + } + resp = requests.post( + current_app.config.get('DESKPRO_API_HOST') + '/api/tickets', + data=data, + headers=headers ) - elif request.method == 'POST': - flash('Thanks your request to go live is being processed', 'default') - # TODO implement whatever this action would do in the real world + if resp.status_code != 201: + current_app.logger.error( + "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') return redirect(url_for('.service_settings', service_id=service_id)) + return render_template('views/service-settings/request-to-go-live.html', form=form) + @main.route("/services//service-settings/switch-live") @login_required diff --git a/app/templates/components/textbox.html b/app/templates/components/textbox.html index e849a6bce..40d141072 100644 --- a/app/templates/components/textbox.html +++ b/app/templates/components/textbox.html @@ -1,5 +1,6 @@ {% macro textbox( field, + label=None, hint=False, highlight_tags=False, autofocus=False, @@ -12,7 +13,11 @@ ) %}