mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 22:40:31 -04:00
Refactored register_errorhandlers so that it handles HTTPError
Remove most cases where we catch HTTPError
This commit is contained in:
@@ -6,6 +6,7 @@ from flask import (Flask, session, Markup, escape, render_template, make_respons
|
|||||||
from flask._compat import string_types
|
from flask._compat import string_types
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
from flask_wtf import CsrfProtect
|
from flask_wtf import CsrfProtect
|
||||||
|
from notifications_python_client import HTTPError
|
||||||
from werkzeug.exceptions import abort
|
from werkzeug.exceptions import abort
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
from pygments.lexers import JavascriptLexer
|
from pygments.lexers import JavascriptLexer
|
||||||
@@ -176,10 +177,10 @@ def useful_headers_after_request(response):
|
|||||||
|
|
||||||
|
|
||||||
def register_errorhandlers(application):
|
def register_errorhandlers(application):
|
||||||
def render_error(error):
|
@application.errorhandler(HTTPError)
|
||||||
# If a HTTPException, pull the `code` attribute; default to 500
|
def render_http_error(error):
|
||||||
error_code = getattr(error, 'code', 500)
|
error_code = getattr(error, 'code', 500)
|
||||||
|
if error_code not in [401, 404, 403, 500]:
|
||||||
|
error_code = 500
|
||||||
resp = make_response(render_template("error/{0}.html".format(error_code)), error_code)
|
resp = make_response(render_template("error/{0}.html".format(error_code)), error_code)
|
||||||
return useful_headers_after_request(resp)
|
return useful_headers_after_request(resp)
|
||||||
for errcode in [401, 404, 403, 500]:
|
|
||||||
application.errorhandler(errcode)(render_error)
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from flask import url_for, abort, current_app
|
from flask import url_for, current_app
|
||||||
from app import notifications_api_client
|
from app import notifications_api_client
|
||||||
from app.utils import BrowsableItem
|
from app.utils import BrowsableItem
|
||||||
from notifications_python_client.errors import HTTPError
|
|
||||||
|
|
||||||
|
|
||||||
def insert_new_service(service_name, user_id):
|
def insert_new_service(service_name, user_id):
|
||||||
@@ -26,15 +25,7 @@ def get_service_by_id(id_):
|
|||||||
|
|
||||||
|
|
||||||
def get_service_by_id_or_404(id_):
|
def get_service_by_id_or_404(id_):
|
||||||
try:
|
return notifications_api_client.get_service(id_)['data']
|
||||||
return notifications_api_client.get_service(id_)['data']
|
|
||||||
except KeyError:
|
|
||||||
abort(404)
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
|
|
||||||
def get_services(user_id=None):
|
def get_services(user_id=None):
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ def get_service_template_or_404(service_id, template_id):
|
|||||||
try:
|
try:
|
||||||
return notifications_api_client.get_service_template(service_id, template_id)
|
return notifications_api_client.get_service_template(service_id, template_id)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
if e.status_code == 404:
|
abort(e.status_code)
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
|
|
||||||
def delete_service_template(service_id, template_id):
|
def delete_service_template(service_id, template_id):
|
||||||
|
|||||||
@@ -16,29 +16,19 @@ from app import job_api_client
|
|||||||
@main.route("/services/<service_id>/dashboard")
|
@main.route("/services/<service_id>/dashboard")
|
||||||
@login_required
|
@login_required
|
||||||
def service_dashboard(service_id):
|
def service_dashboard(service_id):
|
||||||
try:
|
templates = templates_dao.get_service_templates(service_id)['data']
|
||||||
templates = templates_dao.get_service_templates(service_id)['data']
|
jobs = job_api_client.get_job(service_id)['data']
|
||||||
jobs = job_api_client.get_job(service_id)['data']
|
|
||||||
except HTTPError as e:
|
service = get_service_by_id(service_id)
|
||||||
if e.status_code == 404:
|
session['service_name'] = service['data']['name']
|
||||||
abort(404)
|
session['service_id'] = service['data']['id']
|
||||||
else:
|
|
||||||
raise e
|
if session.get('invited_user'):
|
||||||
try:
|
session.pop('invited_user', None)
|
||||||
service = get_service_by_id(service_id)
|
service_name = service['data']['name']
|
||||||
session['service_name'] = service['data']['name']
|
message = 'You have sucessfully accepted your invitation and been added to {}'.format(service_name)
|
||||||
session['service_id'] = service['data']['id']
|
flash(message, 'default_with_tick')
|
||||||
|
|
||||||
if session.get('invited_user'):
|
|
||||||
session.pop('invited_user', None)
|
|
||||||
service_name = service['data']['name']
|
|
||||||
message = 'You have sucessfully accepted your invitation and been added to {}'.format(service_name)
|
|
||||||
flash(message, 'default_with_tick')
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/service_dashboard.html',
|
'views/service_dashboard.html',
|
||||||
jobs=list(reversed(jobs))[:5],
|
jobs=list(reversed(jobs))[:5],
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from flask import (
|
from flask import (
|
||||||
render_template,
|
render_template,
|
||||||
)
|
)
|
||||||
from notifications_python_client.errors import HTTPError
|
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from app.main.forms import ForgotPasswordForm
|
from app.main.forms import ForgotPasswordForm
|
||||||
@@ -12,11 +11,8 @@ from app import user_api_client
|
|||||||
def forgot_password():
|
def forgot_password():
|
||||||
form = ForgotPasswordForm()
|
form = ForgotPasswordForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
try:
|
user_api_client.send_reset_password_url(form.email_address.data)
|
||||||
user_api_client.send_reset_password_url(form.email_address.data)
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code != 404:
|
|
||||||
raise e
|
|
||||||
return render_template('views/password-reset-sent.html')
|
return render_template('views/password-reset-sent.html')
|
||||||
|
|
||||||
return render_template('views/forgot-password.html', form=form)
|
return render_template('views/forgot-password.html', form=form)
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ from flask import (
|
|||||||
redirect,
|
redirect,
|
||||||
url_for,
|
url_for,
|
||||||
session,
|
session,
|
||||||
abort,
|
|
||||||
render_template
|
render_template
|
||||||
)
|
)
|
||||||
|
|
||||||
from notifications_python_client.errors import HTTPError
|
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from app.main.dao.services_dao import get_service_by_id_or_404
|
from app.main.dao.services_dao import get_service_by_id_or_404
|
||||||
@@ -18,32 +16,23 @@ from app import (
|
|||||||
|
|
||||||
@main.route("/invitation/<token>")
|
@main.route("/invitation/<token>")
|
||||||
def accept_invite(token):
|
def accept_invite(token):
|
||||||
|
invited_user = invite_api_client.check_token(token)
|
||||||
|
if invited_user.status == 'cancelled':
|
||||||
|
from_user = user_api_client.get_user(invited_user.from_user)
|
||||||
|
service = get_service_by_id_or_404(invited_user.service)
|
||||||
|
return render_template('views/cancelled-invitation.html',
|
||||||
|
from_user=from_user.name,
|
||||||
|
service_name=service['name'])
|
||||||
|
|
||||||
try:
|
existing_user = user_api_client.get_user_by_email(invited_user.email_address)
|
||||||
|
session['invited_user'] = invited_user.serialize()
|
||||||
|
|
||||||
invited_user = invite_api_client.check_token(token)
|
if existing_user:
|
||||||
if invited_user.status == 'cancelled':
|
|
||||||
from_user = user_api_client.get_user(invited_user.from_user)
|
|
||||||
service = get_service_by_id_or_404(invited_user.service)
|
|
||||||
return render_template('views/cancelled-invitation.html',
|
|
||||||
from_user=from_user.name,
|
|
||||||
service_name=service['name'])
|
|
||||||
|
|
||||||
existing_user = user_api_client.get_user_by_email(invited_user.email_address)
|
user_api_client.add_user_to_service(invited_user.service,
|
||||||
session['invited_user'] = invited_user.serialize()
|
existing_user.id,
|
||||||
|
invited_user.permissions)
|
||||||
if existing_user:
|
invite_api_client.accept_invite(invited_user.service, invited_user.id)
|
||||||
|
return redirect(url_for('main.service_dashboard', service_id=invited_user.service))
|
||||||
user_api_client.add_user_to_service(invited_user.service,
|
else:
|
||||||
existing_user.id,
|
return redirect(url_for('main.register_from_invite'))
|
||||||
invited_user.permissions)
|
|
||||||
invite_api_client.accept_invite(invited_user.service, invited_user.id)
|
|
||||||
return redirect(url_for('main.service_dashboard', service_id=invited_user.service))
|
|
||||||
else:
|
|
||||||
return redirect(url_for('main.register_from_invite'))
|
|
||||||
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|||||||
@@ -20,89 +20,71 @@ from app.main.dao import services_dao
|
|||||||
@main.route("/services/<service_id>/jobs")
|
@main.route("/services/<service_id>/jobs")
|
||||||
@login_required
|
@login_required
|
||||||
def view_jobs(service_id):
|
def view_jobs(service_id):
|
||||||
try:
|
jobs = job_api_client.get_job(service_id)['data']
|
||||||
jobs = job_api_client.get_job(service_id)['data']
|
return render_template(
|
||||||
return render_template(
|
'views/jobs/jobs.html',
|
||||||
'views/jobs/jobs.html',
|
jobs=jobs,
|
||||||
jobs=jobs,
|
service_id=service_id
|
||||||
service_id=service_id
|
)
|
||||||
)
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/jobs/<job_id>")
|
@main.route("/services/<service_id>/jobs/<job_id>")
|
||||||
@login_required
|
@login_required
|
||||||
def view_job(service_id, job_id):
|
def view_job(service_id, job_id):
|
||||||
service = services_dao.get_service_by_id_or_404(service_id)
|
service = services_dao.get_service_by_id_or_404(service_id)
|
||||||
try:
|
job = job_api_client.get_job(service_id, job_id)['data']
|
||||||
job = job_api_client.get_job(service_id, job_id)['data']
|
template = templates_dao.get_service_template_or_404(service_id, job['template'])['data']
|
||||||
template = templates_dao.get_service_template_or_404(service_id, job['template'])['data']
|
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
|
||||||
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
|
finished = job['status'] == 'finished'
|
||||||
finished = job['status'] == 'finished'
|
return render_template(
|
||||||
return render_template(
|
'views/jobs/job.html',
|
||||||
'views/jobs/job.html',
|
notifications=notifications['notifications'],
|
||||||
notifications=notifications['notifications'],
|
counts={
|
||||||
counts={
|
'queued': 0 if finished else job['notification_count'],
|
||||||
'queued': 0 if finished else job['notification_count'],
|
'sent': job['notification_count'] if finished else 0,
|
||||||
'sent': job['notification_count'] if finished else 0,
|
'failed': 0,
|
||||||
'failed': 0,
|
'cost': u'£0.00'
|
||||||
'cost': u'£0.00'
|
},
|
||||||
},
|
uploaded_at=job['created_at'],
|
||||||
uploaded_at=job['created_at'],
|
finished_at=job['updated_at'] if finished else None,
|
||||||
finished_at=job['updated_at'] if finished else None,
|
uploaded_file_name=job['original_file_name'],
|
||||||
uploaded_file_name=job['original_file_name'],
|
template=Template(
|
||||||
template=Template(
|
template,
|
||||||
template,
|
prefix=service['name'] if template['template_type'] == 'sms' else ''
|
||||||
prefix=service['name'] if template['template_type'] == 'sms' else ''
|
),
|
||||||
),
|
service_id=service_id,
|
||||||
service_id=service_id,
|
service=service,
|
||||||
service=service,
|
job_id=job_id
|
||||||
job_id=job_id
|
)
|
||||||
)
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/jobs/<job_id>.json")
|
@main.route("/services/<service_id>/jobs/<job_id>.json")
|
||||||
@login_required
|
@login_required
|
||||||
def view_job_updates(service_id, job_id):
|
def view_job_updates(service_id, job_id):
|
||||||
service = services_dao.get_service_by_id_or_404(service_id)
|
service = services_dao.get_service_by_id_or_404(service_id)
|
||||||
try:
|
job = job_api_client.get_job(service_id, job_id)['data']
|
||||||
job = job_api_client.get_job(service_id, job_id)['data']
|
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
|
||||||
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
|
finished = job['status'] == 'finished'
|
||||||
finished = job['status'] == 'finished'
|
return jsonify(**{
|
||||||
return jsonify(**{
|
'counts': render_template(
|
||||||
'counts': render_template(
|
'partials/jobs/count.html',
|
||||||
'partials/jobs/count.html',
|
counts={
|
||||||
counts={
|
'queued': 0 if finished else job['notification_count'],
|
||||||
'queued': 0 if finished else job['notification_count'],
|
'sent': job['notification_count'] if finished else 0,
|
||||||
'sent': job['notification_count'] if finished else 0,
|
'failed': 0,
|
||||||
'failed': 0,
|
'cost': u'£0.00'
|
||||||
'cost': u'£0.00'
|
}
|
||||||
}
|
),
|
||||||
),
|
'notifications': render_template(
|
||||||
'notifications': render_template(
|
'partials/jobs/notifications.html',
|
||||||
'partials/jobs/notifications.html',
|
notifications=notifications['notifications']
|
||||||
notifications=notifications['notifications']
|
),
|
||||||
),
|
'status': render_template(
|
||||||
'status': render_template(
|
'partials/jobs/status.html',
|
||||||
'partials/jobs/status.html',
|
uploaded_at=job['created_at'],
|
||||||
uploaded_at=job['created_at'],
|
finished_at=job['updated_at'] if finished else None
|
||||||
finished_at=job['updated_at'] if finished else None
|
),
|
||||||
),
|
})
|
||||||
})
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/jobs/<job_id>/notification/<string:notification_id>")
|
@main.route("/services/<service_id>/jobs/<job_id>/notification/<string:notification_id>")
|
||||||
|
|||||||
@@ -11,9 +11,6 @@ from flask_login import (
|
|||||||
current_user
|
current_user
|
||||||
)
|
)
|
||||||
|
|
||||||
from notifications_python_client.errors import HTTPError
|
|
||||||
from app import user_api_client
|
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from app.main.forms import (
|
from app.main.forms import (
|
||||||
InviteUserForm,
|
InviteUserForm,
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ from flask import (
|
|||||||
|
|
||||||
from flask.ext.login import current_user
|
from flask.ext.login import current_user
|
||||||
|
|
||||||
from notifications_python_client.errors import HTTPError
|
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from app.main.dao import users_dao
|
from app.main.dao import users_dao
|
||||||
from app.main.forms import (
|
from app.main.forms import (
|
||||||
@@ -56,17 +54,10 @@ def register_from_invite():
|
|||||||
|
|
||||||
def _do_registration(form, service=None):
|
def _do_registration(form, service=None):
|
||||||
if users_dao.is_email_unique(form.email_address.data):
|
if users_dao.is_email_unique(form.email_address.data):
|
||||||
try:
|
user = user_api_client.register_user(form.name.data,
|
||||||
user = user_api_client.register_user(form.name.data,
|
form.email_address.data,
|
||||||
form.email_address.data,
|
form.mobile_number.data,
|
||||||
form.mobile_number.data,
|
form.password.data)
|
||||||
form.password.data)
|
|
||||||
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
# TODO possibly there should be some exception handling
|
# TODO possibly there should be some exception handling
|
||||||
# for sending sms and email codes.
|
# for sending sms and email codes.
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ from flask import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from notifications_python_client.errors import HTTPError
|
|
||||||
from utils.template import Template
|
from utils.template import Template
|
||||||
from utils.recipients import RecipientCSV, first_column_heading
|
from utils.recipients import RecipientCSV, first_column_heading
|
||||||
|
|
||||||
@@ -80,13 +79,8 @@ def choose_template(service_id, template_type):
|
|||||||
|
|
||||||
if template_type not in ['email', 'sms']:
|
if template_type not in ['email', 'sms']:
|
||||||
abort(404)
|
abort(404)
|
||||||
try:
|
jobs = job_api_client.get_job(service_id)['data']
|
||||||
jobs = job_api_client.get_job(service_id)['data']
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/choose-template.html',
|
'views/choose-template.html',
|
||||||
templates=[
|
templates=[
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ from flask_login import (
|
|||||||
current_user
|
current_user
|
||||||
)
|
)
|
||||||
|
|
||||||
from notifications_python_client.errors import HTTPError
|
|
||||||
|
|
||||||
from app.main.dao.services_dao import (
|
from app.main.dao.services_dao import (
|
||||||
get_service_by_id,
|
get_service_by_id,
|
||||||
delete_service,
|
delete_service,
|
||||||
@@ -31,13 +29,8 @@ from app.main.forms import ConfirmPasswordForm, ServiceNameForm
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings')
|
@user_has_permissions('manage_settings')
|
||||||
def service_settings(service_id):
|
def service_settings(service_id):
|
||||||
try:
|
service = get_service_by_id(service_id)['data']
|
||||||
service = get_service_by_id(service_id)['data']
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/service-settings.html',
|
'views/service-settings.html',
|
||||||
service=service,
|
service=service,
|
||||||
@@ -49,13 +42,7 @@ def service_settings(service_id):
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings')
|
@user_has_permissions('manage_settings')
|
||||||
def service_name_change(service_id):
|
def service_name_change(service_id):
|
||||||
try:
|
service = get_service_by_id(service_id)['data']
|
||||||
service = get_service_by_id(service_id)['data']
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
form = ServiceNameForm()
|
form = ServiceNameForm()
|
||||||
|
|
||||||
@@ -74,13 +61,7 @@ def service_name_change(service_id):
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings')
|
@user_has_permissions('manage_settings')
|
||||||
def service_name_change_confirm(service_id):
|
def service_name_change_confirm(service_id):
|
||||||
try:
|
service = get_service_by_id(service_id)['data']
|
||||||
service = get_service_by_id(service_id)['data']
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
# Validate password for form
|
# Validate password for form
|
||||||
def _check_password(pwd):
|
def _check_password(pwd):
|
||||||
@@ -104,13 +85,7 @@ def service_name_change_confirm(service_id):
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings')
|
@user_has_permissions('manage_settings')
|
||||||
def service_request_to_go_live(service_id):
|
def service_request_to_go_live(service_id):
|
||||||
try:
|
service = get_service_by_id(service_id)['data']
|
||||||
service = get_service_by_id(service_id)['data']
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/service-settings/request-to-go-live.html',
|
'views/service-settings/request-to-go-live.html',
|
||||||
@@ -127,13 +102,7 @@ def service_request_to_go_live(service_id):
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings')
|
@user_has_permissions('manage_settings')
|
||||||
def service_status_change(service_id):
|
def service_status_change(service_id):
|
||||||
try:
|
service = get_service_by_id(service_id)['data']
|
||||||
service = get_service_by_id(service_id)['data']
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return render_template(
|
return render_template(
|
||||||
@@ -149,13 +118,7 @@ def service_status_change(service_id):
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings')
|
@user_has_permissions('manage_settings')
|
||||||
def service_status_change_confirm(service_id):
|
def service_status_change_confirm(service_id):
|
||||||
try:
|
service = get_service_by_id(service_id)['data']
|
||||||
service = get_service_by_id(service_id)['data']
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
# Validate password for form
|
# Validate password for form
|
||||||
def _check_password(pwd):
|
def _check_password(pwd):
|
||||||
@@ -178,13 +141,7 @@ def service_status_change_confirm(service_id):
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings')
|
@user_has_permissions('manage_settings')
|
||||||
def service_delete(service_id):
|
def service_delete(service_id):
|
||||||
try:
|
service = get_service_by_id(service_id)['data']
|
||||||
service = get_service_by_id(service_id)['data']
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return render_template(
|
return render_template(
|
||||||
@@ -200,13 +157,7 @@ def service_delete(service_id):
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings')
|
@user_has_permissions('manage_settings')
|
||||||
def service_delete_confirm(service_id):
|
def service_delete_confirm(service_id):
|
||||||
try:
|
service = get_service_by_id(service_id)['data']
|
||||||
service = get_service_by_id(service_id)['data']
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
# Validate password for form
|
# Validate password for form
|
||||||
def _check_password(pwd):
|
def _check_password(pwd):
|
||||||
@@ -214,13 +165,7 @@ def service_delete_confirm(service_id):
|
|||||||
form = ConfirmPasswordForm(_check_password)
|
form = ConfirmPasswordForm(_check_password)
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
try:
|
service = delete_service(service_id)
|
||||||
service = delete_service(service_id)
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
return redirect(url_for('.choose_service'))
|
return redirect(url_for('.choose_service'))
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
|
|||||||
@@ -2,12 +2,9 @@ from flask import (
|
|||||||
render_template,
|
render_template,
|
||||||
redirect,
|
redirect,
|
||||||
session,
|
session,
|
||||||
url_for,
|
url_for
|
||||||
abort
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from notifications_python_client.errors import HTTPError
|
|
||||||
|
|
||||||
from flask_login import login_user
|
from flask_login import login_user
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
@@ -31,11 +28,6 @@ def verify():
|
|||||||
activated_user = users_dao.activate_user(user)
|
activated_user = users_dao.activate_user(user)
|
||||||
login_user(activated_user)
|
login_user(activated_user)
|
||||||
return redirect(url_for('main.add_service', first='first'))
|
return redirect(url_for('main.add_service', first='first'))
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
finally:
|
finally:
|
||||||
del session['user_details']
|
del session['user_details']
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import json
|
|
||||||
|
|
||||||
from notifications_python_client.notifications import BaseAPIClient
|
from notifications_python_client.notifications import BaseAPIClient
|
||||||
from notifications_python_client.errors import HTTPError
|
from notifications_python_client.errors import HTTPError
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ def test_process_register_creates_new_user(app_,
|
|||||||
assert mock_register_user.called
|
assert mock_register_user.called
|
||||||
|
|
||||||
|
|
||||||
def test_process_register_returns_400_when_mobile_number_is_invalid(app_,
|
def test_process_register_returns_200_when_mobile_number_is_invalid(app_,
|
||||||
mock_send_verify_code,
|
mock_send_verify_code,
|
||||||
mock_get_user_by_email_not_found,
|
mock_get_user_by_email_not_found,
|
||||||
mock_login):
|
mock_login):
|
||||||
|
|||||||
Reference in New Issue
Block a user