moksha/api/widgets/containers/templates/layout_applist.mak | 2 moksha/api/widgets/moksha.py | 29 ++++++ moksha/public/javascript/moksha.js | 55 ++++++++++++- moksha/public/javascript/ui/moksha.ui.tabs.js | 2 setup.py | 2 5 files changed, 86 insertions(+), 4 deletions(-)
New commits: commit ba83263a508529c2127b6434e903f95f55452510 Author: John (J5) Palmieri johnp@redhat.com Date: Wed Feb 18 22:35:41 2009 -0500
make csrf work - all that is left is link rewritting
diff --git a/moksha/api/widgets/containers/templates/layout_applist.mak b/moksha/api/widgets/containers/templates/layout_applist.mak index bf267c4..b2e21bc 100644 --- a/moksha/api/widgets/containers/templates/layout_applist.mak +++ b/moksha/api/widgets/containers/templates/layout_applist.mak @@ -15,7 +15,7 @@ <script type="text/javascript"> <!-- TODO: make this a JS widget --> var ajaxOptions = { - url: "${app['url']}", + url: moksha.csrf_rewrite_url("${app['url']}"), success: function(r, s) { var $panel = $("#${app['id']}"); var $stripped = moksha.filter_resources(r); diff --git a/moksha/api/widgets/moksha.py b/moksha/api/widgets/moksha.py index baff13e..c063860 100644 --- a/moksha/api/widgets/moksha.py +++ b/moksha/api/widgets/moksha.py @@ -17,5 +17,34 @@ # Authors: John (J5) Palmieri johnp@redhat.com from tw.jquery import jquery_js from tw.api import JSLink +from tw.api import Widget +import tg +import pylons + moksha_js = JSLink(modname="moksha", filename='public/javascript/moksha.js', javascript=[jquery_js]) + +class MokshaGlobals(Widget): + javascript = [moksha_js] + template = """<script type="text/javascript"> +moksha_base_url = "${base_url}"; +moksha_csrf_token = "${csrf_token}"; +moksha_userid = "${user_id}"; +</script> +""" + params = ['base_url', 'csrf_token', 'user_id'] + engine_name = 'mako' + + base_url = '/' + csrf_token = '' + user_id = '' + + def update_params(self, d): + super(MokshaGlobals, self).update_params(d) + d['base_url'] = tg.url('/') + identity = pylons.request.environ.get('repoze.who.identity') + + if identity: + d['csrf_token'] = identity.get('_csrf_token','') + d['user_id'] = identity.get('user_id', '') + diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js index d4a977b..ba98362 100644 --- a/moksha/public/javascript/moksha.js +++ b/moksha/public/javascript/moksha.js @@ -87,7 +87,60 @@ moksha = { var $f = moksha.filter_scripts(fragment);
return $f; - } + }, + + /******************************************************************** + * Take a url and attach the csrf hash if available + ********************************************************************/ + csrf_rewrite_url: function(url) { + if (typeof(moksha_csrf_token) === 'undefined' || !moksha_csrf_token) + return url; + + var ourl = moksha.parseUri(url); + + var proto = ourl.protocol; + if (proto) + proto += '://'; + var newurl = proto + ourl.authority + ourl.path; + newurl += '?' + ourl.query + '&_csrf_token=' + moksha_csrf_token; + newurl += '#' + ourl.anchor; + + return newurl; + + }, + + /* + * modified from parseUri 1.2.1 Steven Levithan <stevenlevithan.com> + */ + parseUri: function (str) { + var options = { + strictMode: false, + key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], + q: { + name: "queryKey", + parser: /(?:^|&)([^&=]*)=?([^&]*)/g + }, + parser: { + strict: /^(?:([^:/?#]+):)?(?://((?:(([^:@]*):?([^:@]*))?@)?([^:/?#]*)(?::(\d*))?))?((((?:[^?#/]*/)*)([^?#]*))(?:?([^#]*))?(?:#(.*))?)/, + loose: /^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?://)?((?:(([^:@]*):?([^:@]*))?@)?([^:/?#]*)(?::(\d*))?)(((/(?:[^?#](?![^?#/]*.[^?#/.]+(?:[?#]|$)))*/?)?([^?#/]*))(?:?([^#]*))?(?:#(.*))?)/ + } + }; + + var o = options, + m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), + uri = {}, + i = 14; + + while (i--) uri[o.key[i]] = m[i] || ""; + + uri[o.q.name] = {}; + uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { + if ($1) uri[o.q.name][$1] = $2; + }); + + return uri; + }, + }
})(); \ No newline at end of file diff --git a/moksha/public/javascript/ui/moksha.ui.tabs.js b/moksha/public/javascript/ui/moksha.ui.tabs.js index b216610..63ba21b 100644 --- a/moksha/public/javascript/ui/moksha.ui.tabs.js +++ b/moksha/public/javascript/ui/moksha.ui.tabs.js @@ -529,7 +529,7 @@ $.widget("ui.mokshatabs", { url += self.path_remainder;
var ajaxOptions = $.extend({}, o.ajaxOptions, { - url: url, + url: moksha.csrf_rewrite_url(url), success: function(r, s) { var $panel = $(a.hash + ':first', self.element); var $stripped = moksha.filter_resources(r); diff --git a/setup.py b/setup.py index d930a38..9cdee61 100644 --- a/setup.py +++ b/setup.py @@ -79,7 +79,7 @@ setup( orbited = moksha.api.widgets.orbited:orbited_js
jquery = tw.jquery:jquery_js - moksha = moksha.api.widgets.moksha:moksha_js + moksha = moksha.api.widgets.moksha:MokshaGlobals jquery_ui_core = tw.jquery.ui:ui_core_js jquery_ui_draggable = tw.jquery.ui:ui_draggable_min_js jquery_ui_resizable = tw.jquery.ui:ui_resizable_min_js
moksha-commits@lists.fedorahosted.org