diff --git a/news/135.bugfix b/news/135.bugfix new file mode 100644 index 0000000..20bbce6 --- /dev/null +++ b/news/135.bugfix @@ -0,0 +1 @@ +Fix the currentUser operation when the current user's username is different from their user id. @davisagli diff --git a/plone/app/querystring/queryparser.py b/plone/app/querystring/queryparser.py index a4ab776..4ade30e 100644 --- a/plone/app/querystring/queryparser.py +++ b/plone/app/querystring/queryparser.py @@ -213,7 +213,7 @@ def _currentUser(context, row): """Current user lookup""" mt = getToolByName(context, "portal_membership") user = mt.getAuthenticatedMember() - return {row.index: {"query": user.getUserName()}} + return {row.index: {"query": user.getId()}} def _showInactive(context, row): diff --git a/plone/app/querystring/tests/testQueryParser.py b/plone/app/querystring/tests/testQueryParser.py index 5074b69..d195218 100644 --- a/plone/app/querystring/tests/testQueryParser.py +++ b/plone/app/querystring/tests/testQueryParser.py @@ -116,14 +116,12 @@ class MockNavRoot(MockObject): class MockUser: - def __init__(self, username=None, roles=None): - self.username = "Anonymous User" - if username: - self.username = username + def __init__(self, userid=None, roles=None): + self.userid = userid or "Anonymous User" self.roles = roles or "Anonymous" - def getUserName(self): - return self.username + def getId(self): + return self.userid def getRoles(self): return self.roles @@ -466,7 +464,7 @@ def test__currentUser(self): self.assertEqual(parsed, expected) # Logged in user 'admin' - u = MockUser(username="admin") + u = MockUser(userid="admin") pm = MockPortal_membership(user=u) context = MockSite(portal_membership=pm) data = Row(index="Creator", operator="_currentUser", values=None) @@ -486,7 +484,7 @@ def test__showInactive(self): self.assertEqual(parsed, expected) # Logged in user 'admin' - u = MockUser(username="admin", roles=("Manager",)) + u = MockUser(userid="admin", roles=("Manager",)) pm = MockPortal_membership(user=u) context = MockSite(portal_membership=pm) data = Row(index="show_inactive", operator="_showInactive", values=["Manager"])