Refactoring API de IndexIterator.
[Plinn.git] / utils.py
index 024c975..de68f22 100755 (executable)
--- a/utils.py
+++ b/utils.py
@@ -230,7 +230,7 @@ def getPreferredLanguages(context):
 security.declarePublic('getBestTranslationLanguage')
 def getBestTranslationLanguage(langs, context):
     """ returns best translation language according
-        availables languages (param langs)
+        to available languages (param langs)
         and user preferences (retrieves by context)
     """
     request = getattr(context, 'REQUEST', None)
@@ -319,4 +319,20 @@ def _sudo(func, userid=None) :
         raise e
 
     return ret
-    
\ No newline at end of file
+
+security.declarePublic('searchContentsWithLocalRolesForAuthenticatedUser')
+def searchContentsWithLocalRolesForAuthenticatedUser(**kw):
+    mtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IMembershipTool')
+    ctool = getUtilityByInterfaceName('Products.CMFCore.interfaces.ICatalogTool')
+    member = mtool.getAuthenticatedMember()
+    userid = member.getId()
+    userAndGroups = ['user:%s' % userid]
+    
+    getGroups = getattr(member, 'getGroups', None)
+    if getGroups is not None :
+        for group in getGroups():
+            userAndGroups.append('user:'+group)
+    
+    kw[ 'allowedRolesAndUsers' ] = userAndGroups
+    
+    return ctool.unrestrictedSearchResults(**kw)