diff --git a/common/test/acceptance/tests/studio/test_studio_outline.py b/common/test/acceptance/tests/studio/test_studio_outline.py index ef65e003c4..d7cd119d69 100644 --- a/common/test/acceptance/tests/studio/test_studio_outline.py +++ b/common/test/acceptance/tests/studio/test_studio_outline.py @@ -1449,13 +1449,6 @@ class DefaultStatesContentTest(CourseOutlineTest): self.assertEqual(courseware.xblock_component_type(1), 'html') self.assertEqual(courseware.xblock_component_type(2), 'discussion') - def test_unenroll_course(self): - self.course_outline_page.visit() - self.course_outline_page.view_live() - courseware = CoursewarePage(self.browser, self.course_id) - courseware.wait_for_page() - self.assertEqual(courseware.num_xblock_components, 3) - @attr('shard_3') class UnitNavigationTest(CourseOutlineTest): diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 8327f065c1..8f85e86e94 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -323,47 +323,54 @@ class ViewsTestCase(ModuleStoreTestCase): self.assertNotIn('Problem 1', response.content) self.assertNotIn('Problem 2', response.content) - def test_enroll_staff(self): + def _create_url_for_enroll_staff(self): """ - Here we check two methods GET and POST and should be a staff user + User will have satff access and creates the url for enroll_staff view """ self.user.is_staff = True - self.user.save() + self.user.save() # pylint: disable=no-member self.client.login(username=self.user.username, password=self.password) # create the course course = CourseFactory.create() - chapter = ItemFactory.create(parent=course, category='chapter') - section = ItemFactory.create(parent=chapter, category='sequential', display_name="Sequence") # create the _next parameter - courseware_url = reverse( - 'courseware_section', - kwargs={ - 'course_id': unicode(course.id), - 'chapter': chapter.url_name, - 'section': section.url_name, - } - ) + '?activate_block_id=test_block_id' + courseware_url = reverse('courseware', kwargs={ + 'course_id': course.id.to_deprecated_string()}) + '?activate_block_id=test_block_id' # create the url for enroll_staff view - url = "{enroll_staff_url}?next={courseware_url}".format( - enroll_staff_url= reverse('enroll_staff', kwargs={'course_id': unicode(course.id)}), - courseware_url= courseware_url + enroll_staff_url = "{enroll_staff_url}?next={courseware_url}".format( + enroll_staff_url=reverse('enroll_staff', kwargs={'course_id': unicode(course.id)}), + courseware_url=courseware_url ) + return enroll_staff_url + + def test_redirection_unenrolled_staff(self): + """ + Verify unenrolled staff is not redirected to the 'about' section of the chapter + """ + enroll_staff_url = self._create_url_for_enroll_staff() # Check the GET method - response = self.client.get(url) + response = self.client.get(enroll_staff_url) self.assertEqual(response.status_code, 200) response_content = response.content - self.assertIn('Enroll' , response_content) - self.assertIn('Continue', response_content) + self.assertIn('Enroll', response_content) + self.assertIn("Don't enroll", response_content) - # Check the POST Method - data = {'enroll' : 'Enroll'} - response_post = self.client.post(url, data=data) - # here we check the status code 302 because of the redirect - self.assertEqual(response_post.status_code, 302) + @ddt.data( + {'enroll': "Enroll"}, + {'dont_enroll': "Don't enroll"}, + ) + def test_redirection_unenrolled_staff_post_data(self, data): + """ + Verify unenrolled staff is redirected to the page according to data passed. + """ + enroll_staff_url = self._create_url_for_enroll_staff() + response = self.client.post(enroll_staff_url, data=data) + + # Here we check the status code 302 because of the redirect + self.assertEqual(response.status_code, 302) @unittest.skipUnless(settings.FEATURES.get('ENABLE_SHOPPING_CART'), "Shopping Cart not enabled in settings") @patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True}) diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 53b657ac0f..1c6b7b0514 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -354,12 +354,12 @@ def _index_bulk_op(request, course_key, chapter, section, position): if not registered: # TODO (vshnayder): do course instructors need to be registered to see course? log.debug(u'User %s tried to view course %s but is not enrolled', user, course.location.to_deprecated_string()) - if not bool(staff_access): + if bool(staff_access): + usage_key = UsageKey.from_string(course.location.to_deprecated_string()).replace(course_key=course_key) + redirect_url = get_redirect_url(course_key, usage_key) return redirect("{url}?{redirect}".format( url=reverse(enroll_staff, args=[course_key.to_deprecated_string()]), - redirect=request.GET.urlencode() - ) - ) + redirect=redirect_url)) return redirect(reverse('about_course', args=[course_key.to_deprecated_string()])) # see if all pre-requisites (as per the milestones app feature) have been fulfilled @@ -878,16 +878,18 @@ def enroll_staff(request, course_id): 'csrftoken': csrf(request)["csrf_token"] }) - elif request.method == 'POST' and 'enroll' in request.POST: - enrollment = CourseEnrollment.get_or_create_enrollment(user, course_key) - enrollment.update_enrollment(is_active=True) - log.info( - u"User %s enrolled in %s via `enroll_staff` view", - user.username, - course_id - ) - - return redirect(_next) + elif request.method == 'POST': + if 'enroll' in request.POST: + enrollment = CourseEnrollment.get_or_create_enrollment(user, course_key) + enrollment.update_enrollment(is_active=True) + log.info( + u"User %s enrolled in %s via `enroll_staff` view", + user.username, + course_id + ) + return redirect(_next) + else: + return redirect(reverse('about_course', args=[course_key.to_deprecated_string()])) @ensure_csrf_cookie diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index d6be03b833..a21db446bc 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -3289,6 +3289,7 @@ def validate_request_data_and_get_certificate(certificate_invalidation, course_k ) student = get_student(user, course_key) + certificate = GeneratedCertificate.certificate_for_student(student, course_key) if not certificate: raise ValueError(_( diff --git a/lms/djangoapps/instructor_task/api.py b/lms/djangoapps/instructor_task/api.py index 2898a21f50..10939226f4 100644 --- a/lms/djangoapps/instructor_task/api.py +++ b/lms/djangoapps/instructor_task/api.py @@ -446,7 +446,6 @@ def submit_export_ora2_data(request, course_key): def generate_certificates_for_students(request, course_key, student_set=None, specific_student_id=None): # pylint: disable=invalid-name """ -<<<<<<< HEAD Submits a task to generate certificates for given students enrolled in the course. Arguments: diff --git a/lms/templates/enroll_staff.html b/lms/templates/enroll_staff.html index 552e45ab8b..5730cc6edf 100644 --- a/lms/templates/enroll_staff.html +++ b/lms/templates/enroll_staff.html @@ -1,37 +1,40 @@ <%inherit file="main.html" /> <%namespace name='static' file='static_content.html'/> <%! -from django.utils.translation import ugettext as _ -from courseware.courses import get_course_info_section, get_course_date_summary - - + from django.utils.translation import ugettext as _ + from courseware.courses import get_course_about_section %> -<%block name="pagetitle">${_("{course_number} Course Info").format(course_number=course.display_number_with_default)}%block> - <%block name="headextra"> -<%static:css group='style-course-vendor'/> -<%static:css group='style-course'/> + + %block> -<%block name="bodyclass">view-in-course view-course-info ${course.css_class or ''}%block> -