From ad775741de7e05bf080c5ac7656943d187fa6445 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 24 Mar 2006 10:36:18 +0000
Subject: [PATCH] workaround so that managers only see their USER priority
 preferences.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6197 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/PreferenceTool.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/product/ERP5Form/PreferenceTool.py b/product/ERP5Form/PreferenceTool.py
index 8ece19a1b7..90f9f8d93d 100755
--- a/product/ERP5Form/PreferenceTool.py
+++ b/product/ERP5Form/PreferenceTool.py
@@ -38,6 +38,7 @@ from Products.ERP5Type.Utils import convertToUpperCase
 from Products.ERP5Type.Accessor.TypeDefinition import list_types
 from Products.ERP5Form.Document.Preference import Preference
 from Products.ERP5Form import _dtmldir
+from Products.ERP5Form.Document.Preference import Priority
 
 from MethodObject import Method
 
@@ -169,10 +170,18 @@ class PreferenceTool(BaseTool):
     # XXX will also cause problems with Manager (too long)
     # XXX For manager, create a manager specific preference
     #                  or better solution
+    user = getToolByName(self, 'portal_membership').getAuthenticatedMember()
+    user_is_manager = 'Manager' in user.getRolesInContext(self)
     for pref in self.searchFolder(spec=('ERP5 Preference', )) :
       pref = pref.getObject()
-      if pref.getPreferenceState() == 'enabled' :
-        prefs.append(pref)
+      if pref is not None and pref.getPreferenceState() == 'enabled' :
+        # XXX quick workaround so that manager only see user preference
+        # they actually own.
+        if user_is_manager and pref.getPriority() == Priority.USER :
+          if user.allowed(pref, ('Owner',)):
+            prefs.append(pref)
+        else :
+          prefs.append(pref)
     prefs.sort(lambda b, a: cmp(a.getPriority(), b.getPriority()))
     return prefs
     
-- 
2.30.9