Commit 1b06edb6 by Adam Palay

display banner on course info page if user is not enrolled (TNL-286)

write failing tests for info page banner
parent e569e090
......@@ -20,12 +20,19 @@ class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
data="OOGIE BLOOGIE", display_name="updates"
)
def test_logged_in(self):
def test_logged_in_unenrolled(self):
self.setup_user()
url = reverse('info', args=[self.course.id.to_deprecated_string()])
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
self.assertIn("OOGIE BLOOGIE", resp.content)
self.assertIn("You are not currently enrolled in this course", resp.content)
def test_logged_in_enrolled(self):
self.enroll(self.course)
url = reverse('info', args=[self.course.id.to_deprecated_string()])
resp = self.client.get(url)
self.assertNotIn("You are not currently enrolled in this course", resp.content)
def test_anonymous_user(self):
url = reverse('info', args=[self.course.id.to_deprecated_string()])
......
......@@ -19,7 +19,7 @@ from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_GET
from django.http import Http404, HttpResponse
from django.shortcuts import redirect
from edxmako.shortcuts import render_to_response, render_to_string
from edxmako.shortcuts import render_to_response, render_to_string, marketing_link
from django_future.csrf import ensure_csrf_cookie
from django.views.decorators.cache import cache_control
from django.db import transaction
......@@ -569,6 +569,14 @@ def course_info(request, course_id):
reverifications = fetch_reverify_banner_info(request, course_key)
studio_url = get_studio_url(course, 'course_info')
# link to where the student should go to enroll in the course:
# about page if there is not marketing site, SITE_NAME if there is
url_to_enroll = reverse(course_about, args=[course_id])
if settings.FEATURES.get('ENABLE_MKTG_SITE'):
url_to_enroll = marketing_link('COURSES')
show_enroll_banner = request.user.is_authenticated() and not CourseEnrollment.is_enrolled(request.user, course.id)
context = {
'request': request,
'course_id': course_key.to_deprecated_string(),
......@@ -578,6 +586,8 @@ def course_info(request, course_id):
'masquerade': masq,
'studio_url': studio_url,
'reverifications': reverifications,
'show_enroll_banner': show_enroll_banner,
'url_to_enroll': url_to_enroll,
}
return render_to_response('courseware/info.html', context)
......@@ -806,7 +816,7 @@ def _progress(request, course_key, student_id):
Course staff are allowed to see the progress of students in their class.
"""
course = get_course_with_access(request.user, 'load', course_key, depth=None)
course = get_course_with_access(request.user, 'load', course_key, depth=None, check_if_enrolled=True)
staff_access = has_access(request.user, 'staff', course)
if student_id is None or student_id == request.user.id:
......
......@@ -13,6 +13,24 @@
<%include file="/dashboard/_dashboard_prompt_midcourse_reverify.html" />
% if show_enroll_banner:
<div class="wrapper-msg urgency-low" id="failed-verification-banner">
<div class="msg msg-reverify is-dismissable">
<div class="msg-content">
<h2 class="title">${_("You are not enrolled yet")}</h2>
<div class="copy">
<p class='enroll-message'>
${_(u"You are not currently enrolled in this course. Sign up for it {link_start}here{link_end}!").format(
link_start=u"<a href={}>".format(url_to_enroll),
link_end=u"</a>"
)}
</p>
</div>
</div>
</div>
</div>
% endif
<%include file="/courseware/course_navigation.html" args="active_page='info'" />
<%block name="js_extra">
......@@ -36,7 +54,7 @@ $(document).ready(function(){
</div>
% endif
% endif
<h1>${_("Course Updates &amp; News")}</h1>
${get_course_info_section(request, course, 'updates')}
</section>
......
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