Add test coverage for document permissions and Research AI editor access#3198
Draft
cursor[bot] wants to merge 2 commits intomainfrom
Draft
Add test coverage for document permissions and Research AI editor access#3198cursor[bot] wants to merge 2 commits intomainfrom
cursor[bot] wants to merge 2 commits intomainfrom
Conversation
Cover the bug fix where posts without a linked note would crash with AttributeError when a non-author/non-moderator tried to update. Tests verify each permission path: author, moderator, org member, non-member, and the critical note_id=None guard clause. Co-authored-by: Kobe Attias <kobeattias@gmail.com>
Verify hub editors (non-moderators) can access Research AI views after the IsModerator -> UserIsEditor | IsModerator permission change. Covers: - Permission composition unit tests (OR semantics) - Expert search create/list for editors - Email generate/list/retrieve/draft for editors - Template CRUD for editors Co-authored-by: Kobe Attias <kobeattias@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3198 +/- ##
==========================================
+ Coverage 78.51% 78.52% +0.01%
==========================================
Files 612 612
Lines 34280 34280
==========================================
+ Hits 26916 26920 +4
+ Misses 7364 7360 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.



Risky behavior now covered
HasDocumentEditingPermission
note_id is Noneguard (PR Implement user verification requirement for creating and updating posts #3188 bug fix): When a post has no linked note, a non-author/non-moderator editing attempt would previously crash withAttributeErroronpost.note.organization. The fix returnsFalseinstead. Now has 11 unit tests covering each permission path.Research AI editor access (PR [ExpertFinder] - Update permissions #3173): All Research AI views changed from
IsModeratortoUserIsEditor | IsModerator. Existing tests only verified moderator access—there were zero tests confirming editors could actually use the endpoints. Now has 12 new tests across permissions, expert-finder, email, and template views.Test files added/updated
src/researchhub_document/tests/test_permissions.py— 11 tests forHasDocumentEditingPermissionsrc/research_ai/tests/test_permissions.py— 5 new tests forUserIsEditor | IsModeratorOR-compositionsrc/research_ai/tests/test_expert_finder_views.py— 2 editor access testssrc/research_ai/tests/test_email_views.py— 4 editor access testssrc/research_ai/tests/test_template_views.py— 5 editor access testsWhy these tests materially reduce regression risk
ifguard that could easily be reverted or broken during refactoring. Without direct unit tests, the regression would only surface as a 500 error for real users.