diff --git a/onadata/apps/main/models/user_profile.py b/onadata/apps/main/models/user_profile.py index 54e23257e..a36e040e9 100644 --- a/onadata/apps/main/models/user_profile.py +++ b/onadata/apps/main/models/user_profile.py @@ -6,9 +6,11 @@ from django.db import models from django.db.models.signals import post_save from django.utils.translation import ugettext_lazy +from guardian.conf import settings as guardian_settings from guardian.shortcuts import get_perms_for_model, assign_perm -from rest_framework.authtoken.models import Token from jsonfield import JSONField +from rest_framework.authtoken.models import Token + from onadata.libs.utils.country_field import COUNTRIES from onadata.libs.utils.gravatar import get_gravatar_img_link, gravatar_exists from onadata.apps.main.signals import set_api_permissions @@ -107,5 +109,6 @@ def get_anonymous_user_instance(User): :param User: User class :return: User instance """ + return User(pk=settings.ANONYMOUS_USER_ID, - username='AnonymousUser') + username=guardian_settings.ANONYMOUS_USER_NAME) diff --git a/onadata/settings/base.py b/onadata/settings/base.py index c48824928..0cc36f320 100644 --- a/onadata/settings/base.py +++ b/onadata/settings/base.py @@ -190,9 +190,6 @@ def skip_suspicious_operations(record): os.path.join(TEMPLATE_OVERRIDE_ROOT_DIR, 'static') ] -# needed by guardian -ANONYMOUS_USER_ID = -1 - INSTALLED_APPS = [ 'django.contrib.contenttypes', # Always put `contenttypes` before `auth`; see @@ -406,6 +403,12 @@ def skip_suspicious_operations(record): TESTING_MODE = False +# needed by guardian` +# Deprecated since v1.4.2. ToDo move to constants.py` +ANONYMOUS_USER_ID = -1 +# Needed to get ANONYMOUS_USER = -1 +GUARDIAN_GET_INIT_ANONYMOUS_USER = 'onadata.apps.main.models.user_profile.get_anonymous_user_instance' + PRINT_EXCEPTION = os.environ.get("PRINT_EXCEPTION", False) KOBOFORM_SERVER = os.environ.get("KOBOFORM_SERVER", "localhost") diff --git a/onadata/settings/testing.py b/onadata/settings/testing.py index 9ff9a0bd9..fa47524b4 100644 --- a/onadata/settings/testing.py +++ b/onadata/settings/testing.py @@ -44,8 +44,6 @@ TESTING_MODE = True TEST_HTTP_HOST = 'testserver.com' TEST_USERNAME = 'bob' -# Needed to get ANONYMOUS_USER = -1 in `testing` -GUARDIAN_GET_INIT_ANONYMOUS_USER = 'onadata.apps.main.models.user_profile.get_anonymous_user_instance' ################################ # Celery settings #