[Erp5-report] r16962 - /erp5/trunk/products/CMFCategory/Category.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Oct 11 18:23:01 CEST 2007


Author: jp
Date: Thu Oct 11 18:23:01 2007
New Revision: 16962

URL: http://svn.erp5.org?rev=16962&view=rev
Log:
Added permission filtering to category child methods. Romain will do tests.

Modified:
    erp5/trunk/products/CMFCategory/Category.py

Modified: erp5/trunk/products/CMFCategory/Category.py
URL: http://svn.erp5.org/erp5/trunk/products/CMFCategory/Category.py?rev=16962&r1=16961&r2=16962&view=diff
==============================================================================
--- erp5/trunk/products/CMFCategory/Category.py (original)
+++ erp5/trunk/products/CMFCategory/Category.py Thu Oct 11 18:23:01 2007
@@ -216,7 +216,8 @@
     def getCategoryChildValueList(self, recursive=1, include_if_child=1,
                                   is_self_excluded=1, sort_on=None,
                                   sort_order=None, local_sort_method=None,
-                                  local_sort_id=None, **kw):
+                                  local_sort_id=None, checked_permission=None,
+                                  **kw):
       """
           List the child objects of this category and all its subcategories.
 
@@ -274,12 +275,21 @@
         for c in child_value_list:
           value_list.append(c)
 
+      if checked_permission is not None:
+        checkPermission = self.portal_membership.checkPermission
+        def permissionFilter(obj):
+          if checkPermission(checked_permission, obj):
+            return 1
+          else:
+            return 0
+        value_list = filter(permissionFilter, value_list)
+
       return sortValueList(value_list, sort_on, sort_order, **kw)
 
     # List names recursively
     security.declareProtected(Permissions.AccessContentsInformation,
                                                     'getCategoryChildRelativeUrlList')
-    def getCategoryChildRelativeUrlList(self, base='', recursive=1):
+    def getCategoryChildRelativeUrlList(self, base='', recursive=1, checked_permission=None):
       """
           List the path of this category and all its subcategories.
 
@@ -291,7 +301,8 @@
       if base == 0 or base is None: base = '' # Make sure we get a meaningful base
       if base == 1: base = self.getBaseCategoryId() + '/' # Make sure we get a meaningful base
       url_list = []
-      for value in self.getCategoryChildValueList(recursive = recursive):
+      for value in self.getCategoryChildValueList(recursive=recursive,
+                                                  checked_permission=checked_permission):
         url_list.append(base + value.getRelativeUrl())
       return url_list
 
@@ -693,7 +704,8 @@
                                                  'getCategoryChildValueList')
     def getCategoryChildValueList(self, is_self_excluded=1, recursive=1,
                      include_if_child=1, sort_on=None, sort_order=None,
-                     local_sort_method=None, local_sort_id=None, **kw):
+                     local_sort_method=None, local_sort_id=None,
+                     checked_permission=None, **kw):
       """
           List the child objects of this category and all its subcategories.
 
@@ -752,6 +764,16 @@
           else:
             if len(c.objectIds(self.allowed_types))==0:
               value_list.append(c)
+
+      if checked_permission is not None:
+        checkPermission = self.portal_membership.checkPermission
+        def permissionFilter(obj):
+          if checkPermission(checked_permission, obj):
+            return 1
+          else:
+            return 0
+        value_list = filter(permissionFilter, value_list)
+
       return sortValueList(value_list, sort_on, sort_order, **kw)
 
     # Alias for compatibility




More information about the Erp5-report mailing list