moksha/connector moksha/public
by John (J5) Palmieri
moksha/connector/connector.py | 2 +-
moksha/public/javascript/moksha.js | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
New commits:
commit a74b20f510b1c9ad22a45cbf8a748b1758913206
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Fri Apr 17 13:27:14 2009 -0400
make sure parameters are sent as keywords in calls
diff --git a/moksha/connector/connector.py b/moksha/connector/connector.py
index a4b00e6..9c47a9d 100644
--- a/moksha/connector/connector.py
+++ b/moksha/connector/connector.py
@@ -81,7 +81,7 @@ class IConnector(object):
if op in ('request_data', 'call', 'query', 'query_model'):
return getattr(self, op)(resource_path, params, _cookies, **kwds)
elif op in self._method_paths:
- return self._method_paths[op](self, resource_path, params, _cookies, **kwds)
+ return self._method_paths[op](self, resource_path, _cookies, **params)
return None
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index da1c4e8..0cd73d8 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -325,6 +325,10 @@ moksha = {
ajax_load: function(path, params, callback, $overlay_div, data_type, loading_icon) {
self = this;
+ if (typeof(params) == 'string') {
+ params = $.secureEvalJSON(params);
+ }
+
var profile_start_time = 0;
if (typeof(moksha_profile)!='undefined' && moksha_profile) {
var date = new Date()
15 years, 2 months
moksha/api moksha/public
by John (J5) Palmieri
moksha/api/widgets/containers/templates/tabbedcontainer_tabs.mak | 2 +-
moksha/public/javascript/ui/moksha.ui.tabs.js | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
New commits:
commit ae0f12dbcb5d24962762e7de715dbba8e6ebf356
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Thu Apr 16 15:37:00 2009 -0400
remove uuid's from the link titles
diff --git a/moksha/api/widgets/containers/templates/tabbedcontainer_tabs.mak b/moksha/api/widgets/containers/templates/tabbedcontainer_tabs.mak
index f40257d..a3991ae 100644
--- a/moksha/api/widgets/containers/templates/tabbedcontainer_tabs.mak
+++ b/moksha/api/widgets/containers/templates/tabbedcontainer_tabs.mak
@@ -17,7 +17,7 @@
% if tab['type'] == 'Category':
${display_category(tab)}
% else:
- <a href="${tab['url']}${tab['query_string']}" title="${tab['content_id']}">
+ <a href="${tab['url']}${tab['query_string']}" title="${tab['label']}" panel="${tab['content_id']}">
${tab['label']}
</a>
% endif
diff --git a/moksha/public/javascript/ui/moksha.ui.tabs.js b/moksha/public/javascript/ui/moksha.ui.tabs.js
index 1c965d5..649624c 100644
--- a/moksha/public/javascript/ui/moksha.ui.tabs.js
+++ b/moksha/public/javascript/ui/moksha.ui.tabs.js
@@ -46,7 +46,9 @@ $.widget("ui.mokshatabs", {
return this.$tabs.length;
},
tabId: function(a) {
- return a.title && a.title.replace(/\s/g, '_').replace(/[^A-Za-z0-9\-_:\.]/g, '')
+ var panel = $(a).attr('panel');
+
+ return panel && panel.replace(/\s/g, '_').replace(/[^A-Za-z0-9\-_:\.]/g, '')
|| this.options.idPrefix + $.data(a);
},
ui: function(tab, panel) {
15 years, 2 months
moksha/api
by Luke Macken
moksha/api/widgets/iframe.py | 10 ++++++++++
1 file changed, 10 insertions(+)
New commits:
commit 9541ef75f9a06516d708a62c13bbfa165bdcb43b
Author: Luke Macken <lmacken(a)redhat.com>
Date: Wed Apr 15 11:19:47 2009 -0400
Add a simple iframe widget
diff --git a/moksha/api/widgets/iframe.py b/moksha/api/widgets/iframe.py
new file mode 100644
index 0000000..74da0ca
--- /dev/null
+++ b/moksha/api/widgets/iframe.py
@@ -0,0 +1,10 @@
+from tw.api import Widget
+
+class IFrameWidget(Widget):
+ params = ['id', 'url']
+ template = """
+ <iframe id="${id}" src="${url}" width="100%" height="100%">
+ <p>Your browser does not support iframes.</p>
+ </iframe>
+ """
+ engine_name = 'mako'
15 years, 2 months
moksha/wsgiapp.py
by Luke Macken
moksha/wsgiapp.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
New commits:
commit 0b5c8294f67e358d0352fa1f1515c111271d46dd
Author: Luke Macken <lmacken(a)redhat.com>
Date: Wed Apr 15 10:02:10 2009 -0400
Prevent the RootController from being imported before our application and configuration are loaded
diff --git a/moksha/wsgiapp.py b/moksha/wsgiapp.py
index 82e6fe9..f8184b6 100644
--- a/moksha/wsgiapp.py
+++ b/moksha/wsgiapp.py
@@ -17,7 +17,6 @@
# Authors: Luke Macken <lmacken(a)redhat.com>
from pylons.wsgiapp import PylonsApp
-from moksha.controllers.root import RootController
class MokshaAppDispatcher(PylonsApp):
""" Moksha WSGI Application Dispatcher.
@@ -30,6 +29,8 @@ class MokshaAppDispatcher(PylonsApp):
def __init__(self):
super(MokshaAppDispatcher, self).__init__()
+ from moksha.controllers.root import RootController
+ self.root = RootController
def resolve(self, environ, start_response):
""" Uses dispatching information found in
@@ -39,4 +40,4 @@ class MokshaAppDispatcher(PylonsApp):
"""
environ['pylons.routes_dict'] = environ['wsgiorg.routing_args'][1]
- return RootController()
+ return self.root()
15 years, 2 months
moksha/middleware
by Luke Macken
moksha/middleware/csrf.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
New commits:
commit 5ba82a3e86863e3cae2edf95f8fa24c378457837
Author: Luke Macken <lmacken(a)redhat.com>
Date: Wed Apr 15 09:19:53 2009 -0400
Don't require the third-party hashlib module, and fallback to the sha module.
It seems that with python2.4 and the third-party hashlib module, there are
some serious problems with TG2/beaker: http://trac.turbogears.org/ticket/2133
diff --git a/moksha/middleware/csrf.py b/moksha/middleware/csrf.py
index 2b87d58..ddab4e1 100644
--- a/moksha/middleware/csrf.py
+++ b/moksha/middleware/csrf.py
@@ -27,7 +27,6 @@ import logging
from tg import config
from webob import Request, Response
-from hashlib import sha1
from paste.request import construct_url
from paste.httpexceptions import HTTPFound
from paste.request import parse_formvars, parse_dict_querystring
@@ -36,6 +35,11 @@ from urlparse import urlparse, urlunparse
from repoze.who.interfaces import IMetadataProvider
from zope.interface import implements
+try:
+ from hashlib import sha1
+except ImportError:
+ from sha import sha as sha1
+
log = logging.getLogger(__name__)
class CSRFProtectionMiddleware(object):
15 years, 2 months
moksha/middleware
by John (J5) Palmieri
moksha/middleware/csrf.py | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
New commits:
commit 58f4e470eb01bead9092f728fc42cf3cbbac6c2c
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Wed Apr 15 10:54:13 2009 -0400
strip the SCRIPT_NAME ennviron from the path when comparing
diff --git a/moksha/middleware/csrf.py b/moksha/middleware/csrf.py
index 956d306..2b87d58 100644
--- a/moksha/middleware/csrf.py
+++ b/moksha/middleware/csrf.py
@@ -80,7 +80,7 @@ class CSRFProtectionMiddleware(object):
URLs can then be re-written using the ``moksha.csrf_rewrite_url`` function
that is in the ``moksha.js`` library, which is automatically pulled in by
the MokshaGlobals widget. Here is an example of adding the CSRF token to
- an ajax. This example also utilizes the ``moksha.filter_resources``
+ an ajax. This example also utilizes the ``moksha.filter_resources``
function to strip out any duplicate javascript files.
.. code-block:: javascript
@@ -211,6 +211,19 @@ class CSRFMetadataProvider(object):
self.auth_session_id = auth_session_id
self.auth_state = auth_state
+ def strip_script(self, environ, path):
+ # Strips the script portion of a url path so the middleware works even
+ # when mounted under a path other than root
+ if path.startswith('/') and 'SCRIPT_NAME' in environ:
+ prefix = environ.get('SCRIPT_NAME')
+ if prefix.endswith('/'):
+ prefix = prefix[:-1]
+
+ if path.startswith(prefix):
+ path = path[len(prefix):]
+
+ return path
+
def add_metadata(self, environ, identity):
request = Request(environ)
log.debug("CSRFMetadataProvider.add_metadata(%s)" % request.path)
@@ -224,7 +237,8 @@ class CSRFMetadataProvider(object):
token = sha1(session_id).hexdigest()
identity.update({self.csrf_token_id: token})
log.debug("Identity updated with CSRF token")
- if request.path == self.login_handler:
+ path = self.strip_script(environ, request.path)
+ if path == self.login_handler:
log.debug('Setting CSRF_AUTH_STATE')
environ[self.auth_state] = True
environ[self.token_env] = token
15 years, 2 months
moksha/lib moksha/public
by John (J5) Palmieri
moksha/lib/helpers.py | 18 ++++++++++-------
moksha/public/javascript/moksha.js | 38 ++++++++++++++++++++++++++++++++-----
2 files changed, 44 insertions(+), 12 deletions(-)
New commits:
commit aed3f829bc77c2d143397d7019d30881451bbb5d
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Tue Apr 14 18:50:46 2009 -0400
add the ability to inject arbitrary fields into forms and http headers
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py
index 4065409..01cc726 100644
--- a/moksha/lib/helpers.py
+++ b/moksha/lib/helpers.py
@@ -732,6 +732,16 @@ def to_unicode(obj, encoding='utf-8'):
obj = unicode(obj, encoding, 'replace')
return obj
+def replace_app_header(app, header_name, value):
+ from paste.response import replace_header
+ if app.headers:
+ headers = list(app.headers)
+ else:
+ headers = []
+
+ replace_header(headers, header_name, value)
+ app.headers = headers
+
class EnumDataObj(dict):
def __init__(self, code, data):
super(EnumDataObj, self).__init__(code=code, data=data)
@@ -746,14 +756,8 @@ class EnumDataObj(dict):
raise e
def replace_app_header(self, app, header_name):
- from paste.response import replace_header
- if app.headers:
- headers = list(app.headers)
- else:
- headers = []
+ replace_app_header(app, header_name, self.code)
- replace_header(headers, header_name, self.code)
- app.headers = headers
def __repr__(self):
# act as if the user requested the code
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index 7cfab76..da1c4e8 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -170,17 +170,45 @@ moksha = {
if (typeof(moksha_csrf_token) === 'undefined' || !moksha_csrf_token)
return;
+ moksha.add_hidden_form_field(form_element,
+ '_csrf_token',
+ moksha_csrf_token);
+ },
+
+ /*********************************************************************
+ * Take a form element and add or update a hidden field
+ *
+ * Example:
+ * <form action="/process_form/"
+ * onSubmit="moksha.add_hidden_form_field(this)">
+ *
+ * Params:
+ * form_element - the form being updated
+ * key - the name of the field we are adding
+ * value - the value to set it to
+ * override_existing - defaults to true, if set to false we only
+ * add the field if it does not exist or is
+ * set to an empty string
+ *********************************************************************/
+ add_hidden_form_field: function(form_element, key, value, override_existing) {
+ if (typeof(override_existing) === 'undefined')
+ override_existing = true;
+
var $fe = $(form_element);
- var $csrf_field = $("input[name=_csrf_token]", form_element);
+ var $field = $("input[name=" + key + "]", form_element);
// create a field if it doens't already exist
- if ($csrf_field.length < 1) {
- $csrf_field = $("<input type='hidden'></input>").attr("name", "_csrf_token");
+ if ($field.length < 1) {
+ $field = $("<input type='hidden'></input>").attr("name", key);
- $fe.append($csrf_field);
+ $fe.append($field);
}
- $csrf_field.attr("value", moksha_csrf_token);
+ var v = $field.attr("value");
+ if (!override_existing && v)
+ return;
+
+ $field.attr("value", value);
},
/********************************************************************
15 years, 2 months
moksha/public
by John (J5) Palmieri
moksha/public/javascript/moksha.js | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
New commits:
commit c2c8bf1698b36db83242ba831683ef457aa8fe50
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Tue Apr 14 15:29:04 2009 -0400
have goto do a full url rewrite
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index dd16072..7cfab76 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -194,7 +194,7 @@ moksha = {
if (typeof(params) != 'object')
params = {}
- window.location.href = moksha.csrf_rewrite_url(url, params);
+ window.location.href = moksha.url(url, params);
},
/*
@@ -403,8 +403,12 @@ moksha = {
return burl;
},
- url: function(url) {
+ url: function(url, params) {
+ if (typeof(params) == 'undefined')
+ params = {};
+
var purl = moksha.parseUri(url);
+ purl.update_query_string(params);
if (!purl.protocol) {
var burl = moksha.get_base_url();
15 years, 2 months
moksha/middleware
by John (J5) Palmieri
moksha/middleware/connector.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit 2dcb4730f6bd7975f8466b76da96c16bd210c259
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Tue Apr 14 15:02:32 2009 -0400
check against our stripped path not the full request.path
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py
index f940b94..2ce3073 100644
--- a/moksha/middleware/connector.py
+++ b/moksha/middleware/connector.py
@@ -67,7 +67,7 @@ class MokshaConnectorMiddleware(object):
path = self.strip_script(environ, request.path)
if path.startswith('/moksha_connector'):
- s = request.path.split('/')[2:]
+ s = path.split('/')[2:]
# since keys are not unique we need to condense them
15 years, 2 months
moksha/public
by John (J5) Palmieri
moksha/public/javascript/ui/moksha.ui.grid.js | 20 ++++----------------
1 file changed, 4 insertions(+), 16 deletions(-)
New commits:
commit 1a9be9574f9f22f509d271f8a5c8b18ca1655f6a
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Tue Apr 14 14:55:46 2009 -0400
have grid use the moksha connector loading method to rewrite the url correctly
diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js
index cd91dd0..b71e5fa 100644
--- a/moksha/public/javascript/ui/moksha.ui.grid.js
+++ b/moksha/public/javascript/ui/moksha.ui.grid.js
@@ -124,29 +124,17 @@
// end of the rows
},
- get_json: function(path, args, callback) {
- var self = this;
-
- if (typeof(moksha_csrf_token)!='undefined' && moksha_csrf_token)
- args['_csrf_token'] = moksha_csrf_token;
- moksha.json_load(path, args, function (json) {
- callback(json);
-
- }, this.$overlay_div);
-
- },
-
connector_query_model: function(connector, path, callback) {
- path = '/moksha_connector/' + connector + '/query_model/' + path;
- this.get_json(path, {}, callback);
+ path = '/query_model/' + path;
+ moksha.connector_load(connector, path, {}, callback, this.$overlay_div);
},
connector_query: function(connector, path, dispatch_data, callback) {
- path = '/moksha_connector/' + connector + '/query/' + path;
+ path = '/query/' + path;
if (dispatch_data)
path = path + '/' + $.toJSON(dispatch_data);
- this.get_json(path, {}, callback);
+ moksha.connector_load(connector, path, {}, callback, this.$overlay_div);
},
request_data_refresh: function(event) {
15 years, 2 months