moksha/api/widgets/containers/templates/layout_applist.mak | 28 +++++++ moksha/lib/helpers.py | 50 ++++++++++--- moksha/public/javascript/ui/moksha.ui.tabs.js | 12 ++- 3 files changed, 77 insertions(+), 13 deletions(-)
New commits: commit 066305521fee0c76f4a1c2567369dde97e4dbec9 Merge: 0df4849... c07ffc4... Author: John (J5) Palmieri johnp@redhat.com Date: Mon Feb 16 13:18:47 2009 -0500
Merge branch 'master' of git+ssh://johnp@git.fedorahosted.org/git/moksha
commit 0df4849bf3448147b868fc0bf2490c92f0c3c96d Author: John (J5) Palmieri johnp@redhat.com Date: Mon Feb 16 13:17:42 2009 -0500
fix how we check predicates and add a param_has_value predicate
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py index f3c4586..4dc88b3 100644 --- a/moksha/lib/helpers.py +++ b/moksha/lib/helpers.py @@ -5,6 +5,10 @@ from repoze.what.predicates import (Not, Predicate, All, Any, has_all_permissio in_all_groups, in_any_group, in_group, is_user, not_anonymous)
+from repoze.what.authorize import check_authorization, NotAuthorizedError + +from webob import Request + import urllib import uuid import simplejson as json @@ -318,6 +322,33 @@ class MokshaWidget(Widget): content_id=content_id, params=params, auth=auth)
+class param_has_value(Predicate): + """ + Checks the parameters of the environment and return True if the + parameter specified holds a value + """ + message = u'Parameter "%s(param)" is not set' + + def __init__(self, param, empty_str_is_valid = False, **kwargs): + super(param_has_value, self).__init__(**kwargs) + self.param = param + self.empty_str_is_valid = empty_str_is_valid + + def evaluate(self, environ, credentials): + req = Request(environ) + p = req.params.getall(self.param) + + if not p: + return self.unmet(param = self.param) + + p = p[0] + if p == None: + return self.unmet(param = self.param) + + if not self.empty_str_is_valid and p == '': + return self.unmet(param = self.param) + + return
# setup the dictionary of acceptable callables when eval'ing predicates from # a configuration file - this makes up the keywords of the predicate @@ -326,6 +357,7 @@ _safe_predicate_callables = { 'Not': Not, 'All': All, 'Any': Any, + 'param_has_value': param_has_value, 'has_all_permissions': has_all_permissions, 'has_any_permission': has_any_permission, 'has_permission': has_permission, @@ -378,18 +410,16 @@ def check_predicates(predicates):
from pylons import request
- if(isinstance(predicates, list) or isinstance(predicates, tuple)): - for p in predicates: - if not p.eval_with_environ(request.environ): - return False - return True - - - if(isinstance(predicates, Predicate)): - return predicates.eval_with_environ(request.environ) + if(not(isinstance(predicates, list) or isinstance(predicates, tuple))): + predicates = (predicates,)
- return False + for p in predicates: + try: + check_authorization(p, request.environ) + except NotAuthorizedError, e: + return False
+ return True
def eval_and_check_predicates(predicate_str): """
commit e546a5faf5e44de686232b017207504bb6801de7 Author: John (J5) Palmieri johnp@redhat.com Date: Mon Feb 16 13:16:16 2009 -0500
strip javascript in containers
diff --git a/moksha/api/widgets/containers/templates/layout_applist.mak b/moksha/api/widgets/containers/templates/layout_applist.mak index 8dc1fa6..d9d8a24 100644 --- a/moksha/api/widgets/containers/templates/layout_applist.mak +++ b/moksha/api/widgets/containers/templates/layout_applist.mak @@ -4,6 +4,22 @@ % if app['label']: <dt>${app['label']}</dt> % endif + + <script type="text/javascript"> + function moksha_strip_and_display(r, panel) { + var $temp = $(r); + var $scripts = $temp.find("script[src]"); + $scripts.remove(); + + var $stripped = []; + $.each($temp, function(i, s) { + if (!$(s).is('script[src]')){ + $stripped.push(s); + } + }); + panel.html($stripped); + } + </script> <dd id="${app['id']}"> % if app.has_key('widget'): ${app['widget'](**app['params'])} @@ -12,7 +28,17 @@
% if not app.has_key('widget'): <script type="text/javascript"> - $("#${app['id']}").load("${app['url']}", ${app['params']}); + <!-- TODO: make this a JS widget --> + var ajaxOptions = { + url: "${app['url']}", + success: function(r, s) { + var $panel = $("#${app['id']}"); + moksha_strip_and_display(r, $panel); + }, + data: ${app['params']} + }; + + $.ajax(ajaxOptions); </script> % endif
diff --git a/moksha/public/javascript/ui/moksha.ui.tabs.js b/moksha/public/javascript/ui/moksha.ui.tabs.js index 5208344..406a2ac 100644 --- a/moksha/public/javascript/ui/moksha.ui.tabs.js +++ b/moksha/public/javascript/ui/moksha.ui.tabs.js @@ -532,9 +532,17 @@ $.widget("ui.mokshatabs", { url: url, success: function(r, s) { var $panel = $(a.hash + ':first', self.element); - $panel.html(r); + var $temp = $(r); + var $stripped = []; + $.each($temp, function(i, s) { + if (!$(s).is('script[src]')){ + $stripped.push(s); + } + }); + $panel.html($stripped); cleanup();
+ if (o.cache) $.data(a, 'cache.tabs', true); // if loaded once do not load them again
@@ -542,7 +550,7 @@ $.widget("ui.mokshatabs", { $(self.element).triggerHandler('tabsload', [self.fakeEvent('tabsload'), self.ui(self.$tabs[index], self.$panels[index])], o.load ); - o.ajaxOptions.success && o.ajaxOptions.success(r, s); + o.ajaxOptions.success && o.ajaxOptions.success($temp, s);
// This callback is required because the switch has to take // place after loading has completed. Call last in order to