def handle(self, *args, **options):
        """
        This handler operation does the actual work!
        """
        if len(args) != 1 and len(args) != 2:
            raise CommandError("delete_course requires one or more arguments: <course_id> |commit|")

        try:
            course_key = CourseKey.from_string(args[0])
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(args[0])

        commit = False
        if len(args) == 2:
            commit = args[1] == 'commit'

        if commit:
            print('Actually going to delete the course references from LMS database....')
            print('Note: There is a corresponding CMS command you must run BEFORE this command.')

            if hasattr(settings, 'TEST_ROOT'):
                course_deleted.send(sender=None, course_key=course_key)
            else:

                if query_yes_no("Deleting ALL records with references to course {0}. Confirm?".format(course_key), default="no"):
                    if query_yes_no("Are you sure. This action cannot be undone!", default="no"):

                        # Broadcast the deletion event to CMS listeners
                        print 'Notifying LMS system components...'
                        course_deleted.send(sender=None, course_key=course_key)

                        print 'LMS Course Cleanup Complete!'
    def test_receiver_on_course_deleted(self):
        self._create_course(start=datetime(2010, 1, 1, tzinfo=UTC()),
                            end=datetime(2020, 1, 1, tzinfo=UTC()))
        module = self.get_module_for_user(self.user, self.course, self.problem)
        grade_dict = {'value': 0.75, 'max_value': 1, 'user_id': self.user.id}
        module.system.publish(module, 'grade', grade_dict)

        gradebook = StudentGradebook.objects.get(user=self.user,
                                                 course_id=self.course.id)
        self.assertEqual(gradebook.grade, 0.01)
        self.assertEqual(gradebook.proforma_grade, 0.75)
        self.assertIn(json.dumps(self.problem_progress_summary),
                      gradebook.progress_summary)
        self.assertIn(json.dumps(self.problem_grade_summary),
                      gradebook.grade_summary)
        self.assertEquals(json.loads(gradebook.grading_policy),
                          self.grading_policy)

        gradebook = StudentGradebook.objects.all()
        self.assertEqual(len(gradebook), 1)

        history = StudentGradebookHistory.objects.all()
        self.assertEqual(len(history), 1)

        course_deleted.send(sender=None, course_key=self.course.id)

        with self.assertRaises(StudentGradebook.DoesNotExist):
            gradebook = StudentGradebook.objects.get(user=self.user,
                                                     course_id=self.course.id)

        gradebook = StudentGradebook.objects.all()
        self.assertEqual(len(gradebook), 0)

        history = StudentGradebookHistory.objects.all()
        self.assertEqual(len(history), 0)
Beispiel #3
0
    def test_receiver_on_course_deleted(self):
        """
        Test the workflow
        """
        # Set up the data to be removed
        group = Group.objects.create(name='TestGroup')
        group_profile = GroupProfile.objects.create(group=group)

        CourseGroupRelationship.objects.create(course_id=unicode(
            self.course.id),
                                               group=group)
        CourseContentGroupRelationship.objects.create(
            course_id=unicode(self.course.id),
            content_id=unicode(self.chapter.location),
            group_profile=group_profile)

        self.assertEqual(
            CourseGroupRelationship.objects.filter(
                course_id=unicode(self.course.id)).count(), 1)
        self.assertEqual(
            CourseContentGroupRelationship.objects.filter(
                course_id=self.course.id,
                content_id=unicode(self.chapter.location)).count(), 1)  # pylint: disable=C0301

        # Emit the signal
        course_deleted.send(sender=None, course_key=self.course.id)

        # Validate that the course references were removed
        self.assertEqual(
            CourseGroupRelationship.objects.filter(
                course_id=unicode(self.course.id)).count(), 0)
        self.assertEqual(
            CourseContentGroupRelationship.objects.filter(
                course_id=self.course.id,
                content_id=unicode(self.chapter.location)).count(), 0)  # pylint: disable=C0301
Beispiel #4
0
def delete_course_and_groups(course_key, user_id):
    """
    This deletes the courseware associated with a course_key as well as cleaning update_item
    the various user table stuff (groups, permissions, etc.)
    """
    module_store = modulestore()

    with module_store.bulk_operations(course_key):
        module_store.delete_course(course_key, user_id)

        print 'removing User permissions from course....'
        # in the django layer, we need to remove all the user permissions groups associated with this course
        try:
            remove_all_instructors(course_key)
            print 'User permissions removed, continuing...'
        except Exception as err:
            log.error("Error in deleting course groups for {0}: {1}".format(course_key, err))

        # Broadcast the deletion event to CMS listeners
        print 'Notifying CMS system components...'
        course_deleted.send(sender=None, course_key=course_key)

        print 'CMS Course Cleanup Complete!'
        print 'You must now execute this same command in LMS to clean up orphaned records'
        print 'COMMAND: ./manage.py lms delete_course_references <course_id> commit'
    def test_receiver_on_course_deleted(self):
        """
        Test the workflow
        """
        # Set up the data to be removed
        CourseAccessRole.objects.create(course_id=self.course.id, user=self.user, role='instructor')

        # Emit the signal
        course_deleted.send(sender=None, course_key=self.course.id)

        # Validate that the course references were removed
        self.assertEqual(CourseAccessRole.objects.filter(course_id=self.course.id).count(), 0)
Beispiel #6
0
    def test_receiver_on_course_deleted(self):
        course = self.setup_course_with_grading()
        self._assert_valid_gradebook_on_course(course)

        course_deleted.send(sender=None, course_key=course.id)
        with self.assertRaises(StudentGradebook.DoesNotExist):
            gradebook = StudentGradebook.objects.get(user=self.user,
                                                     course_id=course.id)

        gradebook = StudentGradebook.objects.all()
        self.assertEqual(len(gradebook), 0)

        history = StudentGradebookHistory.objects.all()
        self.assertEqual(len(history), 0)
Beispiel #7
0
    def test_receiver_on_course_deleted(self):
        """
        Test the workflow
        """
        # Set up the data to be removed
        CourseAccessRole.objects.create(course_id=self.course.id,
                                        user=self.user,
                                        role='instructor')

        # Emit the signal
        course_deleted.send(sender=None, course_key=self.course.id)

        # Validate that the course references were removed
        self.assertEqual(
            CourseAccessRole.objects.filter(course_id=self.course.id).count(),
            0)
Beispiel #8
0
    def test_receiver_on_course_deleted(self):
        self._create_course(start=datetime(2010, 1, 1, tzinfo=UTC()), end=datetime(2020, 1, 1, tzinfo=UTC()))
        module = self.get_module_for_user(self.user, self.course, self.problem)
        module.system.publish(module, 'progress', {})

        progress = StudentProgress.objects.all()
        self.assertEqual(len(progress), 1)

        history = StudentProgressHistory.objects.all()
        self.assertEqual(len(history), 1)

        course_deleted.send(sender=None, course_key=self.course.id)

        progress = StudentProgress.objects.all()
        self.assertEqual(len(progress), 0)

        history = StudentProgressHistory.objects.all()
        self.assertEqual(len(history), 0)
Beispiel #9
0
    def test_receiver_on_course_deleted(self):
        self._create_course(start=datetime(2010, 1, 1, tzinfo=UTC()), end=datetime(2020, 1, 1, tzinfo=UTC()))
        module = self.get_module_for_user(self.user, self.course, self.problem)
        module.system.publish(module, 'progress', {})

        progress = StudentProgress.objects.all()
        self.assertEqual(len(progress), 1)

        history = StudentProgressHistory.objects.all()
        self.assertEqual(len(history), 1)

        course_deleted.send(sender=None, course_key=self.course.id)

        progress = StudentProgress.objects.all()
        self.assertEqual(len(progress), 0)

        history = StudentProgressHistory.objects.all()
        self.assertEqual(len(history), 0)
    def handle(self, *args, **options):
        """
        This handler operation does the actual work!
        """
        if len(args) != 1 and len(args) != 2:
            raise CommandError(
                "delete_course requires one or more arguments: <course_id> |commit|"
            )

        try:
            course_key = CourseKey.from_string(args[0])
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(
                args[0])

        commit = False
        if len(args) == 2:
            commit = args[1] == 'commit'

        if commit:
            print(
                'Actually going to delete the course references from LMS database....'
            )
            print(
                'Note: There is a corresponding CMS command you must run BEFORE this command.'
            )

            if hasattr(settings, 'TEST_ROOT'):
                course_deleted.send(sender=None, course_key=course_key)
            else:

                if query_yes_no(
                        "Deleting ALL records with references to course {0}. Confirm?"
                        .format(course_key),
                        default="no"):
                    if query_yes_no(
                            "Are you sure. This action cannot be undone!",
                            default="no"):

                        # Broadcast the deletion event to CMS listeners
                        print 'Notifying LMS system components...'
                        course_deleted.send(sender=None, course_key=course_key)

                        print 'LMS Course Cleanup Complete!'
Beispiel #11
0
    def test_receiver_on_course_deleted(self):
        project = models.Project.objects.create(
            course_id=unicode(self.course.id),
            content_id=unicode(self.chapter.location)
        )
        workgroup = models.Workgroup.objects.create(
            project=project,
            name='TEST WORKGROUP'
        )
        workgroup_user = models.WorkgroupUser.objects.create(
            workgroup=workgroup,
            user=self.user
        )
        workgroup_review = models.WorkgroupReview.objects.create(
            workgroup=workgroup,
            reviewer=self.user,
            question='test',
            answer='test',
            content_id=unicode(self.chapter.location),
        )
        workgroup_peer_review = models.WorkgroupPeerReview.objects.create(
            workgroup=workgroup,
            user=self.user,
            reviewer=self.user,
            question='test',
            answer='test',
            content_id=unicode(self.chapter.location),
        )
        workgroup_submission = models.WorkgroupSubmission.objects.create(
            workgroup=workgroup,
            user=self.user,
            document_id='test',
            document_url='test',
            document_mime_type='test',
        )
        workgroup_submission_review = models.WorkgroupSubmissionReview.objects.create(
            submission=workgroup_submission,
            reviewer=self.user,
            question='test',
            answer='test',
            content_id=unicode(self.chapter.location),
        )

        self.assertEqual(models.Project.objects.filter(id=project.id).count(), 1)
        self.assertEqual(models.Workgroup.objects.filter(id=workgroup.id).count(), 1)
        self.assertEqual(models.WorkgroupUser.objects.filter(id=workgroup_user.id).count(), 1)
        self.assertEqual(models.WorkgroupReview.objects.filter(id=workgroup_review.id).count(), 1)
        self.assertEqual(models.WorkgroupSubmission.objects.filter(id=workgroup_submission.id).count(), 1)
        self.assertEqual(models.WorkgroupSubmissionReview.objects.filter(id=workgroup_submission_review.id).count(), 1)
        self.assertEqual(models.WorkgroupPeerReview.objects.filter(id=workgroup_peer_review.id).count(), 1)

        # Run the data migration
        course_deleted.send(sender=None, course_key=self.course.id)

        # Validate that the course references were removed
        self.assertEqual(models.Project.objects.filter(id=project.id).count(), 0)
        self.assertEqual(models.Workgroup.objects.filter(id=workgroup.id).count(), 0)
        self.assertEqual(models.WorkgroupUser.objects.filter(id=workgroup_user.id).count(), 0)
        self.assertEqual(models.WorkgroupReview.objects.filter(id=workgroup_review.id).count(), 0)
        self.assertEqual(models.WorkgroupSubmission.objects.filter(id=workgroup_submission.id).count(), 0)
        self.assertEqual(models.WorkgroupSubmissionReview.objects.filter(id=workgroup_submission_review.id).count(), 0)
        self.assertEqual(models.WorkgroupPeerReview.objects.filter(id=workgroup_peer_review.id).count(), 0)