Commit c0b50c7f by Waheed Ahmed

Change user.is_authenticated to user.is_authenticated() in roles.py.

LMS-2442
parent c73ac2af
...@@ -64,7 +64,7 @@ class GlobalStaff(AccessRole): ...@@ -64,7 +64,7 @@ class GlobalStaff(AccessRole):
def add_users(self, *users): def add_users(self, *users):
for user in users: for user in users:
if (user.is_authenticated and user.is_active): if (user.is_authenticated() and user.is_active):
user.is_staff = True user.is_staff = True
user.save() user.save()
...@@ -98,7 +98,7 @@ class GroupBasedRole(AccessRole): ...@@ -98,7 +98,7 @@ class GroupBasedRole(AccessRole):
""" """
Return whether the supplied django user has access to this role. Return whether the supplied django user has access to this role.
""" """
if not (user.is_authenticated and user.is_active): if not (user.is_authenticated() and user.is_active):
return False return False
# pylint: disable=protected-access # pylint: disable=protected-access
...@@ -113,7 +113,7 @@ class GroupBasedRole(AccessRole): ...@@ -113,7 +113,7 @@ class GroupBasedRole(AccessRole):
""" """
# silently ignores anonymous and inactive users so that any that are # silently ignores anonymous and inactive users so that any that are
# legit get updated. # legit get updated.
users = [user for user in users if user.is_authenticated and user.is_active] users = [user for user in users if user.is_authenticated() and user.is_active]
group, _ = Group.objects.get_or_create(name=self._group_names[0]) group, _ = Group.objects.get_or_create(name=self._group_names[0])
group.user_set.add(*users) group.user_set.add(*users)
# remove cache # remove cache
......
...@@ -4,7 +4,7 @@ Tests authz.py ...@@ -4,7 +4,7 @@ Tests authz.py
import mock import mock
from django.test import TestCase from django.test import TestCase
from django.contrib.auth.models import User from django.contrib.auth.models import User, AnonymousUser
from xmodule.modulestore import Location from xmodule.modulestore import Location
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
...@@ -78,9 +78,10 @@ class CreatorGroupTest(TestCase): ...@@ -78,9 +78,10 @@ class CreatorGroupTest(TestCase):
""" """
with mock.patch.dict('django.conf.settings.FEATURES', with mock.patch.dict('django.conf.settings.FEATURES',
{'DISABLE_COURSE_CREATION': False, "ENABLE_CREATOR_GROUP": True}): {'DISABLE_COURSE_CREATION': False, "ENABLE_CREATOR_GROUP": True}):
self.user.is_authenticated = False anonymous_user = AnonymousUser()
add_users(self.admin, CourseCreatorRole(), self.user) role = CourseCreatorRole()
self.assertFalse(has_access(self.user, CourseCreatorRole())) add_users(self.admin, role, anonymous_user)
self.assertFalse(has_access(anonymous_user, role))
def test_add_user_not_active(self): def test_add_user_not_active(self):
""" """
......
...@@ -5,7 +5,7 @@ import unittest ...@@ -5,7 +5,7 @@ import unittest
from student.tests.factories import UserFactory, RegistrationFactory, PendingEmailChangeFactory from student.tests.factories import UserFactory, RegistrationFactory, PendingEmailChangeFactory
from student.views import reactivation_email_for_user, change_email_request, confirm_email_change from student.views import reactivation_email_for_user, change_email_request, confirm_email_change
from student.models import UserProfile, PendingEmailChange from student.models import UserProfile, PendingEmailChange
from django.contrib.auth.models import User from django.contrib.auth.models import User, AnonymousUser
from django.test import TestCase, TransactionTestCase from django.test import TestCase, TransactionTestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
from mock import Mock, patch from mock import Mock, patch
...@@ -157,10 +157,11 @@ class EmailChangeRequestTests(TestCase): ...@@ -157,10 +157,11 @@ class EmailChangeRequestTests(TestCase):
self.assertFalse(self.user.email_user.called) self.assertFalse(self.user.email_user.called)
def test_unauthenticated(self): def test_unauthenticated(self):
self.user.is_authenticated = False self.request.user = AnonymousUser()
self.request.user.email_user = Mock()
with self.assertRaises(Http404): with self.assertRaises(Http404):
change_email_request(self.request) change_email_request(self.request)
self.assertFalse(self.user.email_user.called) self.assertFalse(self.request.user.email_user.called)
def test_invalid_password(self): def test_invalid_password(self):
self.request.POST['password'] = 'wrong' self.request.POST['password'] = 'wrong'
......
...@@ -1522,7 +1522,7 @@ def change_email_request(request): ...@@ -1522,7 +1522,7 @@ def change_email_request(request):
""" AJAX call from the profile page. User wants a new e-mail. """ AJAX call from the profile page. User wants a new e-mail.
""" """
## Make sure it checks for existing e-mail conflicts ## Make sure it checks for existing e-mail conflicts
if not request.user.is_authenticated: if not request.user.is_authenticated():
raise Http404 raise Http404
user = request.user user = request.user
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment