Commit 62d8d3ac authored by Vincent Pelletier's avatar Vincent Pelletier

Use PAS API: take 2.

parent 882f0022
if user_id is None: if user_id is None:
person = context.portal_membership.getAuthenticatedMember().getUserValue() person = context.portal_membership.getAuthenticatedMember().getUserValue()
else: else:
person_list = [x for x in context.acl_users.searchUsers(login=user_id, exact_match=True) if 'path' in x] person_list = [x for x in context.acl_users.searchUsers(id=user_id, exact_match=True) if 'path' in x]
if person_list: if person_list:
person, = person_list person, = person_list
person = context.getPortalObject().restrictedTraverse(person['path']) person = context.getPortalObject().restrictedTraverse(person['path'])
......
...@@ -7,7 +7,8 @@ skin_name = request.get('deferred_portal_skin', portal.portal_skins.getDefaultSk ...@@ -7,7 +7,8 @@ skin_name = request.get('deferred_portal_skin', portal.portal_skins.getDefaultSk
tag = 'active-report-wrapped-%s' % random.randint(0, 1000) tag = 'active-report-wrapped-%s' % random.randint(0, 1000)
priority = 3 priority = 3
person_value = portal.ERP5Site_getAuthenticatedMemberPersonValue() user = portal.portal_membership.getAuthenticatedMember()
person_value = user.getUserValue()
if person_value is None: if person_value is None:
portal.changeSkin(None) portal.changeSkin(None)
return context.Base_redirect('view', keep_items=dict( return context.Base_redirect('view', keep_items=dict(
...@@ -20,8 +21,6 @@ if person_value.getDefaultEmailText('') in ('', None): ...@@ -20,8 +21,6 @@ if person_value.getDefaultEmailText('') in ('', None):
portal_status_message=translateString( portal_status_message=translateString(
"You haven't defined your email address"))) "You haven't defined your email address")))
user_name = person_value.getReference()
# save request parameters # save request parameters
# XXX we exclude some reserved names in a very ad hoc way # XXX we exclude some reserved names in a very ad hoc way
request_form = {} request_form = {}
...@@ -62,7 +61,7 @@ activity_context.activate( ...@@ -62,7 +61,7 @@ activity_context.activate(
skin_name=skin_name, skin_name=skin_name,
request_form=request_form, request_form=request_form,
deferred_style_dialog_method=deferred_style_dialog_method, deferred_style_dialog_method=deferred_style_dialog_method,
user_name=user_name, user_name=user.getId(),
params=params, params=params,
) )
......
...@@ -3,7 +3,8 @@ request = container.REQUEST ...@@ -3,7 +3,8 @@ request = container.REQUEST
portal = context.getPortalObject() portal = context.getPortalObject()
N_ = portal.Base_translateString N_ = portal.Base_translateString
person_value = portal.ERP5Site_getAuthenticatedMemberPersonValue() user = portal.portal_membership.getAuthenticatedMember()
person_value = user.getUserValue()
if person_value is None: if person_value is None:
portal.changeSkin(None) portal.changeSkin(None)
return context.Base_redirect('view', keep_items=dict( return context.Base_redirect('view', keep_items=dict(
...@@ -15,7 +16,6 @@ if person_value.getDefaultEmailText('') in ('', None): ...@@ -15,7 +16,6 @@ if person_value.getDefaultEmailText('') in ('', None):
portal_status_message=N_("You haven't defined your email address"))) portal_status_message=N_("You haven't defined your email address")))
user_name = person_value.getReference()
tag = 'active-report-%s' % random.randint(0, 1000) tag = 'active-report-%s' % random.randint(0, 1000)
priority = 2 priority = 2
format = request.get('format', '') format = request.get('format', '')
...@@ -43,7 +43,7 @@ context.activate(activity="SQLQueue", tag=tag, after_tag=after_tag, ...@@ -43,7 +43,7 @@ context.activate(activity="SQLQueue", tag=tag, after_tag=after_tag,
priority=priority).Base_computeReportSection( priority=priority).Base_computeReportSection(
form=form.getId(), form=form.getId(),
request_other=request_other, request_other=request_other,
user_name=user_name, user_name=user.getId(),
tag=tag, tag=tag,
skin_name=skin_name, skin_name=skin_name,
format=format, format=format,
......
...@@ -245,10 +245,9 @@ class NotificationTool(BaseTool): ...@@ -245,10 +245,9 @@ class NotificationTool(BaseTool):
This method provides only high-level functionality so that you can't use email address This method provides only high-level functionality so that you can't use email address
for sender and recipient, or raw data for attachments. for sender and recipient, or raw data for attachments.
sender -- a login name(reference of Person document) or a Person document sender -- a user id or a user document
recipient -- a login name(reference of Person document) or a Person document, recipient -- a user id or a user document, or a list thereof
a list of thereof
subject -- the subject of the message subject -- the subject of the message
...@@ -282,14 +281,13 @@ class NotificationTool(BaseTool): ...@@ -282,14 +281,13 @@ class NotificationTool(BaseTool):
event_keyword_argument_dict -- additional keyword arguments which is used for event_keyword_argument_dict -- additional keyword arguments which is used for
constructor of event document. constructor of event document.
portal_type_list -- Portal Type of Users
TODO: support default notification email TODO: support default notification email
""" """
portal = self.getPortalObject() portal = self.getPortalObject()
catalog_tool = getToolByName(self, 'portal_catalog') searchUsers = self.acl_users.searchUsers
if portal_type_list is None: def getUserValueByUserId(user_id):
portal_type_list = ('Person',) user, = searchUsers(id=user_id, exact_match=True)
return portal.restrictedTraverse(user['path'])
if notifier_list is None: if notifier_list is None:
# XXX TODO: Use priority_level. Need to implement default notifier query system. # XXX TODO: Use priority_level. Need to implement default notifier query system.
...@@ -304,8 +302,7 @@ class NotificationTool(BaseTool): ...@@ -304,8 +302,7 @@ class NotificationTool(BaseTool):
# Find "From" Person # Find "From" Person
from_person = None from_person = None
if isinstance(sender, basestring): if isinstance(sender, basestring):
sender = catalog_tool.getResultValue(portal_type=portal_type_list, sender = getUserValueByUserId(sender)
reference=sender)
if sender is not None: if sender is not None:
email_value = sender.getDefaultEmailValue() email_value = sender.getDefaultEmailValue()
if email_value is not None and email_value.asText(): if email_value is not None and email_value.asText():
...@@ -313,15 +310,17 @@ class NotificationTool(BaseTool): ...@@ -313,15 +310,17 @@ class NotificationTool(BaseTool):
# Find "To" Person list # Find "To" Person list
to_person_list = [] to_person_list = []
# XXX: evaluating a document as boolean is bad, as __bool__ may be
# overloaded to (for example) return False if there are no children (which
# would have unintended effects here).
if recipient: if recipient:
if not isinstance(recipient, (list, tuple)): if not isinstance(recipient, (list, tuple)):
recipient = (recipient,) recipient = (recipient, )
for person in recipient: for person in recipient:
if isinstance(person, basestring): if isinstance(person, basestring):
person_value = catalog_tool.getResultValue(portal_type=portal_type_list, person_value = getUserValueByUserId(person)
reference=person)
if person_value is None: if person_value is None:
raise ValueError("Can't find person document which reference is '%s'" % person) raise ValueError("Can't find user with id %r" % (person, ))
person = person_value person = person_value
to_person_list.append(person) to_person_list.append(person)
......
...@@ -74,7 +74,8 @@ class TestAccounting_l10n_fr(AccountingTestCase): ...@@ -74,7 +74,8 @@ class TestAccounting_l10n_fr(AccountingTestCase):
def createUserAndlogin(self, name=username): def createUserAndlogin(self, name=username):
# create a user with an email address # create a user with an email address
person_module = self.portal.person_module person_module = self.portal.person_module
if person_module._getOb('pers', None) is None: person = person_module._getOb('pers', None)
if person is None:
person = person_module.newContent(id='pers', portal_type='Person', person = person_module.newContent(id='pers', portal_type='Person',
reference=self.username, reference=self.username,
first_name=self.first_name, first_name=self.first_name,
...@@ -85,7 +86,7 @@ class TestAccounting_l10n_fr(AccountingTestCase): ...@@ -85,7 +86,7 @@ class TestAccounting_l10n_fr(AccountingTestCase):
uf = self.portal.acl_users uf = self.portal.acl_users
uf.zodb_roles.assignRoleToPrincipal('Assignor', self.username) uf.zodb_roles.assignRoleToPrincipal('Assignor', self.username)
user = uf.getUserById(self.username).__of__(uf) user = uf.getUser(self.username).__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def test_FEC(self): def test_FEC(self):
......
...@@ -99,8 +99,8 @@ class TestQueryModule(ERP5TypeTestCase): ...@@ -99,8 +99,8 @@ class TestQueryModule(ERP5TypeTestCase):
assignment.validate() assignment.validate()
self.tic() self.tic()
uf = self.portal.acl_users uf = self.portal.acl_users
owner_user = uf.getUser('owner_user').__of__(uf) owner_user = uf.getUserById('owner_user').__of__(uf)
question_user = uf.getUser('question_user').__of__(uf) question_user = uf.getUserById('question_user').__of__(uf)
# add Author local roles on person and query modules # add Author local roles on person and query modules
self.portal.person_module.manage_setLocalRoles('owner_user', ['Author']) self.portal.person_module.manage_setLocalRoles('owner_user', ['Author'])
......
...@@ -127,7 +127,7 @@ class TestTaskMixin: ...@@ -127,7 +127,7 @@ class TestTaskMixin:
# def stepLogin(self, **kw): # def stepLogin(self, **kw):
# portal = self.getPortal() # portal = self.getPortal()
# uf = portal.acl_users # uf = portal.acl_users
# if not uf.getUser('dummy'): # if not uf.getUserById('dummy'):
# uf._doAddUser('manager', '', ['Manager'], []) # uf._doAddUser('manager', '', ['Manager'], [])
# self.login('manager') # self.login('manager')
# person_module = portal.getDefaultModule(self.person_portal_type) # person_module = portal.getDefaultModule(self.person_portal_type)
...@@ -718,7 +718,7 @@ class TestTask(TestTaskMixin, ERP5TypeTestCase): ...@@ -718,7 +718,7 @@ class TestTask(TestTaskMixin, ERP5TypeTestCase):
simulation_tool = self.getPortal().portal_simulation simulation_tool = self.getPortal().portal_simulation
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
if not uf.getUser('manager'): if not uf.getUserById('manager'):
uf._doAddUser('manager', '', ['Manager'], []) uf._doAddUser('manager', '', ['Manager'], [])
self.login('manager') self.login('manager')
try: try:
......
...@@ -99,7 +99,7 @@ class TestTaskReportDivergenceMixin(TestTaskMixin, SecurityTestCase): ...@@ -99,7 +99,7 @@ class TestTaskReportDivergenceMixin(TestTaskMixin, SecurityTestCase):
simulation_tool = portal.portal_simulation simulation_tool = portal.portal_simulation
rule_tool = portal.portal_rules rule_tool = portal.portal_rules
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
if not uf.getUser('manager'): if not uf.getUserById('manager'):
uf._doAddUser('manager', '', ['Manager'], []) uf._doAddUser('manager', '', ['Manager'], [])
self.login('manager') self.login('manager')
simulation_tool.Base_setDefaultSecurity() simulation_tool.Base_setDefaultSecurity()
......
...@@ -73,7 +73,7 @@ class TestZODBHistory(ERP5TypeTestCase): ...@@ -73,7 +73,7 @@ class TestZODBHistory(ERP5TypeTestCase):
def addUser(self, user_name, role=['Member', 'Owner', 'Assignor']): def addUser(self, user_name, role=['Member', 'Owner', 'Assignor']):
""" Create a test user.""" """ Create a test user."""
uf = self.portal.acl_users uf = self.portal.acl_users
if not uf.getUser(user_name): if not uf.getUserById(user_name):
uf._doAddUser(user_name, '', role, []) uf._doAddUser(user_name, '', role, [])
def _clearCache(self): def _clearCache(self):
......
...@@ -61,7 +61,7 @@ class TestGUISecurity(ERP5TypeTestCase): ...@@ -61,7 +61,7 @@ class TestGUISecurity(ERP5TypeTestCase):
def loginAs(self, id='user'): def loginAs(self, id='user'):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
user = uf.getUserById(id).__of__(uf) user = uf.getUser(id).__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def stepCreateObjects(self, sequence = None, sequence_list = None, **kw): def stepCreateObjects(self, sequence = None, sequence_list = None, **kw):
......
...@@ -72,8 +72,8 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -72,8 +72,8 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
def loginAsUser(self, username): def loginAsUser(self, username):
uf = self.portal.acl_users uf = self.portal.acl_users
uf.zodb_roles.assignRoleToPrincipal('Manager', username) user = uf.getUser(username).__of__(uf)
user = uf.getUserById(username).__of__(uf) uf.zodb_roles.assignRoleToPrincipal('Manager', user.getId())
newSecurityManager(None, user) newSecurityManager(None, user)
def test_skin_selection(self): def test_skin_selection(self):
......
...@@ -2090,7 +2090,7 @@ return 1 ...@@ -2090,7 +2090,7 @@ return 1
""" """
# Create a root level zope user # Create a root level zope user
root_user_folder = self.getPortalObject().aq_parent.acl_users root_user_folder = self.getPortalObject().aq_parent.acl_users
if not root_user_folder.getUser('zope_user'): if not root_user_folder.getUserById('zope_user'):
root_user_folder._doAddUser('zope_user', '', ['Manager',], []) root_user_folder._doAddUser('zope_user', '', ['Manager',], [])
self.commit() self.commit()
# Create document with good content # Create document with good content
......
...@@ -335,15 +335,15 @@ class ERP5KeyAuthPlugin(ERP5UserManager, CookieAuthHelper): ...@@ -335,15 +335,15 @@ class ERP5KeyAuthPlugin(ERP5UserManager, CookieAuthHelper):
return None return None
#Search the user by his login #Search the user by his login
user_list = self.getUserByLogin(login) user = self.getUser(login)
if len(user_list) != 1: if user is None:
raise _AuthenticationFailure() raise _AuthenticationFailure()
user = user_list[0] user_value = user.getUserValue()
if True: if True:
try: try:
# get assignment list # get assignment list
assignment_list = [x for x in user.contentValues(portal_type="Assignment") \ assignment_list = [x for x in user_value.contentValues(portal_type="Assignment") \
if x.getValidationState() == "open"] if x.getValidationState() == "open"]
valid_assignment_list = [] valid_assignment_list = []
# check dates if exist # check dates if exist
...@@ -359,7 +359,7 @@ class ERP5KeyAuthPlugin(ERP5UserManager, CookieAuthHelper): ...@@ -359,7 +359,7 @@ class ERP5KeyAuthPlugin(ERP5UserManager, CookieAuthHelper):
# validate # validate
if len(valid_assignment_list) > 0: if len(valid_assignment_list) > 0:
return (login, login) return (user.getId(), user.getUserName())
finally: finally:
pass pass
......
...@@ -115,7 +115,7 @@ class TestUserManagement(ERP5TypeTestCase): ...@@ -115,7 +115,7 @@ class TestUserManagement(ERP5TypeTestCase):
from Products.PluggableAuthService.interfaces.plugins import\ from Products.PluggableAuthService.interfaces.plugins import\
IAuthenticationPlugin IAuthenticationPlugin
uf = self.getUserFolder() uf = self.getUserFolder()
self.assertNotEquals(uf.getUserById(login, None), None) self.assertNotEquals(uf.getUser(login), None)
for plugin_name, plugin in uf._getOb('plugins').listPlugins( for plugin_name, plugin in uf._getOb('plugins').listPlugins(
IAuthenticationPlugin ): IAuthenticationPlugin ):
if plugin.authenticateCredentials( if plugin.authenticateCredentials(
......
...@@ -260,7 +260,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -260,7 +260,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
'''Creates the default user.''' '''Creates the default user.'''
uf = self.portal.acl_users uf = self.portal.acl_users
# do nothing if the user already exists # do nothing if the user already exists
if not uf.getUser(user_name): if not uf.getUserById(user_name):
uf._doAddUser(user_name, 'secret', ['Member'], []) uf._doAddUser(user_name, 'secret', ['Member'], [])
def _setUpDummyMailHost(self): def _setUpDummyMailHost(self):
......
...@@ -1419,7 +1419,7 @@ class _TestZodbComponent(SecurityTestCase): ...@@ -1419,7 +1419,7 @@ class _TestZodbComponent(SecurityTestCase):
otherwise it should not be importable at all otherwise it should not be importable at all
""" """
uf = self.portal.acl_users uf = self.portal.acl_users
if not uf.getUser('ERP5TypeTestCase_NonDeveloper'): if not uf.getUserById('ERP5TypeTestCase_NonDeveloper'):
uf._doAddUser('ERP5TypeTestCase_NonDeveloper', uf._doAddUser('ERP5TypeTestCase_NonDeveloper',
'', ['Manager', 'Member', 'Assignee', '', ['Manager', 'Member', 'Assignee',
'Assignor', 'Author', 'Auditor', 'Associate'], []) 'Assignor', 'Author', 'Auditor', 'Associate'], [])
......
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