Commit 7204ea05 authored by Jérome Perrin's avatar Jérome Perrin

API to create a preference for any user


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35105 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f9e55f26
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
# #
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo, getSecurityManager from AccessControl import ClassSecurityInfo
from AccessControl.SecurityManagement import getSecurityManager,\
setSecurityManager, newSecurityManager
from MethodObject import Method from MethodObject import Method
from Products.ERP5Type.Globals import InitializeClass, DTMLFile from Products.ERP5Type.Globals import InitializeClass, DTMLFile
from zLOG import LOG, PROBLEM from zLOG import LOG, PROBLEM
...@@ -274,5 +276,21 @@ class PreferenceTool(BaseTool): ...@@ -274,5 +276,21 @@ class PreferenceTool(BaseTool):
template_list.append(template) template_list.append(template)
return template_list return template_list
security.declareProtected(Permissions.ManagePortal,
'createPreferenceForUser')
def createPreferenceForUser(self, username):
"""Creates a preference for a given user.
"""
security_manager = getSecurityManager()
try:
user_folder = self.getPortalObject().acl_users
user = user_folder.getUserById(username)
if user is None:
raise TypeError("User %r not found" % (username, ))
newSecurityManager(None, user.__of__(user_folder))
return self.newContent(portal_type='Preference')
finally:
setSecurityManager(security_manager)
InitializeClass(PreferenceTool) InitializeClass(PreferenceTool)
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