app/soc/views/models/base.py
changeset 586 a4a36b06a870
parent 576 6614d3f545b7
child 587 7504504209a3
--- a/app/soc/views/models/base.py	Tue Nov 25 17:18:57 2008 +0000
+++ b/app/soc/views/models/base.py	Tue Nov 25 17:19:37 2008 +0000
@@ -106,11 +106,10 @@
     
     new_params['sidebar'] = None
     new_params['sidebar_defaults'] = [
-     ('/%s/create', 'New %(name)s'),
-     ('/%s/list', 'List %(name_plural)s'),
+     ('/%s/create', 'New %(name)s', 'create'),
+     ('/%s/list', 'List %(name_plural)s', 'list'),
     ]
     new_params['sidebar_additional'] = []
-    new_params['sidebar_heading'] = None
 
     new_params['key_fields_prefix'] = []
 
@@ -586,9 +585,9 @@
 
     result = []
 
-    for url, menu_text in defaults:
+    for url, menu_text, access_type in defaults:
       url = url % params['url_name'].lower()
-      item = (url, menu_text % params)
+      item = (url, menu_text % params, access_type)
       result.append(item)
 
     for item in params['sidebar_additional']:
@@ -596,7 +595,7 @@
 
     return result
 
-  def getSidebarLinks(self, params=None):
+  def getSidebarLinks(self, request, params=None):
     """Returns an dictionary with one sidebar entry.
 
     Args:
@@ -604,15 +603,23 @@
     """
 
     params = dicts.merge(params, self._params)
+    rights = params['rights']
 
     items = []
 
-    for url, menu_text in self._getSidebarItems(params):
-      items.append({'url': url, 'title': menu_text})
+    for url, menu_text, access_type in self._getSidebarItems(params):
+      try:
+        self.checkAccess(access_type, request, rights)
+        items.append({'url': url, 'title': menu_text})
+      except out_of_band.Error:
+        pass
+
+    if not items:
+      return
 
     res = {}
 
-    if not params['sidebar_heading']:
+    if 'sidebar_heading' not in params:
       params['sidebar_heading'] = params['name']
 
     res['heading'] = params['sidebar_heading']