Commit 18e87e09 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

ERP5Security: fix getUserByLogin to work with ERP5 Login

parent bace6049
...@@ -70,8 +70,8 @@ def getUserByLogin(portal, login, exact_match=True): ...@@ -70,8 +70,8 @@ def getUserByLogin(portal, login, exact_match=True):
if not (portal.portal_catalog.hasColumn('portal_type') and portal.portal_catalog.hasColumn('reference')): if not (portal.portal_catalog.hasColumn('portal_type') and portal.portal_catalog.hasColumn('reference')):
raise RuntimeError('Catalog does not have column information. Make sure RDB is working and disk is not full.') raise RuntimeError('Catalog does not have column information. Make sure RDB is working and disk is not full.')
result = portal.portal_catalog.unrestrictedSearchResults( result = portal.portal_catalog.unrestrictedSearchResults(
select_expression='reference', select_expression='reference, portal_type',
portal_type="Person", portal_type=("ERP5 Login"),
reference=dict(query=login, key=reference_key)) reference=dict(query=login, key=reference_key))
# XXX: Here, we filter catalog result list ALTHOUGH we did pass # XXX: Here, we filter catalog result list ALTHOUGH we did pass
# parameters to unrestrictedSearchResults to restrict result set. # parameters to unrestrictedSearchResults to restrict result set.
...@@ -88,6 +88,15 @@ def getUserByLogin(portal, login, exact_match=True): ...@@ -88,6 +88,15 @@ def getUserByLogin(portal, login, exact_match=True):
# 1 row in set (0.01 sec) # 1 row in set (0.01 sec)
# "bar OR foo" because of ZSQLCatalog tokenizing searched strings # "bar OR foo" because of ZSQLCatalog tokenizing searched strings
# by default (feature). # by default (feature).
result_list = [x.getObject().getParentValue()
for x in result if not exact_match
or x['reference'] in login]
if result_list:
return result_list
result = portal.portal_catalog.unrestrictedSearchResults(
select_expression='reference, portal_type',
portal_type=("Person"),
reference=dict(query=login, key=reference_key))
return [x.getObject() for x in result if not exact_match return [x.getObject() for x in result if not exact_match
or x['reference'] in login] or x['reference'] in login]
......
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