Author: tmckay
Date: 2013-12-20 16:37:53 +0000 (Fri, 20 Dec 2013)
New Revision: 5789
Modified:
branches/statusquo/cumin/python/cumin/grid/main.py
branches/statusquo/cumin/python/cumin/grid/tags.py
branches/statusquo/cumin/python/cumin/inventory/main.py
branches/statusquo/cumin/python/cumin/main.py
branches/statusquo/cumin/python/cumin/messaging/main.py
branches/statusquo/cumin/python/cumin/objectselector.py
branches/statusquo/cumin/python/cumin/persona.py
branches/statusquo/cumin/python/cumin/stat.py
branches/statusquo/cumin/python/cumin/usergrid/main.py
branches/statusquo/cumin/python/cumin/widgets.py
branches/statusquo/wooly/python/wooly/__init__.py
Log:
Add a unified patch for the following issues
BZ1015692
BZ1015694
BZ1025227
Modified: branches/statusquo/cumin/python/cumin/grid/main.py
===================================================================
--- branches/statusquo/cumin/python/cumin/grid/main.py 2013-12-20 16:33:21 UTC (rev 5788)
+++ branches/statusquo/cumin/python/cumin/grid/main.py 2013-12-20 16:37:53 UTC (rev 5789)
@@ -19,16 +19,28 @@
self.job_submit = JobSubmit(app)
self.dag_job_submit = DagJobSubmit(app)
self.vm_job_submit = VmJobSubmit(app)
+
+ def add_module_for_submits(self, module):
+ # Well, none of these are actually contained by
+ # anything per se and they are linked to via TaskLink
+ # objects from multiple places in grid and usergrid.
+ # Allow module values to be added...
+ for s in (self.job_submit,
+ self.dag_job_submit,
+ self.vm_job_submit):
+ if not hasattr(s.form, "cumin_module"):
+ s.form.cumin_module = []
+ s.form.cumin_module.append(module)
+
def init(self):
super(Module, self).init()
+ self.app.export_page.set_cumin_module_for_children(self.name)
self.frame = PoolFrame(self.app, "grid")
self.frame.cumin_module = self.name
+ self.add_module_for_submits(self.name)
+ self.app.main_page.add_to_view(self.frame)
- self.app.main_page.main.grid = self.frame
- self.app.main_page.main.add_tab(self.frame)
-
-
def init_test(self, test):
GridTest("grid", test)
Modified: branches/statusquo/cumin/python/cumin/grid/tags.py
===================================================================
--- branches/statusquo/cumin/python/cumin/grid/tags.py 2013-12-20 16:33:21 UTC (rev 5788)
+++ branches/statusquo/cumin/python/cumin/grid/tags.py 2013-12-20 16:37:53 UTC (rev 5789)
@@ -301,11 +301,11 @@
super(TagInventory, self).__init__(app, name, cls)
self.table.adapter = TagsAdapter(app, cls)
- tag_add_task = AddTags(app)
+ tag_add_task = AddTags(app, self)
link = TaskLink(app, "tag_add", tag_add_task)
self.links.add_child(link)
- self.activate_config_task = ActivateConfigTask(app)
+ self.activate_config_task = ActivateConfigTask(app, self)
link = TaskLink(app, "actlink", self.activate_config_task)
self.links.add_child(link)
@@ -444,7 +444,7 @@
self.label = self.LabelField(app, "labelf")
self.add_field(self.label)
-
+
def render_submit_content(self, session):
''' overriding base method to control the label on the submit button
'''
return "Activate"
@@ -1130,11 +1130,12 @@
'''
This task is used to activate the wallaby configuration.
'''
- def __init__(self, app):
+ def __init__(self, app, selector):
super(ActivateConfigTask, self).__init__(app)
cls = app.model.com_redhat_cumin_grid.Node
self.form = ActivateConfigurationForm(app, self.name, self, cls)
self.invoc = None
+ self.selector = selector
def get_title(self, session, object):
return "Activate wallaby configuration"
@@ -1157,11 +1158,12 @@
'''
This task is used to create a tag in wallaby without assigning it to any nodes.
'''
- def __init__(self, app):
+ def __init__(self, app, selector):
super(AddTags, self).__init__(app)
cls = app.model.com_redhat_cumin_grid.Node
self.form = CreateTags(app, self.name, self, cls)
self.invoc = None
+ self.selector = selector
def get_title(self, session, object):
return "Create tags"
Modified: branches/statusquo/cumin/python/cumin/inventory/main.py
===================================================================
--- branches/statusquo/cumin/python/cumin/inventory/main.py 2013-12-20 16:33:21 UTC (rev
5788)
+++ branches/statusquo/cumin/python/cumin/inventory/main.py 2013-12-20 16:37:53 UTC (rev
5789)
@@ -14,6 +14,7 @@
def __init__(self, app, name):
super(Module, self).__init__(app, name)
+ self.app.export_page.set_cumin_module_for_children(self.name)
self.frame = InventoryFrame(app, "inventory")
self.app = app
self.frame.cumin_module = name
Modified: branches/statusquo/cumin/python/cumin/main.py
===================================================================
--- branches/statusquo/cumin/python/cumin/main.py 2013-12-20 16:33:21 UTC (rev 5788)
+++ branches/statusquo/cumin/python/cumin/main.py 2013-12-20 16:37:53 UTC (rev 5789)
@@ -151,7 +151,9 @@
self.form_page = CuminFormPage(self, "form.html")
self.add_page(self.form_page)
- self.add_page(StatFlashPage(self, "chart.json"))
+ self.chart_page = StatFlashPage(self, "chart.json")
+ self.add_page(self.chart_page)
+
self.add_page(FlashFullPage(self, "flashpage.html"))
self.export_page = CuminExportPage(self, "csv")
@@ -279,6 +281,13 @@
super(Cumin, self).init()
+ # Form widgets need cumin_module values set for them
+ # because the links are processed directly by the forms page
+ # via the 'mode' parameter
+ self.form_page.set_modules_for_forms()
+
+ self.chart_page.set_modules_for_charts()
+
def start(self):
log.info("Starting %s", self)
@@ -365,10 +374,24 @@
self.main = main_view
self.add_mode(self.main)
self.set_default_frame(self.main)
- self.cumin_module = ["messaging", "grid"]
+ self.cumin_module = []
self.page_html_class = "Cumin"
+ def add_module(self, module):
+ if type(module) in (list, tuple):
+ self.cumin_module.extend(module)
+ else:
+ self.cumin_module.append(module)
+
+ def add_to_view(self, frame):
+ # Add a frame to the main view with a tab and
+ # make sure that the page is visible to the
+ # module associated with the frame
+ setattr(self.main, frame.name, frame)
+ self.main.add_tab(frame)
+ self.add_module(frame.cumin_module)
+
def render_title(self, session):
return self.get_title(session)
Modified: branches/statusquo/cumin/python/cumin/messaging/main.py
===================================================================
--- branches/statusquo/cumin/python/cumin/messaging/main.py 2013-12-20 16:33:21 UTC (rev
5788)
+++ branches/statusquo/cumin/python/cumin/messaging/main.py 2013-12-20 16:37:53 UTC (rev
5789)
@@ -15,14 +15,14 @@
def __init__(self, app, name):
super(Module, self).__init__(app, name)
+ self.app.export_page.set_cumin_module_for_children(self.name)
self.frame = MessagingFrame(self.app, "messaging")
self.frame.cumin_module = name
def init(self):
super(Module, self).init()
- self.app.main_page.main.messaging = self.frame
- self.app.main_page.main.add_tab(self.frame)
+ self.app.main_page.add_to_view(self.frame)
def init_test(self, test):
MessagingTest("messaging", test)
Modified: branches/statusquo/cumin/python/cumin/objectselector.py
===================================================================
--- branches/statusquo/cumin/python/cumin/objectselector.py 2013-12-20 16:33:21 UTC (rev
5788)
+++ branches/statusquo/cumin/python/cumin/objectselector.py 2013-12-20 16:37:53 UTC (rev
5789)
@@ -135,9 +135,11 @@
# avoid name collisions on csv page
while self.name in self.app.export_page.modes.children_by_name:
self.name = self.name + ".1"
+
+ # this will also set cumin_module on self to the
+ # prevailing value in effect for the page at this time
+ self.app.export_page.add_csv_exporter(self)
- self.app.export_page.modes.add_mode(self)
-
def render(self, session):
writer = Writer()
Modified: branches/statusquo/cumin/python/cumin/persona.py
===================================================================
--- branches/statusquo/cumin/python/cumin/persona.py 2013-12-20 16:33:21 UTC (rev 5788)
+++ branches/statusquo/cumin/python/cumin/persona.py 2013-12-20 16:37:53 UTC (rev 5789)
@@ -129,7 +129,7 @@
return True
return False
- def authorize(self, web_session, widget):
+ def authorize(self, web_session, widget, reason_on_fail=None):
if not hasattr(widget, "cumin_module") or \
widget.cumin_module is None:
# no module for this widget, we have to allow it
@@ -141,29 +141,31 @@
# (like a column in a table that is only valid if a
# particular module has been loaded).
if type(widget.cumin_module) in (list, tuple):
- if len(set(widget.cumin_module) & set(self.persona.modules)) == 0:
- return False
- elif not widget.cumin_module in self.persona.modules:
- return False
+ res = len(set(widget.cumin_module) & set(self.persona.modules)) != 0
+ else:
+ res = widget.cumin_module in self.persona.modules
+ if not res:
+ reason = "MODULE_NOT_LOADED"
- if not self.is_enforcing():
- # Auth checks against group are off.
- return True
-
- try:
- group = web_session.client_session.attributes['login_session'].group
- except KeyError:
- group = "nogroup"
-
- if type(group) == type([]):
+ # Okay, check access by groups if checks are on
+ elif self.is_enforcing():
+ try:
+ group =
web_session.client_session.attributes['login_session'].group
+ except KeyError:
+ group = "nogroup"
+ if not type(group) in (tuple, list):
+ group = [group]
for g in group:
- if self.persona.lookup(g, widget.cumin_module):
+ res = self.persona.lookup(g, widget.cumin_module)
+ if res:
log.debug("Allowing %s authorization for %s ",
widget.cumin_module, group)
- return True
- else:
- return self.persona.lookup(group, widget.cumin_module)
+ break
+ if not res:
+ log.debug("Denying %s authorization for %s ", widget.my_name,
group)
+ reason = "GROUP_NOT_AUTHORIZED"
- log.debug("Denying %s authorization for %s ", widget.my_name, group)
- return False
+ if not res and reason_on_fail is not None:
+ reason_on_fail.reason = reason
+ return res
Modified: branches/statusquo/cumin/python/cumin/stat.py
===================================================================
--- branches/statusquo/cumin/python/cumin/stat.py 2013-12-20 16:33:21 UTC (rev 5788)
+++ branches/statusquo/cumin/python/cumin/stat.py 2013-12-20 16:37:53 UTC (rev 5789)
@@ -154,6 +154,10 @@
self.fullpageable = True
+ def init(self):
+ super(StatValueChart, self).init()
+ self.app.chart_page.add_chart(self)
+
def get_href_params(self, session):
object = self.object.get(session)
params = list()
@@ -1228,6 +1232,8 @@
def __init__(self, app, name):
super(StatFlashPage, self).__init__(app, name)
+ self.charts = dict()
+
# number of milliseconds since the last update
self.elapsed = Parameter(app, "elapsed")
self.elapsed.default = None
@@ -1290,6 +1296,17 @@
return "text/plain"
def do_render(self, session):
+ try:
+ chart_id = self.chart_id.get(session)
+ if self.charts[chart_id]:
+ chart = self.charts[chart_id]
+ if not self.app.authorize_cb(session, chart):
+ log.debug("Redirect on not authorized for chart %s" %
chart)
+ self.redirect_on_not_authorized(session)
+ return
+ except Exception, e:
+ pass
+
adapter, stats = self.get_adapter_stats(session)
chart = self.chart_factory(self.chart_type.get(session))
@@ -1311,6 +1328,25 @@
return chart_obj
+ def add_chart(self, chart):
+ self.charts[chart.path] = chart
+
+ def set_modules_for_charts(self):
+
+ # Look through all of the chart widgets we have stored as children
+ # and attempt to trace through ancestors and find a cumin_module value
+ for k,child in self.charts.iteritems():
+ if hasattr(child, "cumin_module") and child.cumin_module:
+ continue
+
+ for anc in child.ancestors:
+ if hasattr(anc, "cumin_module") and anc.cumin_module:
+ child.cumin_module = anc.cumin_module
+ log.debug("Adding %s module for %s from %s" %
(anc.cumin_module,
+ child.name,
+ anc))
+ break
+
class PercentAreaChart(AreaChart):
def get_max_min(self, session, stats, samples, time_span, end_seconds_ago):
max_val, min_val = super(PercentAreaChart, self).get_max_min(session, stats,
samples, time_span, end_seconds_ago)
Modified: branches/statusquo/cumin/python/cumin/usergrid/main.py
===================================================================
--- branches/statusquo/cumin/python/cumin/usergrid/main.py 2013-12-20 16:33:21 UTC (rev
5788)
+++ branches/statusquo/cumin/python/cumin/usergrid/main.py 2013-12-20 16:37:53 UTC (rev
5789)
@@ -9,6 +9,11 @@
def init(self):
super(Module, self).init()
+ self.app.export_page.set_cumin_module_for_children(self.name)
self.app.user_grid_page = MainPage(self.app, "usergrid.html")
self.app.add_page(self.app.user_grid_page, add_to_link_set=True)
self.app.user_grid_page.cumin_module = self.name
+
+ # Usergrid links explicitly to submit forms in the grid module.
+ # Add our module value here
+ self.app.grid.add_module_for_submits(self.name)
Modified: branches/statusquo/cumin/python/cumin/widgets.py
===================================================================
--- branches/statusquo/cumin/python/cumin/widgets.py 2013-12-20 16:33:21 UTC (rev 5788)
+++ branches/statusquo/cumin/python/cumin/widgets.py 2013-12-20 16:37:53 UTC (rev 5789)
@@ -1417,6 +1417,36 @@
# for form in model tasks:
# self.add_mode(form)
+ def set_modules_for_forms(self):
+
+ # Look through all of the form widgets we have stored as children
+ # and attempt to trace through ancestors and find a cumin_module value
+ for child in self.modes.children:
+ if hasattr(child, "cumin_module") and child.cumin_module:
+ continue
+
+ if not hasattr(child, "cumin_module"):
+ if hasattr(child, "task") and hasattr(child.task,
"frame"):
+ start = child.task.frame
+ elif hasattr(child, "task") and hasattr(child.task,
"selector"):
+ start = child.task.selector
+ else:
+ start = child
+
+ if hasattr(start, "cumin_module") and start.cumin_module:
+ child.cumin_module = start.cumin_module
+ log.debug("Adding %s module for %s from %s" %
(start.cumin_module,
+ child.name,
+ start))
+ elif start.ancestors:
+ for anc in start.ancestors:
+ if hasattr(anc, "cumin_module") and anc.cumin_module:
+ child.cumin_module = anc.cumin_module
+ log.debug("Adding %s module for %s from %s" %
(anc.cumin_module,
+ child.name,
+ anc))
+ break
+
def render_content(self, session):
writer = Writer()
@@ -1455,11 +1485,26 @@
agent = Parameter(app, "qmf_obj_id")
self.agents = ListParameter(app, "agents", agent)
self.add_parameter(self.agents)
+ self.cumin_module_value = None
+ def set_cumin_module_for_children(self, module):
+ self.cumin_module_value = module
+
+ def add_csv_exporter(self, exporter):
+ self.modes.add_mode(exporter)
+ if (not hasattr(exporter, "cumin_module") or \
+ not exporter.cumin_module) and self.cumin_module_value:
+ exporter.cumin_module = self.cumin_module_value
+
def render_content(self, session, *args):
writer = Writer()
mode = self.modes.mode.get(session)
+ if not self.app.authorize_cb(session, mode):
+ log.debug("Redirect on not authorized for csv export %s" %
mode.name)
+ self.redirect_on_not_authorized(session)
+ return
+
objects = self.get_objects(session)
for obj, mobj in zip(objects, mode.objects):
mobj.set(session, obj)
Modified: branches/statusquo/wooly/python/wooly/__init__.py
===================================================================
--- branches/statusquo/wooly/python/wooly/__init__.py 2013-12-20 16:33:21 UTC (rev 5788)
+++ branches/statusquo/wooly/python/wooly/__init__.py 2013-12-20 16:37:53 UTC (rev 5789)
@@ -296,8 +296,16 @@
def redirect_on_not_authorized(self, session):
# Give an opportunity to redirect to a valid page
# when a user is not authorized for this widget.
- pass
-
+ mainpage = self.app.mainpage_cb(session)
+ if mainpage in self.app.pages_by_name:
+ log.debug("Not authorized, redirecting to %s", mainpage)
+ page = self.app.pages_by_name[mainpage]
+ sess = Session(page)
+ if hasattr(self, "redirect"):
+ self.redirect.set(session, sess.marshal())
+ elif hasattr(self, "page"):
+ self.page.redirect.set(session, sess.marshal())
+
def authorized(self, session):
return session.login_current()
@@ -315,8 +323,17 @@
self.redirect_to_login(session)
return
- if not self.app.authorize_cb(session, self):
- self.redirect_on_not_authorized(session)
+ class Reason(object):
+ pass
+
+ reason = Reason()
+ if not self.app.authorize_cb(session, self, reason):
+ # It's possible that a widget is not authorized
+ # because its module is not loaded, in which case
+ # it should simply not draw (no redirect needed).
+ # So check the reason before we redirect.
+ if reason.reason == "GROUP_NOT_AUTHORIZED":
+ self.redirect_on_not_authorized(session)
else:
if self.update_enabled:
self.page.enable_update(session, self)