misc: fix has_role filter when user is proxied (#50874)
gitea-wip/combo/pipeline/head Build started... Details
gitea/combo/pipeline/head Build started... Details

This commit is contained in:
Lauréline Guérin 2021-02-04 15:49:14 +01:00
parent d0fc3f581c
commit f333ce7b1c
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 6 additions and 0 deletions

View File

@ -291,6 +291,8 @@ def shown_because_admin(cell, request):
def has_role(user, groupname):
if not user or user.is_anonymous:
return False
if not hasattr(user, 'groups'):
return False
return user.groups.filter(name=groupname).exists()

View File

@ -17,6 +17,7 @@ from django.utils.timezone import now
from combo.data.models import Page, TextCell
from combo.apps.assets.models import Asset
from combo.profile.utils import get_user_from_name_id
pytestmark = pytest.mark.django_db
@ -109,6 +110,9 @@ def test_has_role():
assert t.render(context) == 'False'
request.user = AnonymousUser()
assert t.render(context) == 'False'
context['selected_user'] = get_user_from_name_id('unknown')
t = Template('{{ selected_user|has_role:"Role2" }}')
assert t.render(context) == 'False'
def test_get():