fix(collections): check .permitted so permission filters take effect - #821
Open
bencap wants to merge 1 commit into
Open
fix(collections): check .permitted so permission filters take effect#821bencap wants to merge 1 commit into
bencap wants to merge 1 commit into
Conversation
`PermissionResponse` defined no `__bool__`, so the object was always truthy. `routers/collections.py` was the only module testing the response directly rather than reading `.permitted`, which left every permission check in it inert. - 18 association filters kept every member, disclosing the URNs of private score sets and experiments to any caller who could read the collection - 6 roster checks never took their narrowing branch, disclosing the full collection user roster, names and ORCID iDs included, to non-admins and to anonymous readers of public collections Raise `TypeError` from `PermissionResponse.__bool__` so a bare `if has_permission(...)` cannot be written again. Collapse the six duplicated roster blocks into `_narrow_user_roles_for_non_admins` and route `list_my_collections` through it as well. That endpoint held the only working version of the rule, gating on the caller's own collection role; sharing one implementation stops the two endpoints drifting apart again. The rule is `Action.ADD_ROLE`: whoever may add a user to a collection may see who is in it. Four existing tests asserted that editors and viewers see themselves in the roster, which was the bug's behaviour rather than the intended rule, and now expect the narrowed roster that `list_my_collections` has always returned. New tests cover both disclosures from the outside via response bodies, the roster rule parameterized over each contribution role, and the fact that the newly active filters must not delete the association rows they decline to show, since they assign to `delete-orphan` collections.
This was referenced Aug 7, 2026
Coverage Report for CI Build 31213077228Warning No base build found for commit Coverage: 89.269%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
bencap
marked this pull request as ready for review
August 7, 2026 21:50
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.
PermissionResponsedefined no__bool__, so the object was always truthy.routers/collections.pywas the only module testing the response directly rather than reading.permitted, which left every permission check in it inert.Raise
TypeErrorfromPermissionResponse.__bool__so a bareif has_permission(...)cannot be written again.Collapse the six duplicated roster blocks into
_narrow_user_roles_for_non_adminsand routelist_my_collectionsthrough it as well. That endpoint held the only working version of the rule, gating on the caller's own collection role; sharing one implementation stops the two endpoints drifting apart again. The rule isAction.ADD_ROLE: whoever may add a user to a collection may see who is in it.Four existing tests asserted that editors and viewers see themselves in the roster, which was the bug's behaviour rather than the intended rule, and now expect the narrowed roster that
list_my_collectionshas always returned.New tests cover both disclosures from the outside via response bodies, the roster rule parameterized over each contribution role, and the fact that the newly active filters must not delete the association rows they decline to show, since they assign to
delete-orphancollections.Closes #822