From abb3e7fb24bd7b47bb3bd1a916028aa01e906214 Mon Sep 17 00:00:00 2001 From: LV-426 Date: Fri, 23 Jan 2015 01:18:28 +0200 Subject: rz_api_rest: supply common request context --- src/server/rz_api_rest.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/server') diff --git a/src/server/rz_api_rest.py b/src/server/rz_api_rest.py index 03a83f3a..21c92b58 100644 --- a/src/server/rz_api_rest.py +++ b/src/server/rz_api_rest.py @@ -30,6 +30,18 @@ log = logging.getLogger('rhizi') db_ctl = None # injected: DB controller +def __context__common(): + """ + build a common rquest context to pass along with a kernel diff commit: + - set user_name + """ + + ret = {} + if session.has_key('username'): + ret['user_name'] = session['username'] + + return ret + def diff_commit__topo(): """ REST API wrapper around diff_commit__topo(): @@ -48,9 +60,10 @@ def diff_commit__topo(): except Exception as e: return common_resp_handle(error='malformed input') + ctx = __context__common() try: kernel = flask.current_app.kernel - _, commit_ret = kernel.diff_commit__topo(topo_diff) + _, commit_ret = kernel.diff_commit__topo(topo_diff, ctx) return common_resp_handle(data=commit_ret) except Exception as e: log.error(e.message) @@ -72,9 +85,10 @@ def diff_commit__attr(): # handle DB ERRORS, eg. name attr change error return common_resp_handle(error='error occurred') + ctx = __context__common() try: attr_diff = sanitize_input(request) - validate_obj__attr_diff(attr_diff) + validate_obj__attr_diff(attr_diff, ctx) except Exception as e: return common_resp_handle(error='malformed input') -- cgit v1.3.1