Commit f1f5a7dd by Clinton Blackburn Committed by Clinton Blackburn

Disabled edx-notes for anonymous users

parent 7c94131e
...@@ -61,9 +61,7 @@ class TabTestCase(SharedModuleStoreTestCase): ...@@ -61,9 +61,7 @@ class TabTestCase(SharedModuleStoreTestCase):
""" """
Creates a mock user with the specified properties. Creates a mock user with the specified properties.
""" """
user = UserFactory() user = UserFactory(is_staff=is_staff)
user.name = 'mock_user'
user.is_staff = is_staff
user.is_enrolled = is_enrolled user.is_enrolled = is_enrolled
user.is_authenticated = lambda: is_authenticated user.is_authenticated = lambda: is_authenticated
return user return user
......
...@@ -24,13 +24,16 @@ def edxnotes(cls): ...@@ -24,13 +24,16 @@ def edxnotes(cls):
is_studio = getattr(self.system, "is_author_mode", False) is_studio = getattr(self.system, "is_author_mode", False)
course = self.descriptor.runtime.modulestore.get_course(self.runtime.course_id) course = self.descriptor.runtime.modulestore.get_course(self.runtime.course_id)
# Must be disabled: # Must be disabled when:
# - in Studio; # - in Studio
# - when Harvard Annotation Tool is enabled for the course; # - Harvard Annotation Tool is enabled for the course
# - when the feature flag or `edxnotes` setting of the course is set to False. # - the feature flag or `edxnotes` setting of the course is set to False
if is_studio or not is_feature_enabled(course): # - the user is not authenticated
user = self.runtime.get_real_user(self.runtime.anonymous_student_id)
if is_studio or not is_feature_enabled(course) or not user.is_authenticated():
return original_get_html(self, *args, **kwargs) return original_get_html(self, *args, **kwargs)
else: else:
return render_to_string("edxnotes_wrapper.html", { return render_to_string("edxnotes_wrapper.html", {
"content": original_get_html(self, *args, **kwargs), "content": original_get_html(self, *args, **kwargs),
"uid": generate_uid(), "uid": generate_uid(),
...@@ -41,7 +44,7 @@ def edxnotes(cls): ...@@ -41,7 +44,7 @@ def edxnotes(cls):
# Use camelCase to name keys. # Use camelCase to name keys.
"usageId": unicode(self.scope_ids.usage_id).encode("utf-8"), "usageId": unicode(self.scope_ids.usage_id).encode("utf-8"),
"courseId": unicode(self.runtime.course_id).encode("utf-8"), "courseId": unicode(self.runtime.course_id).encode("utf-8"),
"token": get_edxnotes_id_token(self.runtime.get_real_user(self.runtime.anonymous_student_id)), "token": get_edxnotes_id_token(user),
"tokenUrl": get_token_url(self.runtime.course_id), "tokenUrl": get_token_url(self.runtime.course_id),
"endpoint": get_public_endpoint(), "endpoint": get_public_endpoint(),
"debug": settings.DEBUG, "debug": settings.DEBUG,
......
...@@ -31,6 +31,9 @@ class EdxNotesTab(EnrolledTab): ...@@ -31,6 +31,9 @@ class EdxNotesTab(EnrolledTab):
if not settings.FEATURES.get("ENABLE_EDXNOTES") or is_harvard_notes_enabled(course): if not settings.FEATURES.get("ENABLE_EDXNOTES") or is_harvard_notes_enabled(course):
return False return False
if user and not user.is_authenticated():
return False
return course.edxnotes return course.edxnotes
......
...@@ -10,6 +10,7 @@ from unittest import skipUnless ...@@ -10,6 +10,7 @@ from unittest import skipUnless
import ddt import ddt
import jwt import jwt
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.client import RequestFactory from django.test.client import RequestFactory
...@@ -72,10 +73,10 @@ class TestProblem(object): ...@@ -72,10 +73,10 @@ class TestProblem(object):
The purpose of this class is to imitate any problem. The purpose of this class is to imitate any problem.
""" """
def __init__(self, course): def __init__(self, course, user=None):
self.system = MagicMock(is_author_mode=False) self.system = MagicMock(is_author_mode=False)
self.scope_ids = MagicMock(usage_id="test_usage_id") self.scope_ids = MagicMock(usage_id="test_usage_id")
self.user = UserFactory.create(username="Joe", email="joe@example.com", password="edx") self.user = user or UserFactory()
self.runtime = MagicMock(course_id=course.id, get_real_user=lambda anon_id: self.user) self.runtime = MagicMock(course_id=course.id, get_real_user=lambda anon_id: self.user)
self.descriptor = MagicMock() self.descriptor = MagicMock()
self.descriptor.runtime.modulestore.get_course.return_value = course self.descriptor.runtime.modulestore.get_course.return_value = course
...@@ -100,9 +101,9 @@ class EdxNotesDecoratorTest(ModuleStoreTestCase): ...@@ -100,9 +101,9 @@ class EdxNotesDecoratorTest(ModuleStoreTestCase):
ClientFactory(name="edx-notes") ClientFactory(name="edx-notes")
# Using old mongo because of locator comparison issues (see longer # Using old mongo because of locator comparison issues (see longer
# note below in EdxNotesHelpersTest setUp. # note below in EdxNotesHelpersTest setUp.
self.course = CourseFactory.create(edxnotes=True, default_store=ModuleStoreEnum.Type.mongo) self.course = CourseFactory(edxnotes=True, default_store=ModuleStoreEnum.Type.mongo)
self.user = UserFactory.create(username="Bob", email="bob@example.com", password="edx") self.user = UserFactory()
self.client.login(username=self.user.username, password="edx") self.client.login(username=self.user.username, password=UserFactory._DEFAULT_PASSWORD)
self.problem = TestProblem(self.course) self.problem = TestProblem(self.course)
@patch.dict("django.conf.settings.FEATURES", {'ENABLE_EDXNOTES': True}) @patch.dict("django.conf.settings.FEATURES", {'ENABLE_EDXNOTES': True})
...@@ -170,6 +171,13 @@ class EdxNotesDecoratorTest(ModuleStoreTestCase): ...@@ -170,6 +171,13 @@ class EdxNotesDecoratorTest(ModuleStoreTestCase):
enable_edxnotes_for_the_course(self.course, self.user.id) enable_edxnotes_for_the_course(self.course, self.user.id)
self.assertEqual("original_get_html", self.problem.get_html()) self.assertEqual("original_get_html", self.problem.get_html())
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_EDXNOTES": True})
def test_anonymous_user(self):
user = AnonymousUser()
problem = TestProblem(self.course, user)
enable_edxnotes_for_the_course(self.course, None)
assert problem.get_html() == "original_get_html"
@attr(shard=3) @attr(shard=3)
@skipUnless(settings.FEATURES["ENABLE_EDXNOTES"], "EdxNotes feature needs to be enabled.") @skipUnless(settings.FEATURES["ENABLE_EDXNOTES"], "EdxNotes feature needs to be enabled.")
......
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