Commit 62d8d3ac by Vincent Pelletier

Use PAS API: take 2.

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