Commit f78b0e95 authored by Alexandre Boeglin's avatar Alexandre Boeglin

Replaced all references to Person.id by Person.reference, like in

ERP5GroupManager. cleaned a bit.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5087 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c94e6d2f
...@@ -63,91 +63,83 @@ class ERP5UserManager(BasePlugin): ...@@ -63,91 +63,83 @@ class ERP5UserManager(BasePlugin):
security.declarePrivate( 'authenticateCredentials' ) security.declarePrivate( 'authenticateCredentials' )
def authenticateCredentials(self, credentials): def authenticateCredentials(self, credentials):
""" See IAuthenticationPlugin. """ See IAuthenticationPlugin.
o We expect the credentials to be those returned by o We expect the credentials to be those returned by
ILoginPasswordExtractionPlugin. ILoginPasswordExtractionPlugin.
""" """
def _authenticateCredentials(login, password, path): def _authenticateCredentials(login, password, path):
if login is None or password is None: if login is None or password is None:
return None return None
user_list = self.getUserByLogin(login) user_list = self.getUserByLogin(login)
if not user_list: if not user_list:
return None return None
user = user_list[0] user = user_list[0]
if user.getPassword() == password: if user.getPassword() == password and\
LOG('authenticateCredentials', 0, user.getId()) user.getCareerRole() == 'internal':
return user.getId(), login LOG('authenticateCredentials', 0, user.getId())
return login, login # use same for user_id and login
return None return None
_authenticateCredentials = CachingMethod(_authenticateCredentials, id='ERP5UserManager_authenticateCredentials') _authenticateCredentials = CachingMethod(_authenticateCredentials, id='ERP5UserManager_authenticateCredentials')
return _authenticateCredentials(login=credentials.get('login'), password=credentials.get('password'), path=self.getPhysicalPath()) return _authenticateCredentials(login=credentials.get('login'), password=credentials.get('password'), path=self.getPhysicalPath())
# #
# IUserEnumerationPlugin implementation # IUserEnumerationPlugin implementation
# #
security.declarePrivate( 'enumerateUsers' ) security.declarePrivate( 'enumerateUsers' )
def enumerateUsers(self, id=None, login=None, exact_match=False, sort_by=None, max_results=None, **kw): def enumerateUsers(self, id=None, login=None, exact_match=False, sort_by=None, max_results=None, **kw):
""" See IUserEnumerationPlugin. """ See IUserEnumerationPlugin.
""" """
def _enumerateUsers(t_id, path): def _enumerateUsers(id_tuple, exact_match, path):
user_info = [] user_info = []
user_objects = []
plugin_id = self.getId() plugin_id = self.getId()
if isinstance(t_id, str): if not exact_match:
t_id = (t_id,) id_tuple = tuple(['%%%s%%' % id for id in id_tuple])
if t_id: user_objects = [user for user in self.getUserByLogin(id_tuple)\
person_module = self.getPortalObject()\ if user.getCareerRole() == 'internal']
.getDefaultModule('Person') #XXX is this static check ok ?
for user_name in t_id:
user = getattr(person_module, user_name, None)
if user:
if user.getCareerRole() == 'internal':
user_objects.append(user)
elif login:
for user in self.getUserByLogin(login):
if user.getCareerRole() == 'internal':
user_objects.append(user)
for user in user_objects: for user in user_objects:
LOG('enumerateUsers', 0, user.getId()) LOG('enumerateUsers', 0, user.getReference())
info = { 'id' : user.getId() info = { 'id' : user.getReference()
, 'login' : user.getReference() , 'login' : user.getReference()
, 'pluginid' : plugin_id , 'pluginid' : plugin_id
} }
user_info.append(info) user_info.append(info)
return tuple(user_info) return tuple(user_info)
_enumerateUsers = CachingMethod(_enumerateUsers, id='ERP5UserManager_enumerateUsers') _enumerateUsers = CachingMethod(_enumerateUsers, id='ERP5UserManager_enumerateUsers')
if isinstance(id, str):
id = (id,)
if isinstance(id, list): if isinstance(id, list):
id = tuple(id) id = tuple(id)
return _enumerateUsers(t_id=id, path=self.getPhysicalPath()) return _enumerateUsers(id_tuple=id, exact_match=exact_match, path=self.getPhysicalPath())
def getUserByLogin(self, login): def getUserByLogin(self, login):
""" """
Search the Catalog for login and return a list of person objects Search the Catalog for login and return a list of person objects
login can be a string list or a list of strings login can be a string list or a list of strings
""" """
# because we aren't logged in, we have to create our own # because we aren't logged in, we have to create our own
# SecurityManager to be able to access the Catalog # SecurityManager to be able to access the Catalog
sm = getSecurityManager() sm = getSecurityManager()
newSecurityManager(self, self.getPortalObject().portal_catalog.getOwner()) newSecurityManager(self, self.getPortalObject().portal_catalog.getOwner())
result = self.getPortalObject().portal_catalog(portal_type="Person", reference=login) result = self.getPortalObject().portal_catalog(portal_type="Person", reference=login)
setSecurityManager(sm) setSecurityManager(sm)
return [item.getObject() for item in result] return [item.getObject() for item in result]
classImplements( ERP5UserManager classImplements( ERP5UserManager
, IAuthenticationPlugin , IAuthenticationPlugin
, IUserEnumerationPlugin , IUserEnumerationPlugin
......
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