diff --git a/lms/djangoapps/notes/api.py b/lms/djangoapps/notes/api.py index 296ec2766f..bf7b1005ad 100644 --- a/lms/djangoapps/notes/api.py +++ b/lms/djangoapps/notes/api.py @@ -2,6 +2,8 @@ from django.contrib.auth.decorators import login_required from django.http import HttpResponse, Http404 from django.core.exceptions import ValidationError from notes.models import Note +from notes.utils import notes_enabled_for_course +from courseware.courses import get_course_with_access import json import logging @@ -34,6 +36,11 @@ def api_request(request, course_id, **kwargs): Raises a 404 if the resource type doesn't exist, or if there is no action method associated with the HTTP method. ''' + course = get_course_with_access(request.user, course_id, 'load') + if not notes_enabled_for_course(course): + log.debug('Notes not enabled for course') + raise Http404 + resource_map = api_resource_map() resource_name = kwargs.pop('resource') resource = resource_map.get(resource_name) diff --git a/lms/djangoapps/notes/utils.py b/lms/djangoapps/notes/utils.py new file mode 100644 index 0000000000..e06df3e42a --- /dev/null +++ b/lms/djangoapps/notes/utils.py @@ -0,0 +1,5 @@ +# TODO: make a separate policy setting to enable/disable notes. +def notes_enabled_for_course(course): + ''' Returns True if notes are enabled for the course, False otherwise. ''' + notes_tab_type = 'notes' + return next((True for tab in course.tabs if tab['type'] == notes_tab_type), False) diff --git a/lms/djangoapps/notes/views.py b/lms/djangoapps/notes/views.py index 865e894ac1..ba47540071 100644 --- a/lms/djangoapps/notes/views.py +++ b/lms/djangoapps/notes/views.py @@ -1,13 +1,18 @@ from django.contrib.auth.decorators import login_required +from django.http import Http404 from mitxmako.shortcuts import render_to_response from courseware.courses import get_course_with_access from notes.models import Note +from notes.utils import notes_enabled_for_course import json @login_required def notes(request, course_id): - ''' Displays a student's notes in a course. ''' + ''' Displays the student's notes. ''' + course = get_course_with_access(request.user, course_id, 'load') + if not notes_enabled_for_course(course): + raise Http404 notes = Note.objects.filter(course_id=course_id, user=request.user).order_by('-created', 'uri') json_notes = json.dumps([n.as_dict() for n in notes]) diff --git a/lms/djangoapps/staticbook/views.py b/lms/djangoapps/staticbook/views.py index 04433f0e0e..6d3dcbd5ca 100644 --- a/lms/djangoapps/staticbook/views.py +++ b/lms/djangoapps/staticbook/views.py @@ -5,6 +5,7 @@ from mitxmako.shortcuts import render_to_response from courseware.access import has_access from courseware.courses import get_course_with_access +from notes.utils import notes_enabled_for_course from static_replace import replace_static_urls @@ -102,6 +103,7 @@ def html_index(request, course_id, book_index, chapter=None): """ course = get_course_with_access(request.user, course_id, 'load') staff_access = has_access(request.user, course, 'staff') + notes_enabled = notes_enabled_for_course(course) book_index = int(book_index) if book_index < 0 or book_index >= len(course.html_textbooks): @@ -130,4 +132,5 @@ def html_index(request, course_id, book_index, chapter=None): 'course': course, 'textbook': textbook, 'chapter': chapter, - 'staff_access': staff_access}) + 'staff_access': staff_access, + 'notes_enabled': notes_enabled}) diff --git a/lms/templates/static_htmlbook.html b/lms/templates/static_htmlbook.html index ae04f7343a..8a3c50f680 100644 --- a/lms/templates/static_htmlbook.html +++ b/lms/templates/static_htmlbook.html @@ -31,11 +31,14 @@ anchorToLoad = options.anchor_id; } - var onComplete = function(url) { - return function() { - $('#viewerContainer').trigger('notes:init', [url]); - } - }; + var onComplete = function() {}; + if(options.notesEnabled) { + onComplete = function(url) { + return function() { + $('#viewerContainer').trigger('notes:init', [url]); + } + }; + } loadUrl = function htmlViewLoadUrl(url, anchorId) { // clear out previous load, if any: @@ -102,6 +105,11 @@ options.anchor_id = ${anchor_id}; %endif + options.notesEnabled = false; + %if notes_enabled is not UNDEFINED and notes_enabled: + options.notesEnabled = true; + %endif + $('#outerContainer').myHTMLViewer(options); });