예제 #1
0
 def test_get_integrity_signature(self):
     """
     Test to get an integrity signature
     """
     create_integrity_signature(self.user.username, self.course_id)
     signature = get_integrity_signature(self.user.username, self.course_id)
     self._assert_integrity_signature(signature)
예제 #2
0
    def user_needs_integrity_signature(self):
        """
        Boolean describing whether the user needs to sign the integrity agreement for a course.
        """
        if not settings.FEATURES.get('ENABLE_INTEGRITY_SIGNATURE'):
            return False

        integrity_signature_required = (
            self.enrollment_object
            # Master's enrollments are excluded here as honor code is handled separately
            and self.enrollment_object.mode
            in CourseMode.CREDIT_MODES + CourseMode.CREDIT_ELIGIBLE_MODES)

        if not integrity_signature_required:
            # Check masquerading as a non-audit enrollment
            integrity_signature_required = is_masquerading_as_non_audit_enrollment(
                self.effective_user, self.course_key, self.course_masquerade)

        if integrity_signature_required:
            signature = get_integrity_signature(self.effective_user.username,
                                                str(self.course_key))
            if not signature:
                return True

        return False
예제 #3
0
 def user_needs_integrity_signature(self):
     """
     Boolean describing whether the user needs to sign the integrity agreement for a course.
     """
     if (is_integrity_signature_enabled(self.course_key)
             and not self.is_staff and self.enrollment_object
             and self.enrollment_object.mode
             in CourseMode.CERTIFICATE_RELEVANT_MODES):
         signature = get_integrity_signature(self.effective_user.username,
                                             str(self.course_key))
         if not signature:
             return True
     return False
예제 #4
0
 def test_create_duplicate_integrity_signature(self):
     """
     Test that duplicate integrity signatures cannot be created
     """
     with LogCapture(LOGGER_NAME, level=logging.WARNING) as logger:
         create_integrity_signature(self.user.username, self.course_id)
         create_integrity_signature(self.user.username, self.course_id)
         signature = get_integrity_signature(self.user.username,
                                             self.course_id)
         self._assert_integrity_signature(signature)
         logger.check((LOGGER_NAME, 'WARNING', (
             'Integrity signature already exists for user_id={user_id} and '
             'course_id={course_id}'.format(user_id=self.user.id,
                                            course_id=str(
                                                self.course_id)))))
예제 #5
0
    def get(self, request, course_id):
        """
        In order to check whether the user has signed the integrity agreement for a given course.

        Should return the following:
            username (str)
            course_id (str)
            created_at (str)

        If a username is not given, it should default to the requesting user (or masqueraded user).
        Only staff should be able to access this endpoint for other users.
        """
        # check that waffle flag is enabled
        if not is_integrity_signature_enabled(
                CourseKey.from_string(course_id)):
            return Response(status=status.HTTP_404_NOT_FOUND, )

        # check that user can make request
        user = request.user.username
        requested_user = request.GET.get('username')
        is_staff = is_user_course_or_global_staff(request.user, course_id)

        if not is_staff and requested_user and (user != requested_user):
            return Response(
                status=status.HTTP_403_FORBIDDEN,
                data={
                    "message":
                    "User does not have permission to view integrity agreement."
                })

        username = requested_user if requested_user else user
        signature = get_integrity_signature(username, course_id)

        if signature is None:
            return Response(status=status.HTTP_404_NOT_FOUND, )

        serializer = IntegritySignatureSerializer(signature)
        return Response(serializer.data)
예제 #6
0
 def test_get_nonexistent_integrity_signature(self):
     """
     Test that None is returned if an integrity signature does not exist
     """
     signature = get_integrity_signature(self.user.username, self.course_id)
     self.assertIsNone(signature)