Commit dcb5eecb authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

ERP5Security: fix getUserByLogin to work with ERP5 Login

parent 6ab2ed8a
...@@ -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,8 +88,17 @@ def getUserByLogin(portal, login, exact_match=True): ...@@ -88,8 +88,17 @@ 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).
return [x.getObject() for x in result if not exact_match result_list = [x.getObject().getParentValue()
or x['reference'] in login] 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
or x['reference'] in login]
class ERP5UserManager(BasePlugin): class ERP5UserManager(BasePlugin):
......
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