Exemplo n.º 1
0
    def test_user_not_yet_answered_required_survey(self):
        """
        Assert that a new course which has a required survey but user has not answered it yet
        """
        self.assertTrue(
            is_survey_required_and_unanswered(self.student, self.course))

        temp_course = CourseFactory.create(course_survey_required=False)
        self.assertFalse(
            is_survey_required_and_unanswered(self.student, temp_course))

        temp_course = CourseFactory.create(course_survey_required=True,
                                           course_survey_name="NonExisting")
        self.assertFalse(
            is_survey_required_and_unanswered(self.student, temp_course))
Exemplo n.º 2
0
    def test_user_not_yet_answered_required_survey(self):
        """
        Assert that a new course which has a required survey but user has not answered it yet
        """
        self.assertTrue(is_survey_required_and_unanswered(self.student, self.course))

        temp_course = CourseFactory.create(
            course_survey_required=False
        )
        self.assertFalse(is_survey_required_and_unanswered(self.student, temp_course))

        temp_course = CourseFactory.create(
            course_survey_required=True,
            course_survey_name="NonExisting"
        )
        self.assertFalse(is_survey_required_and_unanswered(self.student, temp_course))
Exemplo n.º 3
0
 def test_user_has_answered_required_survey(self):
     """
     Assert that a new course which has a required survey and user has answers for it
     """
     self.survey.save_user_answers(self.student, self.student_answers, None)
     self.assertFalse(
         is_survey_required_and_unanswered(self.student, self.course))
Exemplo n.º 4
0
    def check_course_access(self,
                            course,
                            user,
                            action,
                            check_if_enrolled=False,
                            check_survey_complete=True):
        """
        Check that the user has the access to perform the specified action
        on the course (CourseDescriptor|CourseOverview).

        check_if_enrolled: If true, additionally verifies that the user is enrolled.
        check_survey_complete: If true, additionally verifies that the user has completed the survey.
        """

        # Allow staff full access to the course even if not enrolled
        if has_access(user, 'staff', course.id):
            return course, courseware_privileges.full_access

        access_response = has_access(user, action, course, course.id)
        if not access_response:
            return None, courseware_privileges.access_deny
        if check_if_enrolled:
            # If the user is not enrolled, redirect them to the about page
            if not CourseEnrollment.is_enrolled(user, course.id):
                return None, courseware_privileges.need_enroll

        # Redirect if the user must answer a survey before entering the course.
        if check_survey_complete and action == 'load':
            if is_survey_required_and_unanswered(user, course):
                return None, courseware_privileges.need_survey
            elif user.is_anonymous:
                return None, courseware_privileges.need_login
            else:
                return course, courseware_privileges.full_access
Exemplo n.º 5
0
def check_course_access(course,
                        user,
                        action,
                        check_if_enrolled=False,
                        check_survey_complete=True):
    """
    Check that the user has the access to perform the specified action
    on the course (CourseDescriptor|CourseOverview).

    check_if_enrolled: If true, additionally verifies that the user is enrolled.
    check_survey_complete: If true, additionally verifies that the user has completed the survey.
    """
    # Allow staff full access to the course even if not enrolled
    if has_access(user, 'staff', course.id):
        return

    access_response = has_access(user, action, course, course.id)
    if not access_response:
        # Redirect if StartDateError
        if isinstance(access_response, StartDateError):
            start_date = strftime_localized(course.start, 'SHORT_DATE')
            params = QueryDict(mutable=True)
            params['notlive'] = start_date
            raise CourseAccessRedirect(
                '{dashboard_url}?{params}'.format(
                    dashboard_url=reverse('dashboard'),
                    params=params.urlencode()), access_response)

        # Redirect if AuditExpiredError
        if isinstance(access_response, AuditExpiredError):
            params = QueryDict(mutable=True)
            params[
                'access_response_error'] = access_response.additional_context_user_message
            raise CourseAccessRedirect(
                '{dashboard_url}?{params}'.format(
                    dashboard_url=reverse('dashboard'),
                    params=params.urlencode()), access_response)

        # Redirect if the user must answer a survey before entering the course.
        if isinstance(access_response, MilestoneAccessError):
            raise CourseAccessRedirect(
                '{dashboard_url}'.format(dashboard_url=reverse('dashboard'), ),
                access_response)

        # Deliberately return a non-specific error message to avoid
        # leaking info about access control settings
        raise CoursewareAccessException(access_response)

    if check_if_enrolled:
        # If the user is not enrolled, redirect them to the about page
        if not CourseEnrollment.is_enrolled(user, course.id):
            raise CourseAccessRedirect(
                reverse('about_course', args=[unicode(course.id)]))

    # Redirect if the user must answer a survey before entering the course.
    if check_survey_complete and action == 'load':
        if is_survey_required_and_unanswered(user, course):
            raise CourseAccessRedirect(
                reverse('course_survey', args=[unicode(course.id)]))
Exemplo n.º 6
0
def check_course_access(course, user, action, check_if_enrolled=False, check_survey_complete=True):
    """
    Check that the user has the access to perform the specified action
    on the course (CourseDescriptor|CourseOverview).

    check_if_enrolled: If true, additionally verifies that the user is enrolled.
    check_survey_complete: If true, additionally verifies that the user has completed the survey.
    """
    # Allow staff full access to the course even if not enrolled
    if has_access(user, 'staff', course.id):
        return

    request = get_current_request()
    check_content_start_date_for_masquerade_user(course.id, user, request, course.start)

    access_response = has_access(user, action, course, course.id)
    if not access_response:
        # Redirect if StartDateError
        if isinstance(access_response, StartDateError):
            start_date = strftime_localized(course.start, 'SHORT_DATE')
            params = QueryDict(mutable=True)
            params['notlive'] = start_date
            raise CourseAccessRedirect('{dashboard_url}?{params}'.format(
                dashboard_url=reverse('dashboard'),
                params=params.urlencode()
            ), access_response)

        # Redirect if AuditExpiredError
        if isinstance(access_response, AuditExpiredError):
            params = QueryDict(mutable=True)
            params['access_response_error'] = access_response.additional_context_user_message
            raise CourseAccessRedirect('{dashboard_url}?{params}'.format(
                dashboard_url=reverse('dashboard'),
                params=params.urlencode()
            ), access_response)

        # Redirect if the user must answer a survey before entering the course.
        if isinstance(access_response, MilestoneAccessError):
            raise CourseAccessRedirect('{dashboard_url}'.format(
                dashboard_url=reverse('dashboard'),
            ), access_response)

        # Deliberately return a non-specific error message to avoid
        # leaking info about access control settings
        raise CoursewareAccessException(access_response)

    if check_if_enrolled:
        # If the user is not enrolled, redirect them to the about page
        if not CourseEnrollment.is_enrolled(user, course.id):
            raise CourseAccessRedirect(reverse('about_course', args=[unicode(course.id)]))

    # Redirect if the user must answer a survey before entering the course.
    if check_survey_complete and action == 'load':
        if is_survey_required_and_unanswered(user, course):
            raise CourseAccessRedirect(reverse('course_survey', args=[unicode(course.id)]))
Exemplo n.º 7
0
 def test_staff_must_answer_survey(self):
     """
     Assert that someone with staff level permissions does not have to answer the survey
     """
     self.assertFalse(
         is_survey_required_and_unanswered(self.staff, self.course))
Exemplo n.º 8
0
 def test_staff_must_answer_survey(self):
     """
     Assert that someone with staff level permissions does not have to answer the survey
     """
     self.assertFalse(is_survey_required_and_unanswered(self.staff, self.course))
Exemplo n.º 9
0
 def test_user_has_answered_required_survey(self):
     """
     Assert that a new course which has a required survey and user has answers for it
     """
     self.survey.save_user_answers(self.student, self.student_answers, None)
     self.assertFalse(is_survey_required_and_unanswered(self.student, self.course))