Author: justi9
Date: 2009-09-23 11:29:33 -0400 (Wed, 23 Sep 2009)
New Revision: 3643
Modified:
mgmt/trunk/cumin/python/cumin/parameters.py
mgmt/trunk/cumin/python/cumin/usergrid/widgets.py
mgmt/trunk/cumin/python/cumin/widgets.py
Log:
* Move the user attribute to cumin-common code, and put an instance
on CuminPage
* Only show the page nav to the main administration page if the user
has the admin role
Modified: mgmt/trunk/cumin/python/cumin/parameters.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/parameters.py 2009-09-23 15:01:11 UTC (rev 3642)
+++ mgmt/trunk/cumin/python/cumin/parameters.py 2009-09-23 15:29:33 UTC (rev 3643)
@@ -4,6 +4,10 @@
from model import Pool
from model import Job
+class UserAttribute(Attribute):
+ def get(self, session):
+ return session.user_session.subject
+
class ObjectAssociateAttribute(Attribute):
def __init__(self, app, name, object):
super(ObjectAssociateAttribute, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/usergrid/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/usergrid/widgets.py 2009-09-23 15:01:11 UTC (rev 3642)
+++ mgmt/trunk/cumin/python/cumin/usergrid/widgets.py 2009-09-23 15:29:33 UTC (rev 3643)
@@ -1,6 +1,7 @@
from wooly import *
from wooly.widgets import *
+from cumin.parameters import *
from cumin.widgets import *
from cumin.util import *
from cumin.grid.submission import *
@@ -12,18 +13,11 @@
strings = StringCatalog(__file__)
-class UserAttribute(Attribute):
- def get(self, session):
- return session.user_session.subject
-
class MainPage(CuminPage, ModeSet):
def __init__(self, app, name):
super(MainPage, self).__init__(app, name)
- self.user = UserAttribute(app, "user")
- self.add_attribute(self.user)
-
- self.main = MainView(app, "main", self.user)
+ self.main = MainView(app, "main")
self.add_mode(self.main)
self.set_default_frame(self.main)
@@ -31,31 +25,26 @@
return "User Grid"
class MainView(CuminMainView):
- def __init__(self, app, name, user):
+ def __init__(self, app, name):
super(MainView, self).__init__(app, name)
- self.overview = OverviewFrame(app, "overview", user)
+ self.overview = OverviewFrame(app, "overview")
self.add_tab(self.overview)
- self.submissions = UserSubmissionSet(app, "submissions", user)
+ self.submissions = UserSubmissionSet(app, "submissions")
self.add_tab(self.submissions)
- self.slots = UserSlotSet(app, "slots", user)
+ self.slots = UserSlotSet(app, "slots")
self.add_tab(self.slots)
class OverviewFrame(Widget):
- def __init__(self, app, name, user):
- super(OverviewFrame, self).__init__(app, name)
-
def render_title(self, session):
return "Overview"
class UserSubmissionSet(SubmissionSet):
- def __init__(self, app, name, user):
+ def __init__(self, app, name):
super(UserSubmissionSet, self).__init__(app, name)
- self.user = user
-
self.scheduler_col.visible = False
self.submitter_col.visible = False
@@ -63,18 +52,13 @@
pass # XXX return "where m.name = %(name)s"
def get_sql_values(self, session):
- user = self.user.get(session)
+ user = self.page.user.get(session)
return {"name": user.name}
class UserSlotSet(SlotSet):
- def __init__(self, app, name, user):
- super(UserSlotSet, self).__init__(app, name)
-
- self.user = user
-
def render_sql_where(self, session):
return "where s.remote_user like %(name)s"
def get_sql_values(self, session):
- user = self.user.get(session)
+ user = self.page.user.get(session)
return {"name": "%s%%" % user.name}
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2009-09-23 15:01:11 UTC (rev 3642)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2009-09-23 15:29:33 UTC (rev 3643)
@@ -73,10 +73,19 @@
self.html_class = CuminPageLinks.__name__
def do_get_items(self, session):
- return (self.app.main_page,
- self.app.user_grid_page,
- self.app.account_page)
+ pages = list()
+ user = self.page.user.get(session)
+ for role in user.roles:
+ if role.name == "admin":
+ pages.append(self.app.main_page)
+ break
+
+ pages.append(self.app.user_grid_page)
+ pages.append(self.app.account_page)
+
+ return pages
+
def render_item_content(self, session, page):
href = Session(page).marshal()
title = page.render_title(session)
@@ -1330,6 +1339,9 @@
self.__modal = Attribute(app, "modal")
self.add_attribute(self.__modal)
+ self.user = UserAttribute(app, "user")
+ self.add_attribute(self.user)
+
def save_session(self, session):
if self.app.debug:
self.app.debug.sessions.append(session)