Skip to content

Fix module order reset when Editor saves a lesson#7910

Merged
donnapep merged 4 commits into
trunkfrom
fix/broken-module-order-for-editors
Mar 6, 2026
Merged

Fix module order reset when Editor saves a lesson#7910
donnapep merged 4 commits into
trunkfrom
fix/broken-module-order-for-editors

Conversation

@donnapep

@donnapep donnapep commented Mar 6, 2026

Copy link
Copy Markdown
Member

Summary

  • When a non-admin user (e.g. Editor) saves a lesson in a course with modules owned by another user (e.g. Admin), the module ownership filters (filter_module_terms, filter_course_selected_terms) strip modules the Editor doesn't own during the read/save cycle in save_lesson_order().
  • This causes all non-owned modules to be disassociated from the course and the module order to be reset.
  • Fix: temporarily remove the ownership filters before reading and saving the course structure, then restore them after.

Fixes #7889

Test plan

  • Run npm run test-php:wp-env -- --filter testAddLessonToCourseOrder_AsEditor_PreservesModuleOrder — should pass
  • Run full test suite npm run test-php:wp-env — only pre-existing Sensei_Class_Feature_Flags_Test failures expected
  • Manual: Log in as Admin, create a course with modules and lessons. Log in as Editor, edit a lesson in that course and save. Verify modules remain associated and order is preserved.

🤖 Generated with Claude Code

donnapep and others added 2 commits March 6, 2026 10:44
Remove module ownership filters (filter_module_terms, filter_course_selected_terms)
before reading and saving the course structure in save_lesson_order(). Without this,
non-admin users only retrieve their own modules, causing all other modules to be
disassociated from the course on save.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 6, 2026 15:58
@donnapep donnapep added this to the 4.26.0 milestone Mar 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a regression where saving a lesson as a non-admin (e.g., Editor) could unintentionally drop modules they don’t own from a course and reset the course’s module order, due to module ownership filters affecting the read/save cycle.

Changes:

  • Temporarily removes module ownership term filters during Sensei_Admin::save_lesson_order() so the full course structure is read/saved.
  • Adds a unit test to ensure module order is preserved when an Editor saves a lesson.
  • Adds a changelog entry documenting the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/unit-tests/test-class-lesson.php Adds coverage to ensure Editor lesson saves do not reset _module_order or disassociate modules.
includes/class-sensei-admin.php Removes/re-adds module ownership filters around course structure read/save to prevent module loss/order reset.
changelog/fix-broken-module-order-for-editors Documents the bugfix in the changelog.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread includes/class-sensei-admin.php
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread includes/class-sensei-admin.php
Comment thread tests/unit-tests/test-class-lesson.php
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI commented Mar 6, 2026

Copy link
Copy Markdown

@donnapep I've opened a new pull request, #7911, to work on those changes. Once the pull request is ready, I'll request review from you.

@donnapep donnapep merged commit 4b0a2e9 into trunk Mar 6, 2026
23 checks passed
@donnapep donnapep deleted the fix/broken-module-order-for-editors branch March 6, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Module Order reset if lesson updated by Editor

3 participants