misc: fix |has_role filter used on bad object (#62439)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Lauréline Guérin 2022-03-04 16:18:04 +01:00
parent c4de7aa569
commit b39e5a9f57
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 5 additions and 1 deletions

View File

@ -320,7 +320,7 @@ def shown_because_admin(cell, request):
@register.filter(name='has_role')
def has_role(user, groupname):
if not user or user.is_anonymous:
if not user or getattr(user, 'is_anonymous', True):
return False
if not hasattr(user, 'groups'):
return False

View File

@ -116,6 +116,10 @@ def test_has_role():
t = Template('{{ selected_user|has_role:"Role2" }}')
assert t.render(context) == 'False'
# filter not on user object
t = Template('{{ request|has_role:"Role1" }}')
assert t.render(context) == 'False'
def test_get():
t = Template('{{ foo|get:"foo-bar" }}')