From a14ced4d18ce868b9b2d7a37ce4d937c734f09e6 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 5 Oct 2019 10:30:04 +0200 Subject: [PATCH] dj22: use user.is_authenticated as a boolean (#36708) --- hobo/context_processors.py | 2 +- hobo/rest_authentication.py | 9 ++++----- hobo/views.py | 2 +- tests_authentic/test_rest_authentication.py | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/hobo/context_processors.py b/hobo/context_processors.py index b0acdf7..436cbdd 100644 --- a/hobo/context_processors.py +++ b/hobo/context_processors.py @@ -160,7 +160,7 @@ def portal_agent_url(request): if 'authentic2' in settings.INSTALLED_APPS: portal_agents = [x for x in settings.KNOWN_SERVICES.get('combo', {}).values() if x.get('is-portal-agent')] - if len(portal_agents) > 1 and request.user and request.user.is_authenticated() and request.user.ou_id: + if len(portal_agents) > 1 and request.user and request.user.is_authenticated and request.user.ou_id: ou_slug = request.user.ou.slug for portal_agent in portal_agents: variables = portal_agent.get('variables') or {} diff --git a/hobo/rest_authentication.py b/hobo/rest_authentication.py index 765e440..88c544a 100644 --- a/hobo/rest_authentication.py +++ b/hobo/rest_authentication.py @@ -18,8 +18,8 @@ except ImportError: class AnonymousAuthenticServiceUser(AnonymousUser): '''This virtual user hold permissions for other publik services''' - def is_authenticated(self): - return True + is_authenticated = True + is_anonymous = True def has_perm(self, perm_or_perms, obj=None): return True @@ -41,9 +41,8 @@ class AnonymousAuthenticServiceUser(AnonymousUser): class AnonymousAdminServiceUser(AnonymousUser): '''This virtual user hold permissions for other publik services''' is_staff = True - - def is_authenticated(self): - return True + is_authenticated = True + is_anonymous = True def __unicode__(self): return 'Publik Service Admin' diff --git a/hobo/views.py b/hobo/views.py index 63fb584..8f59ac6 100644 --- a/hobo/views.py +++ b/hobo/views.py @@ -19,7 +19,7 @@ from .environment.utils import Zone, get_installed_services from .forms import HoboForm, HoboUpdateForm, get_tenant_model def is_superuser(u): - if not u.is_authenticated(): + if not u.is_authenticated: return False if not u.is_superuser: raise PermissionDenied diff --git a/tests_authentic/test_rest_authentication.py b/tests_authentic/test_rest_authentication.py index e059ea3..2b15bf4 100644 --- a/tests_authentic/test_rest_authentication.py +++ b/tests_authentic/test_rest_authentication.py @@ -46,7 +46,7 @@ def test_publik_authentication(tenant, settings): assert isinstance(result, tuple) assert len(result) == 2 assert result[0].__class__ is rest_authentication.AnonymousAdminServiceUser - assert result[0].is_authenticated() + assert result[0].is_authenticated assert result[0].is_staff assert result[1] is None