Automattic / sensei

Sensei LMS - Online Courses, Quizzes, & Learning
https://senseilms.com
GNU General Public License v2.0
539 stars 198 forks source link

Changing course teachers causes modules to break #3813

Open jom opened 3 years ago

jom commented 3 years ago

For both legacy courses and course outline courses, modules break (lessons aren't assigned and strange things happen) when a teacher This happens for different reasons for both legacy courses and course outline courses, so we might want to break this work up.

Steps to Reproduce

  1. As a teacher, create a course with multiple modules and multiple lessons in each module.
  2. As an admin, change the teacher to a different teacher user.
  3. It should already be broken (on refresh), but you can also re-save the course again and see it try to assign the old modules to the course again.

What I Expected

Course structure not to change.

What Happened Instead

Lessons were removed from modules.

PHP / WordPress / Sensei LMS version

PHP 7.2 / WordPress 5.5 / Sensei LMS 3.5.2 (legacy) and Sensei LMS 3.6.0-beta.1 (block + legacy)

Browser / OS version

Chrome

renatho commented 3 years ago

The #3869 PR fixes this issue for legacy courses (handled by the modules meta box).


For course outline courses, I think we can fix it by skipping the Sensei_Teacher::update_course_modules_author with a validation like:

        // Skip if modules are handled by course outline block.
        $course = get_post( $course_id );
        if ( has_block( 'sensei-lms/course-outline', $course ) ) {
            return;
        }

But we would need to sync and re-save the blocks structure when changing the teacher too (see the subscribe in the assets/blocks/course-outline/store.js). It needs more exploration and tests, but I think the after #3862 is merged, the Sensei_Course_Structure class will be enough to handle the stuff handled by Sensei_Teacher::update_course_modules_author.

renatho commented 3 years ago

Adding a video for context of the pending issue:

https://user-images.githubusercontent.com/876340/130844024-fb3cc9e2-aedc-4f62-862d-2c96d7f751f1.mov

alexsanford commented 3 years ago

Noting here that this appears to only be a problem for "Draft" lessons. Published lessons do not get moved outside of their Modules.