Commit f1f5a7dd by Clinton Blackburn Committed by Clinton Blackburn

Disabled edx-notes for anonymous users

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