dj22: use user.is_authenticated as a boolean or callable (#37503)

This commit is contained in:
Thomas NOËL 2019-11-07 01:12:40 +01:00
parent ef552c210e
commit ce798bc587
2 changed files with 20 additions and 4 deletions

View File

@ -8,6 +8,7 @@ from django.contrib.auth import get_user_model
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.db.models.fields import FieldDoesNotExist
from django.utils.deprecation import CallableTrue
from django.utils.module_loading import import_string
try:
@ -18,8 +19,14 @@ except ImportError:
class AnonymousAuthenticServiceUser(AnonymousUser):
'''This virtual user hold permissions for other publik services'''
is_authenticated = True
is_anonymous = True
@property
def is_anonymous(self):
return CallableTrue
@property
def is_authenticated(self):
return CallableTrue
def has_perm(self, perm_or_perms, obj=None):
return True
@ -41,8 +48,14 @@ class AnonymousAuthenticServiceUser(AnonymousUser):
class AnonymousAdminServiceUser(AnonymousUser):
'''This virtual user hold permissions for other publik services'''
is_staff = True
is_authenticated = True
is_anonymous = True
@property
def is_anonymous(self):
return CallableTrue
@property
def is_authenticated(self):
return CallableTrue
def __unicode__(self):
return 'Publik Service Admin'

View File

@ -47,6 +47,9 @@ def test_publik_authentication(tenant, settings):
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_anonymous
assert result[0].is_anonymous()
assert result[0].is_staff
assert result[1] is None