Commit f827c538 by Waheed Ahmed

Merge pull request #4460 from edx/waheed/lms6617-disable-student-view-if-course-is-not-released

Disabled student view if course is not yet released for students.
parents 4aa2dc52 3c8eacd4
...@@ -6,6 +6,7 @@ import logging ...@@ -6,6 +6,7 @@ import logging
import urllib import urllib
import json import json
from datetime import datetime
from collections import defaultdict from collections import defaultdict
from django.utils import translation from django.utils import translation
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
...@@ -16,6 +17,7 @@ from django.core.exceptions import PermissionDenied ...@@ -16,6 +17,7 @@ from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.models import User, AnonymousUser from django.contrib.auth.models import User, AnonymousUser
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.utils.timezone import UTC
from django.views.decorators.http import require_GET from django.views.decorators.http import require_GET
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
...@@ -27,7 +29,7 @@ from functools import wraps ...@@ -27,7 +29,7 @@ from functools import wraps
from markupsafe import escape from markupsafe import escape
from courseware import grades from courseware import grades
from courseware.access import has_access from courseware.access import has_access, _adjust_start_date_for_beta_testers
from courseware.courses import get_courses, get_course, get_studio_url, get_course_with_access, sort_by_announcement from courseware.courses import get_courses, get_course, get_studio_url, get_course_with_access, sort_by_announcement
from courseware.masquerade import setup_masquerade from courseware.masquerade import setup_masquerade
from courseware.model_data import FieldDataCache from courseware.model_data import FieldDataCache
...@@ -337,6 +339,13 @@ def index(request, course_id, chapter=None, section=None, ...@@ -337,6 +339,13 @@ def index(request, course_id, chapter=None, section=None,
'reverifications': fetch_reverify_banner_info(request, course_key), 'reverifications': fetch_reverify_banner_info(request, course_key),
} }
now = datetime.now(UTC())
effective_start = _adjust_start_date_for_beta_testers(user, course, course_key)
if staff_access and now < effective_start:
# Disable student view button if user is staff and
# course is not yet visible to students.
context['disable_student_access'] = True
has_content = course.has_children_at_depth(CONTENT_DEPTH) has_content = course.has_children_at_depth(CONTENT_DEPTH)
if not has_content: if not has_content:
# Show empty courseware for a course with no units # Show empty courseware for a course with no units
...@@ -590,6 +599,13 @@ def course_info(request, course_id): ...@@ -590,6 +599,13 @@ def course_info(request, course_id):
'url_to_enroll': url_to_enroll, 'url_to_enroll': url_to_enroll,
} }
now = datetime.now(UTC())
effective_start = _adjust_start_date_for_beta_testers(request.user, course, course_key)
if staff_access and now < effective_start:
# Disable student view button if user is staff and
# course is not yet visible to students.
context['disable_student_access'] = True
return render_to_response('courseware/info.html', context) return render_to_response('courseware/info.html', context)
......
...@@ -62,6 +62,10 @@ def url_class(is_active): ...@@ -62,6 +62,10 @@ def url_class(is_active):
<script type="text/javascript"> <script type="text/javascript">
masq = (function(){ masq = (function(){
var el = $('#staffstatus'); var el = $('#staffstatus');
% if disable_student_access:
el.attr("disabled", true);
el.attr("title", "${_("Course is not yet visible to students.")}");
% endif
var setstat = function(status){ var setstat = function(status){
if (status=='student'){ if (status=='student'){
el.html('<font color="green">${_("Student view")}</font>'); el.html('<font color="green">${_("Student view")}</font>');
...@@ -72,6 +76,9 @@ masq = (function(){ ...@@ -72,6 +76,9 @@ masq = (function(){
setstat('${masquerade}'); setstat('${masquerade}');
el.click(function(){ el.click(function(){
if (el.attr("disabled")) {
return alert("${_("You cannot view the course as a student or beta tester before the course release date.")}");
}
$.ajax({ url: '/masquerade/toggle', $.ajax({ url: '/masquerade/toggle',
type: 'GET', type: 'GET',
success: function(result){ success: function(result){
......
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