Refactor and fix auth errors

This commit is contained in:
Ken Tsang
2017-03-22 10:54:15 +00:00
parent b81d789307
commit 8e5266e89b
4 changed files with 16 additions and 11 deletions

View File

@@ -147,17 +147,22 @@ def register_blueprint(application):
def register_v2_blueprints(application): def register_v2_blueprints(application):
from app.v2.notifications.post_notifications import notification_blueprint as post_notifications from app.v2.notifications.post_notifications import v2_notification_blueprint as post_notifications
from app.v2.notifications.get_notifications import notification_blueprint as get_notifications from app.v2.notifications.get_notifications import v2_notification_blueprint as get_notifications
from app.v2.template.get_template import template_blueprint as get_template from app.v2.template.get_template import v2_template_blueprint as get_template
from app.v2.template.post_template import template_blueprint as post_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) post_notifications.before_request(requires_auth)
application.register_blueprint(post_notifications) application.register_blueprint(post_notifications)
get_notifications.before_request(requires_auth) get_notifications.before_request(requires_auth)
application.register_blueprint(get_notifications) application.register_blueprint(get_notifications)
get_template.before_request(requires_auth)
application.register_blueprint(get_template) application.register_blueprint(get_template)
post_template.before_request(requires_auth)
application.register_blueprint(post_template) application.register_blueprint(post_template)

View File

@@ -2,6 +2,6 @@ from flask import Blueprint
from app.v2.errors import register_errors 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)

View File

@@ -7,12 +7,12 @@ from werkzeug.exceptions import abort
from app import api_user from app import api_user
from app.dao import templates_dao from app.dao import templates_dao
from app.schema_validation import validate 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 from app.v2.template.template_schemas import get_template_by_id_request
@template_blueprint.route("/<template_id>", methods=['GET']) @v2_template_blueprint.route("/<template_id>", methods=['GET'])
@template_blueprint.route("/<template_id>/version/<int:version>", methods=['GET']) @v2_template_blueprint.route("/<template_id>/version/<int:version>", methods=['GET'])
def get_template_by_id(template_id, version=None): def get_template_by_id(template_id, version=None):
try: try:
_data = {} _data = {}

View File

@@ -9,11 +9,11 @@ from app.dao import templates_dao
from app.schema_validation import validate from app.schema_validation import validate
from app.utils import get_template_instance from app.utils import get_template_instance
from app.v2.errors import BadRequestError 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 from app.v2.template.template_schemas import post_template_preview_request, create_post_template_preview_response
@template_blueprint.route("/<template_id>/preview", methods=['POST']) @v2_template_blueprint.route("/<template_id>/preview", methods=['POST'])
def post_template_preview(template_id): def post_template_preview(template_id):
try: try:
_data = request.get_json() _data = request.get_json()