diff --git a/swh/web/ui/templates/search.html b/swh/web/ui/templates/search.html --- a/swh/web/ui/templates/search.html +++ b/swh/web/ui/templates/search.html @@ -99,7 +99,7 @@ From text input {% endif %} {% if res['found'] %} - {{ res['sha1'] }} + {{ res['sha1'] }} {% else %} {{ res['sha1'] }} diff --git a/swh/web/ui/views/browse.py b/swh/web/ui/views/browse.py --- a/swh/web/ui/views/browse.py +++ b/swh/web/ui/views/browse.py @@ -6,6 +6,10 @@ from encodings.aliases import aliases from flask import render_template, request, url_for, redirect +from werkzeug.exceptions import BadRequest + +from functools import wraps + from flask.ext.api.decorators import set_renderers from flask.ext.api.renderers import HTMLRenderer @@ -18,6 +22,26 @@ hash_filter_keys = ALGORITHMS +class arg_checker(object): + """ + Check argument names provided. If they are not present or None, + then the client sent a request with missing arguments, so we return + a 400 BAD REQUEST + """ + def __init__(self, *name_check): + self.name_check = name_check + + def __call__(self, func): + @wraps(func) + def wrapped_func(*func_args, **func_kwargs): + print(app) + for arg in self.name_check: + if func_kwargs.get(arg) is None: + return BadRequest() + return func(*func_args, **func_kwargs) + return wrapped_func + + @app.route('/search/', methods=['GET', 'POST']) @set_renderers(HTMLRenderer) def search(): @@ -38,7 +62,6 @@ TODO: Batch-process with all checksums, not just sha1 """ - env = {'search_res': None, 'search_stats': None, 'message': []} @@ -74,7 +97,6 @@ return render_template('search.html', **env) -@app.route('/browse/content/') @app.route('/browse/content//') @set_renderers(HTMLRenderer) def browse_content(q): @@ -192,7 +214,6 @@ return render_template('content-with-origin.html', **env) -@app.route('/browse/directory/') @app.route('/browse/directory//') @app.route('/browse/directory///') @set_renderers(HTMLRenderer) @@ -239,7 +260,6 @@ return render_template('directory.html', **env) -@app.route('/browse/origin/') @app.route('/browse/origin//') @set_renderers(HTMLRenderer) def browse_origin(origin_id): @@ -263,7 +283,6 @@ return render_template('origin.html', **env) -@app.route('/browse/person/') @app.route('/browse/person//') @set_renderers(HTMLRenderer) def browse_person(person_id): @@ -282,7 +301,6 @@ return render_template('person.html', **env) -@app.route('/browse/release/') @app.route('/browse/release//') @set_renderers(HTMLRenderer) def browse_release(sha1_git): @@ -302,7 +320,6 @@ return render_template('release.html', **env) -@app.route('/browse/revision/') @app.route('/browse/revision//') @app.route('/browse/revision//prev//') @set_renderers(HTMLRenderer) @@ -323,7 +340,6 @@ Example: GET /browse/revision/ """ - env = {'sha1_git': sha1_git, 'message': None, 'revision': None} @@ -333,7 +349,6 @@ env['revision'] = utils.prepare_data_for_view(rev) except (NotFoundExc, BadInputExc) as e: env['message'] = str(e) - return render_template('revision.html', **env) @@ -377,8 +392,6 @@ @app.route('/browse/revision' - '/origin/log/') -@app.route('/browse/revision' '/origin//log/') @app.route('/browse/revision' '/origin/'