Commit 6ec89c42 authored by Jérome Perrin's avatar Jérome Perrin

extend createPreferenceForUser API to enable the preference directly.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35612 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 245ce4d7
...@@ -295,8 +295,9 @@ class PreferenceTool(BaseTool): ...@@ -295,8 +295,9 @@ class PreferenceTool(BaseTool):
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'createPreferenceForUser') 'createPreferenceForUser')
def createPreferenceForUser(self, username): def createPreferenceForUser(self, username, enable=True):
"""Creates a preference for a given user. """Creates a preference for a given user, and optionnally enable the
preference.
""" """
security_manager = getSecurityManager() security_manager = getSecurityManager()
try: try:
...@@ -305,7 +306,10 @@ class PreferenceTool(BaseTool): ...@@ -305,7 +306,10 @@ class PreferenceTool(BaseTool):
if user is None: if user is None:
raise ValueError("User %r not found" % (username, )) raise ValueError("User %r not found" % (username, ))
newSecurityManager(None, user.__of__(user_folder)) newSecurityManager(None, user.__of__(user_folder))
return self.newContent(portal_type='Preference') preference = self.newContent(portal_type='Preference')
if enable:
preference.enable()
return preference
finally: finally:
setSecurityManager(security_manager) setSecurityManager(security_manager)
......
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