Scope GET sensei-messages with ?sender=all to message participants - #8032
Merged
Merged
Conversation
Non-admin results are limited to threads where the user is the _sender or _receiver; admins are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Sensei messages REST collection scoping so GET /wp/v2/sensei-messages?sender=all only returns threads the requester participates in (sender/receiver), except for site admins who can see everything—aligning endpoint behavior with documented message visibility.
Changes:
- Adjusted
sender=allquery scoping to limit non-admins to message threads where they are_senderor_receiver. - Updated/expanded PHPUnit coverage to ensure teachers cannot view other teachers’ threads and can view their own sent + received threads.
- Added a changelog entry for the behavior fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| includes/rest-api/class-sensei-rest-api-messages-controller.php | Changes sender=all collection filtering to scope non-admins to participant threads via _sender/_receiver meta. |
| tests/unit-tests/rest-api/test-class-sensei-rest-api-messages-controller.php | Removes outdated “teacher sees all” expectation; adds regression tests for teacher participant-only visibility and helper support for _receiver. |
| changelog/fix-messages-rest-sender-all-scoping | Adds a patch-level changelog entry documenting the REST visibility alignment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
albarin
marked this pull request as ready for review
June 29, 2026 12:46
donnapep
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
Aligns the
GET /wp/v2/sensei-messages?sender=allfilter with documented messages behaviour. Per the docs, messages are viewable only by "the teacher, the sender, and site administrators", so:manage_options) see all messages._senderor_receiver.The
?sender=currentpath is unchanged. Also tidied the existing unit test and added regression coverage for the scoping.Testing Instructions
teacherA,teacherB) and a student user.Contact teacherblock, and assignteacherBas its teacher.Start Course, and use the Contact Teacher button to messageteacherB.teacherArequestGET /wp-json/wp/v2/sensei-messages?sender=all→ response is[].teacherB, the same?sender=allrequest returns their own received message.?sender=allreturns all messages.Automated:
make test-php-filter FILTER="Sensei_REST_API_Messages_Controller_Tests"→ 8 tests pass.