コード例 #1
0
 def test_get_user_for_role(self):
     """
     test users_for_role
     """
     role = CourseStaffRole(self.course_key)
     role.add_users(self.student)
     self.assertGreater(len(role.users_with_role()), 0)
コード例 #2
0
def delete_course_and_groups(course_id, commit=False):
    """
    This deletes the courseware associated with a course_id as well as cleaning update_item
    the various user table stuff (groups, permissions, etc.)
    """
    module_store = modulestore('direct')
    content_store = contentstore()

    module_store.ignore_write_events_on_courses.add(course_id)

    if delete_course(module_store, content_store, course_id, commit):

        print 'removing User permissions from course....'
        # in the django layer, we need to remove all the user permissions groups associated with this course
        if commit:
            try:
                staff_role = CourseStaffRole(course_id)
                staff_role.remove_users(*staff_role.users_with_role())
                instructor_role = CourseInstructorRole(course_id)
                instructor_role.remove_users(
                    *instructor_role.users_with_role())
            except Exception as err:
                log.error(
                    "Error in deleting course groups for {0}: {1}".format(
                        course_id, err))
コード例 #3
0
 def test_get_user_for_role(self):
     """
     test users_for_role
     """
     role = CourseStaffRole(self.course_key)
     role.add_users(self.student)
     self.assertGreater(len(role.users_with_role()), 0)
コード例 #4
0
ファイル: utils.py プロジェクト: rayhooker/edx-platform
def delete_course_and_groups(course_id, commit=False):
    """
    This deletes the courseware associated with a course_id as well as cleaning update_item
    the various user table stuff (groups, permissions, etc.)
    """
    module_store = modulestore('direct')
    content_store = contentstore()

    org, course_num, _ = course_id.split("/")
    module_store.ignore_write_events_on_courses.append('{0}/{1}'.format(
        org, course_num))

    loc = CourseDescriptor.id_to_location(course_id)
    if delete_course(module_store, content_store, loc, commit):
        print 'removing forums permissions and roles...'
        unseed_permissions_roles(course_id)

        print 'removing User permissions from course....'
        # in the django layer, we need to remove all the user permissions groups associated with this course
        if commit:
            try:
                staff_role = CourseStaffRole(loc)
                staff_role.remove_users(*staff_role.users_with_role())
                instructor_role = CourseInstructorRole(loc)
                instructor_role.remove_users(
                    *instructor_role.users_with_role())
            except Exception as err:
                log.error(
                    "Error in deleting course groups for {0}: {1}".format(
                        loc, err))
コード例 #5
0
ファイル: utils.py プロジェクト: ybergner/edx-platform
def delete_course_and_groups(course_id, commit=False):
    """
    This deletes the courseware associated with a course_id as well as cleaning update_item
    the various user table stuff (groups, permissions, etc.)
    """
    module_store = modulestore('direct')
    content_store = contentstore()

    course_id_dict = Location.parse_course_id(course_id)
    module_store.ignore_write_events_on_courses.append(
        '{org}/{course}'.format(**course_id_dict))

    loc = CourseDescriptor.id_to_location(course_id)
    if delete_course(module_store, content_store, loc, commit):

        print 'removing User permissions from course....'
        # in the django layer, we need to remove all the user permissions groups associated with this course
        if commit:
            try:
                staff_role = CourseStaffRole(loc)
                staff_role.remove_users(*staff_role.users_with_role())
                instructor_role = CourseInstructorRole(loc)
                instructor_role.remove_users(
                    *instructor_role.users_with_role())
            except Exception as err:
                log.error(
                    "Error in deleting course groups for {0}: {1}".format(
                        loc, err))

            # remove location of this course from loc_mapper and cache
            loc_mapper().delete_course_mapping(loc)
コード例 #6
0
ファイル: utils.py プロジェクト: norsecode/edx-platform
def delete_course_and_groups(course_id, commit=False):
    """
    This deletes the courseware associated with a course_id as well as cleaning update_item
    the various user table stuff (groups, permissions, etc.)
    """
    module_store = modulestore('direct')
    content_store = contentstore()

    org, course_num, _ = course_id.split("/")
    module_store.ignore_write_events_on_courses.append('{0}/{1}'.format(
        org, course_num))

    loc = CourseDescriptor.id_to_location(course_id)
    if delete_course(module_store, content_store, loc, commit):
        print 'removing forums permissions and roles...'
        unseed_permissions_roles(course_id)

        print 'removing User permissions from course....'
        # in the django layer, we need to remove all the user permissions groups associated with this course
        if commit:
            try:
                staff_role = CourseStaffRole(loc)
                staff_role.remove_users(*staff_role.users_with_role())
                instructor_role = CourseInstructorRole(loc)
                instructor_role.remove_users(
                    *instructor_role.users_with_role())
            except Exception as err:
                log.error(
                    "Error in deleting course groups for {0}: {1}".format(
                        loc, err))
コード例 #7
0
ファイル: utils.py プロジェクト: DazzaGreenwood/edx-platform
def delete_course_and_groups(course_id, commit=False):
    """
    This deletes the courseware associated with a course_id as well as cleaning update_item
    the various user table stuff (groups, permissions, etc.)
    """
    module_store = modulestore('direct')
    content_store = contentstore()

    course_id_dict = Location.parse_course_id(course_id)
    module_store.ignore_write_events_on_courses.append('{org}/{course}'.format(**course_id_dict))

    loc = CourseDescriptor.id_to_location(course_id)
    if delete_course(module_store, content_store, loc, commit):

        print 'removing User permissions from course....'
        # in the django layer, we need to remove all the user permissions groups associated with this course
        if commit:
            try:
                staff_role = CourseStaffRole(loc)
                staff_role.remove_users(*staff_role.users_with_role())
                instructor_role = CourseInstructorRole(loc)
                instructor_role.remove_users(*instructor_role.users_with_role())
            except Exception as err:
                log.error("Error in deleting course groups for {0}: {1}".format(loc, err))

            # remove location of this course from loc_mapper and cache
            loc_mapper().delete_course_mapping(loc)
コード例 #8
0
def remove_all_instructors(course_key):
    """
    Removes all instructor and staff users from the given course.
    """
    staff_role = CourseStaffRole(course_key)
    staff_role.remove_users(*staff_role.users_with_role())
    instructor_role = CourseInstructorRole(course_key)
    instructor_role.remove_users(*instructor_role.users_with_role())
コード例 #9
0
ファイル: utils.py プロジェクト: musmanmalik/edx-platform
def remove_all_instructors(course_key):
    """
    Removes all instructor and staff users from the given course.
    """
    staff_role = CourseStaffRole(course_key)
    staff_role.remove_users(*staff_role.users_with_role())
    instructor_role = CourseInstructorRole(course_key)
    instructor_role.remove_users(*instructor_role.users_with_role())
コード例 #10
0
ファイル: utils.py プロジェクト: HoraceS/edx-platform
def remove_all_instructors(course_key):
    """
    Removes given user as instructor and staff to the given course,
    after verifying that the requesting_user has permission to do so.
    """
    staff_role = CourseStaffRole(course_key)
    staff_role.remove_users(*staff_role.users_with_role())
    instructor_role = CourseInstructorRole(course_key)
    instructor_role.remove_users(*instructor_role.users_with_role())
コード例 #11
0
    def test_update_and_assign_or_revoke_staff(self):
        """
        Successfully updates existing enrollments to assign or revoke the CourseStaff role.
        """
        course_staff_role = CourseStaffRole(self.course_id)
        course_staff_role.add_users(self.student_2)

        self.create_program_and_course_enrollments('learner-1',
                                                   user=self.student_1)
        self.create_program_and_course_enrollments('learner-2',
                                                   user=self.student_2)
        self.create_program_and_course_enrollments('learner-3', user=None)
        learner_4_enrollment = self.create_program_and_course_enrollments(
            'learner-4', user=None)
        learner_5_enrollment = self.create_program_and_course_enrollments(
            'learner-5', user=None)
        CourseAccessRoleAssignment.objects.create(
            enrollment=learner_4_enrollment,
            role=ProgramCourseEnrollmentRoles.COURSE_STAFF,
        )
        CourseAccessRoleAssignment.objects.create(
            enrollment=learner_5_enrollment,
            role=ProgramCourseEnrollmentRoles.COURSE_STAFF,
        )
        course_enrollment_requests = [
            self.course_enrollment_request('learner-1', CourseStatuses.ACTIVE,
                                           True),
            self.course_enrollment_request('learner-2', CourseStatuses.ACTIVE,
                                           False),
            self.course_enrollment_request('learner-3', CourseStatuses.ACTIVE,
                                           True),
            self.course_enrollment_request('learner-4', CourseStatuses.ACTIVE,
                                           False),
            self.course_enrollment_request('learner-5', CourseStatuses.ACTIVE,
                                           True),
        ]
        write_program_course_enrollments(
            self.program_uuid,
            self.course_id,
            course_enrollment_requests,
            True,
            True,
        )
        # Role is revoked for user's with a linked enrollment
        self.assertListEqual([self.student_1],
                             list(course_staff_role.users_with_role()))

        # CourseAccessRoleAssignment objects are created/revoked for enrollments with no linked user
        pending_role_assingments = CourseAccessRoleAssignment.objects.all()
        assert pending_role_assingments.count() == 2
        pending_role_assingments.get(
            enrollment__program_enrollment__external_user_key='learner-3',
            enrollment__course_key=self.course_id)
        pending_role_assingments.get(
            enrollment__program_enrollment__external_user_key='learner-5',
            enrollment__course_key=self.course_id)
コード例 #12
0
    def test_create_enrollments_and_assign_staff(self):
        """
        Successfully creates both waiting and linked program course enrollments with the course staff role.
        """
        course_staff_role = CourseStaffRole(self.course_id)
        course_staff_role.add_users(self.student_1)

        self.create_program_enrollment('learner-1', user=None)
        self.create_program_enrollment('learner-2', user=self.student_1)
        self.create_program_enrollment('learner-3', user=self.student_2)

        course_enrollment_requests = [
            self.course_enrollment_request('learner-1', CourseStatuses.ACTIVE,
                                           True),
            self.course_enrollment_request('learner-2', CourseStatuses.ACTIVE,
                                           True),
            self.course_enrollment_request('learner-3', CourseStatuses.ACTIVE,
                                           True),
        ]
        write_program_course_enrollments(
            self.program_uuid,
            self.course_id,
            course_enrollment_requests,
            True,
            True,
        )

        self.assert_program_course_enrollment('learner-1',
                                              CourseStatuses.ACTIVE, False)
        self.assert_program_course_enrollment('learner-2',
                                              CourseStatuses.ACTIVE, True)
        self.assert_program_course_enrollment('learner-3',
                                              CourseStatuses.ACTIVE, True)

        # Users linked to either enrollment are given the course staff role
        self.assertListEqual([self.student_1, self.student_2],
                             list(course_staff_role.users_with_role()))

        # CourseAccessRoleAssignment objects are created for enrollments with no linked user
        pending_role_assingments = CourseAccessRoleAssignment.objects.all()
        assert pending_role_assingments.count() == 1
        pending_role_assingments.get(
            enrollment__program_enrollment__external_user_key='learner-1',
            enrollment__course_key=self.course_id)
コード例 #13
0
def delete_course_and_groups(course_id, user_id):
    """
    This deletes the courseware associated with a course_id as well as cleaning update_item
    the various user table stuff (groups, permissions, etc.)
    """
    module_store = modulestore()

    with module_store.bulk_write_operations(course_id):
        module_store.delete_course(course_id, 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:
            staff_role = CourseStaffRole(course_id)
            staff_role.remove_users(*staff_role.users_with_role())
            instructor_role = CourseInstructorRole(course_id)
            instructor_role.remove_users(*instructor_role.users_with_role())
        except Exception as err:
            log.error("Error in deleting course groups for {0}: {1}".format(course_id, err))
コード例 #14
0
ファイル: utils.py プロジェクト: gtomar/edx-platform
def delete_course_and_groups(course_id, user_id):
    """
    This deletes the courseware associated with a course_id as well as cleaning update_item
    the various user table stuff (groups, permissions, etc.)
    """
    module_store = modulestore()

    with module_store.bulk_write_operations(course_id):
        module_store.delete_course(course_id, 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:
            staff_role = CourseStaffRole(course_id)
            staff_role.remove_users(*staff_role.users_with_role())
            instructor_role = CourseInstructorRole(course_id)
            instructor_role.remove_users(*instructor_role.users_with_role())
        except Exception as err:
            log.error("Error in deleting course groups for {0}: {1}".format(course_id, err))
コード例 #15
0
ファイル: utils.py プロジェクト: LoveCoding/Projects
def delete_course_and_groups(course_id, commit=False):
    """
    This deletes the courseware associated with a course_id as well as cleaning update_item
    the various user table stuff (groups, permissions, etc.)
    """
    module_store = modulestore('direct')
    content_store = contentstore()

    module_store.ignore_write_events_on_courses.add(course_id)

    if delete_course(module_store, content_store, course_id, commit):

        print 'removing User permissions from course....'
        # in the django layer, we need to remove all the user permissions groups associated with this course
        if commit:
            try:
                staff_role = CourseStaffRole(course_id)
                staff_role.remove_users(*staff_role.users_with_role())
                instructor_role = CourseInstructorRole(course_id)
                instructor_role.remove_users(*instructor_role.users_with_role())
            except Exception as err:
                log.error("Error in deleting course groups for {0}: {1}".format(course_id, err))