Skip to content

Commit

Permalink
Merge pull request #136 from plone/fix-currentUser
Browse files Browse the repository at this point in the history
Fix currentUser operation
  • Loading branch information
davisagli authored Aug 17, 2023
2 parents f5bfc7b + 26d6e56 commit 2a5a5cd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions news/135.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the currentUser operation when the current user's username is different from their user id. @davisagli
2 changes: 1 addition & 1 deletion plone/app/querystring/queryparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 6 additions & 8 deletions plone/app/querystring/tests/testQueryParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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"])
Expand Down

0 comments on commit 2a5a5cd

Please sign in to comment.