Commit a86436c4 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Renamed to follow naming convention. Added comments for implementation weaknesses.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4944 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 699268e9
...@@ -52,16 +52,16 @@ class PreferenceTool(BaseTool): ...@@ -52,16 +52,16 @@ class PreferenceTool(BaseTool):
security.declareProtected( security.declareProtected(
Permissions.ManagePortal, 'manage_overview' ) Permissions.ManagePortal, 'manage_overview' )
manage_overview = DTMLFile( 'explainPreferenceTool', _dtmldir ) manage_overview = DTMLFile( 'explainPreferenceTool', _dtmldir )
security.declareProtected( security.declareProtected(
Permissions.ManagePortal, 'manage_group_preferences' ) Permissions.ManagePortal, 'manage_group_preferences' )
manage_group_preferences = DTMLFile( manage_group_preferences = DTMLFile(
'PreferenceTool_managePreferences', _dtmldir ) 'PreferenceTool_managePreferences', _dtmldir )
manage_options = ( BaseTool.manage_options + manage_options = ( BaseTool.manage_options +
( { 'label' : 'User Groups Preferences' ( { 'label' : 'User Groups Preferences'
, 'action' : 'manage_group_preferences'},)) , 'action' : 'manage_group_preferences'},))
security.declarePrivate('manage_afterAdd') security.declarePrivate('manage_afterAdd')
def manage_afterAdd(self, item, container) : def manage_afterAdd(self, item, container) :
""" init the permissions right after creation """ """ init the permissions right after creation """
...@@ -70,7 +70,7 @@ class PreferenceTool(BaseTool): ...@@ -70,7 +70,7 @@ class PreferenceTool(BaseTool):
item.manage_permission(Permissions.View, item.manage_permission(Permissions.View,
['Member', 'Auditor', 'Manager']) ['Member', 'Auditor', 'Manager'])
BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container) BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container)
def _aq_dynamic(self, name): def _aq_dynamic(self, name):
""" if the name is a valid preference, then start a lookup on """ if the name is a valid preference, then start a lookup on
active preferences. """ active preferences. """
...@@ -80,16 +80,16 @@ class PreferenceTool(BaseTool): ...@@ -80,16 +80,16 @@ class PreferenceTool(BaseTool):
aq_base_name = getattr(aq_base(self), name, None) aq_base_name = getattr(aq_base(self), name, None)
if aq_base_name is not None : if aq_base_name is not None :
return aq_base_name return aq_base_name
if name in self.getValidPreferenceNames() : if name in self.getValidPreferencePropertyIdList() :
return self.getPreference(name) return self.getPreference(name)
security.declareProtected(Permissions.View, "getPreference") security.declareProtected(Permissions.View, "getPreference")
def getPreference(self, pref_name) : def getPreference(self, pref_name) :
""" get the preference on the most appopriate Preference object. """ """ get the preference on the most appopriate Preference object. """
def _getPreference(pref_name="", user_name="") : def _getPreference(pref_name="", user_name="") :
found = 0 found = 0
MARKER = [] MARKER = []
for pref in self._getMostAppropriatePreferences() : for pref in self._getSortedPreferenceList() :
attr = getattr(pref, pref_name, MARKER) attr = getattr(pref, pref_name, MARKER)
if attr is not MARKER : if attr is not MARKER :
found = 1 found = 1
...@@ -106,17 +106,17 @@ class PreferenceTool(BaseTool): ...@@ -106,17 +106,17 @@ class PreferenceTool(BaseTool):
id='PreferenceTool.CachingMethod') id='PreferenceTool.CachingMethod')
user_name = getSecurityManager().getUser().getId() user_name = getSecurityManager().getUser().getId()
return _getPreference(pref_name=pref_name, user_name=user_name) return _getPreference(pref_name=pref_name, user_name=user_name)
security.declareProtected(Permissions.ModifyPortalContent, "setPreference") security.declareProtected(Permissions.ModifyPortalContent, "setPreference")
def setPreference(self, pref_name, value) : def setPreference(self, pref_name, value) :
""" set the preference on the active Preference object""" """ set the preference on the active Preference object"""
self.getActivePreference()._edit(**{pref_name:value}) self.getActivePreference()._edit(**{pref_name:value})
security.declareProtected(Permissions.View, "getValidPreferenceNames") security.declareProtected(Permissions.View, "getValidPreferencePropertyIdList")
def getValidPreferenceNames(self) : def getValidPreferencePropertyIdList(self) :
""" return the list of attributes that are preferences names and """ return the list of attributes that are preferences names and
should be looked up on Preferences. """ should be looked up on Preferences. """
def _getValidPreferenceNames(self) : def _getValidPreferencePropertyIdList(self) :
""" a cache for this method """ """ a cache for this method """
attr_list = [] attr_list = []
try : try :
...@@ -132,7 +132,7 @@ class PreferenceTool(BaseTool): ...@@ -132,7 +132,7 @@ class PreferenceTool(BaseTool):
zmi_property_sheet_list.append( zmi_property_sheet_list.append(
getattr(__import__(property_sheet), property_sheet)) getattr(__import__(property_sheet), property_sheet))
except ImportError, e : except ImportError, e :
LOG('PreferenceTool._getValidPreferenceNames', INFO, LOG('PreferenceTool._getValidPreferencePropertyIdList', INFO,
'unable to import Property Sheet %s' % property_sheet, e) 'unable to import Property Sheet %s' % property_sheet, e)
# 'Static' property sheets defined on the class # 'Static' property sheets defined on the class
class_property_sheet_list = Preference.property_sheets class_property_sheet_list = Preference.property_sheets
...@@ -163,16 +163,22 @@ class PreferenceTool(BaseTool): ...@@ -163,16 +163,22 @@ class PreferenceTool(BaseTool):
'get%sTitleList' % convertToUpperCase(attribute), 'get%sTitleList' % convertToUpperCase(attribute),
'get%sList' % convertToUpperCase(attribute), ] 'get%sList' % convertToUpperCase(attribute), ]
return attr_list return attr_list
_getValidPreferenceNames = CachingMethod( _getValidPreferencePropertyIdList = CachingMethod(
_getValidPreferenceNames, cache_duration = 600, _getValidPreferencePropertyIdList, cache_duration = 600,
id = 'PreferenceTool._getPreferenceAttributes') id = 'PreferenceTool._getPreferenceAttributes')
return _getValidPreferenceNames(self) return _getValidPreferencePropertyIdList(self)
security.declarePrivate('_getMostAppropriatePreferences') security.declarePrivate('_getSortedPreferenceList')
def _getMostAppropriatePreferences(self) : def _getSortedPreferenceList(self) :
""" return the most appropriate preferences objects, """ return the most appropriate preferences objects,
sorted so that the first in the list should be applied first """ sorted so that the first in the list should be applied first
"""
prefs = [] prefs = []
# XXX This will not work with 1000000 users (searchFolder required)
# XXX will also cause problems with Manager (too long)
# XXX Use catalog instead of contentValues (ex. searchFolder)
# XXX For manager, create a manager specific preference
# or better solution
for pref in self.contentValues(spec=('ERP5 Preference', )) : for pref in self.contentValues(spec=('ERP5 Preference', )) :
pref = pref.getObject() pref = pref.getObject()
if pref.getPreferenceState() == 'enabled' : if pref.getPreferenceState() == 'enabled' :
...@@ -184,16 +190,19 @@ class PreferenceTool(BaseTool): ...@@ -184,16 +190,19 @@ class PreferenceTool(BaseTool):
def getActivePreference(self) : def getActivePreference(self) :
""" returns the current preference for the user. """ returns the current preference for the user.
Note that this preference may be read only. """ Note that this preference may be read only. """
enabled_prefs = self._getMostAppropriatePreferences() enabled_prefs = self._getSortedPreferenceList()
if len(enabled_prefs) > 0 : if len(enabled_prefs) > 0 :
return enabled_prefs[0] return enabled_prefs[0]
security.declareProtected(Permissions.View, 'getDocumentTemplatesForFolder') security.declareProtected(Permissions.View, 'getDocumentTemplate')
def getDocumentTemplatesForFolder(self, folder) : def getDocumentTemplate(self, folder) :
""" returns all document templates that are in acceptable Preferences """ returns all document templates that are in acceptable Preferences
for the folder """ based on different criteria such as folder, portal_type, etc.
XXX This spec still needs to be refined before implementation
"""
acceptable_templates = [] acceptable_templates = []
for pref in self._getMostAppropriatePreferences() : for pref in self._getSortedPreferenceList() :
for doc in pref.objectValues() : for doc in pref.objectValues() :
if hasattr(doc, 'getTemplateDestinationUidList') and \ if hasattr(doc, 'getTemplateDestinationUidList') and \
folder.getUid() in doc.getTemplateDestinationUidList() : folder.getUid() in doc.getTemplateDestinationUidList() :
...@@ -201,9 +210,19 @@ class PreferenceTool(BaseTool): ...@@ -201,9 +210,19 @@ class PreferenceTool(BaseTool):
return acceptable_templates return acceptable_templates
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'manage_updateUserGroupsPreferences') 'USELESS_manage_updateUserGroupsPreferences')
def manage_updateUserGroupsPreferences(self, REQUEST) : def USELESS_manage_updateUserGroupsPreferences(self, REQUEST) :
""" action edit Users Groups Preferences from the management sceen """ """ action edit Users Groups Preferences from the
management sceen
XXX This is not compatible with 1,000,000 preferences
Also, the type of preference (or, better, the priority)
must be *stored* on the preference itself and
set from the preference itself.
This API is therefore useless.
"""
for k, v in REQUEST.items() : for k, v in REQUEST.items() :
if k.startswith("preference_priority_") : if k.startswith("preference_priority_") :
self[k[len('preference_priority_'):]].setPriority(v) self[k[len('preference_priority_'):]].setPriority(v)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment