From 8e5266e89bb8deb18f8f052c583b1dbcba789b88 Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Wed, 22 Mar 2017 10:54:15 +0000 Subject: [PATCH] Refactor and fix auth errors --- app/__init__.py | 13 +++++++++---- app/v2/template/__init__.py | 4 ++-- app/v2/template/get_template.py | 6 +++--- app/v2/template/post_template.py | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index f7cecaa9b..f860a0c21 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -147,17 +147,22 @@ def register_blueprint(application): def register_v2_blueprints(application): - from app.v2.notifications.post_notifications import notification_blueprint as post_notifications - from app.v2.notifications.get_notifications import notification_blueprint as get_notifications - from app.v2.template.get_template import template_blueprint as get_template - from app.v2.template.post_template import template_blueprint as post_template + from app.v2.notifications.post_notifications import v2_notification_blueprint as post_notifications + from app.v2.notifications.get_notifications import v2_notification_blueprint as get_notifications + from app.v2.template.get_template import v2_template_blueprint as get_template + from app.v2.template.post_template import v2_template_blueprint as post_template + from app.authentication.auth import requires_auth post_notifications.before_request(requires_auth) application.register_blueprint(post_notifications) get_notifications.before_request(requires_auth) application.register_blueprint(get_notifications) + + get_template.before_request(requires_auth) application.register_blueprint(get_template) + + post_template.before_request(requires_auth) application.register_blueprint(post_template) diff --git a/app/v2/template/__init__.py b/app/v2/template/__init__.py index ad051cfca..32a21d564 100644 --- a/app/v2/template/__init__.py +++ b/app/v2/template/__init__.py @@ -2,6 +2,6 @@ from flask import Blueprint from app.v2.errors import register_errors -template_blueprint = Blueprint("v2_template", __name__, url_prefix='/v2/template') +v2_template_blueprint = Blueprint("v2_template", __name__, url_prefix='/v2/template') -register_errors(template_blueprint) +register_errors(v2_template_blueprint) diff --git a/app/v2/template/get_template.py b/app/v2/template/get_template.py index 794cba614..5ef128b60 100644 --- a/app/v2/template/get_template.py +++ b/app/v2/template/get_template.py @@ -7,12 +7,12 @@ from werkzeug.exceptions import abort from app import api_user from app.dao import templates_dao from app.schema_validation import validate -from app.v2.template import template_blueprint +from app.v2.template import v2_template_blueprint from app.v2.template.template_schemas import get_template_by_id_request -@template_blueprint.route("/", methods=['GET']) -@template_blueprint.route("//version/", methods=['GET']) +@v2_template_blueprint.route("/", methods=['GET']) +@v2_template_blueprint.route("//version/", methods=['GET']) def get_template_by_id(template_id, version=None): try: _data = {} diff --git a/app/v2/template/post_template.py b/app/v2/template/post_template.py index 0c2292965..00557a0c2 100644 --- a/app/v2/template/post_template.py +++ b/app/v2/template/post_template.py @@ -9,11 +9,11 @@ from app.dao import templates_dao from app.schema_validation import validate from app.utils import get_template_instance from app.v2.errors import BadRequestError -from app.v2.template import template_blueprint +from app.v2.template import v2_template_blueprint from app.v2.template.template_schemas import post_template_preview_request, create_post_template_preview_response -@template_blueprint.route("//preview", methods=['POST']) +@v2_template_blueprint.route("//preview", methods=['POST']) def post_template_preview(template_id): try: _data = request.get_json()