When Deleting a course from Open edX , what effect on role(staff role, instructor role) have and why is it nessary or not?

hi,
i tried to mimic management Command tutor dev run cms ./manage.py cms delete_course <course_key> for deleting course
, i go through this file Command File delete_course.py
and then i made changes in CourseContext Model for custom delete method here Like:

def delete(self, *args, **kwargs):
        # Delete related Sectors instances
        try:
            course_key = self.learning_context.context_key
            module_store = modulestore()
            with module_store.bulk_operations(course_key):
                module_store.delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command)
            contentstore().delete_all_course_assets(course_key)
            # 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())
        except:
            pass
        super().delete(*args, **kwargs)

but as you commented lines are for removing all instructor and staff users from the given course
as these are the functions used in delete_course.py from cms/djangoapps/contentstore/utils.py

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())


def delete_course(course_key, user_id, keep_instructors=False):
    """
    Delete course from module store and if specified remove user and
    groups permissions from course.
    """
    _delete_course_from_modulestore(course_key, user_id)

    if not keep_instructors:
        _remove_instructors(course_key)


def _delete_course_from_modulestore(course_key, user_id):
    """
    Delete course from MongoDB. Deleting course will fire a signal which will result into
    deletion of the courseware associated with a course_key.
    """
    module_store = modulestore()

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

, what i have written working , but when i uncomment those four line gives me circular import error.
now i want to ask , how to Removes all instructor and staff users from the given course or if i do not remove this what impact does it have ??

Hi @vivek! I hope you are well.

To answer your question regarding how to remove all instructor and staff users from a course, I can suggest two options.

1. Via Instructor Tab

A user with course staff access will find an Instructor tab located in the top menu of the course page.

Under Instructor tab, select Membership.

Then, scroll down to Course Team Management and you will be able to remove all course instructors/staff by clicking Revoke Access.

2. Via Django Admin

You can add or remove course team members through the Course Access Roles table in Django admin.

https://YOUR_LMS_URL/admin/student/courseaccessrole

You can look up all the course team members in this table using the course ID, and then remove their access as needed. Below is an example:

I hope you find this information helpful! :blush: