Repository navigation
OpenConceptLab/ocl_online#747 OpenConceptLab/ocl_online#546 | Version lists, counts and latest are of the versions the requester can view - #1119
Conversation
…ptLab/ocl_online#735 | Version lists, counts and latest are of the versions the requester can view A source's or collection's versions list holds the versions the requester can view, and so do the version count in its summary, latest_released_version and previous_version_url. latest in a URL names the newest released version they can view, for the version and for everything read under it. Lists and searches of sources and collections show a version only with its HEAD, whichever versions they ask for. The rule's HEAD check is one condition per kind of owner, which the database can join on, so it costs a list of versions next to nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk
…rt of the latest version is written only where it was before A read of latest/export/ by someone who can't view the latest version gets the newest one they can view. A write is to the latest version, or refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk
… under latest needs a release, and versions embedded elsewhere follow the reader A write under a collection's latest is refused when it has no release. A collection's $cascade starts from a concept of the version its URL names, HEAD's without one. A pinned repository's version count, and the previous version of one an expansion or a reference lists, are the requester's. An export of a private version names the one before it, whoever can view the export being able to view both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk
… concept of the version it names, and an export names the previous public version Without a version it starts from HEAD's, the one it walks: from any expansion, or the one the URL names. `source` picks among concepts that share a code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk
|
Reviews: two full Codex passes and checks of the commits after them, a simplification review, and an access-control pass that compared signed-out, member and staff answers with Lint and the full suite pass on 855949b (4,308 tests, and 818 with search). After the deploy, one clean-up of export files is on OpenConceptLab/ocl_online#747. |
…#1119 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk
snyaggarwal
left a comment
There was a problem hiding this comment.
Approve. Mergeable as is. The two notes below are about performance and can be follow-ups.
Merge order: #1119, then #1120, then #1128, as in the hand-back. All three merge cleanly onto today's master (3c2e9c1) and onto each other in either order. #1119 and #1120 carry the same get_viewable_versions_criteria hunk, and #1119 and #1128 the same HEAD num_found line, so whichever goes second has nothing to resolve. CI ran on 7ab829e. Since then master has gained #1123, #1127 and #1124, which touch core/concepts/models.py and core/mappings/models.py in other hunks only.
What I checked, beyond the Codex passes and the adversarial pass on OpenConceptLab/ocl_online#747, which I don't repeat here:
- Leaks, by requester. I checked the versions list (GET and HEAD),
latest(reads, summary, export and the reads under it), the summary'sversions, andprevious_version_url, including where it's embedded in expansions, references and pins. I also checked the?version=andallVersionslists.tests_viewable_versions.pycovers signed out, outsider, member, admin, owner and staff. I found no path left that names a hidden version. The create serializers still returnversions = num_versions, but only to the creator, and no detail serializer has that field. - DB and ES agree. The DB lists go through
get_viewable.allVersionssearches exclude by id the versions that only their HEAD hides. #1120 applies the same rule to the facet. - Cache. The only cached lists here are a version's concepts and mappings. Their key comes from the resolved version's URI (
get_concepts_cache_keys), not from the request URL. So whenlatestresolves differently for different users, each version gets its own key. Nothing is shared across users that shouldn't be. - Queries.
load_previous_version_urismakes one query per page, where there used to be one per row. Summary counts andlatest_released_versionstay at one query per row, as before.
Non-blocking, inline
- HEAD-only lists don't need the HEAD check. Skipping it there would likely win back most of the signed-out
/collections/count going from 11 to 86 ms. - The
allVersionsexclusion negates the criteria, which brings back the OR of twoEXISTSthis PR removed elsewhere. Please measure it on production.
|
|
||
| def filter_queryset_by_public_access(self, queryset): | ||
| user = self.request.user | ||
| if issubclass(queryset.model, ConceptContainerModel): # a version shows only with its HEAD |
There was a problem hiding this comment.
Non-blocking, performance. The default /sources/, /collections/ and /repos/ DB lists are filtered to version=HEAD. For a HEAD row, "its HEAD is private" is the row's own public_access, which criteria already checks, and own is already left out of private_heads. So in those lists the two NOT EXISTS checks can never remove a row. That's likely most of the signed-out /collections/ count going from 11 to 86 ms. One fix is to skip the HEAD check when the list is HEAD-only, meaning no ?version= and no allVersions. A heads_only argument to get_viewable_versions_criteria would do it.
| viewable = model.get_viewable_versions_criteria(self.request.user) | ||
| if viewable is None: | ||
| return results | ||
| ids = list(model.objects.filter( |
There was a problem hiding this comment.
Non-blocking, performance. ~viewable negates the criteria, which turns the two NOT EXISTS back into EXISTS(private org HEAD) OR EXISTS(private user HEAD). That's the OR the PR body says Postgres can't join on. It runs on every allVersions search, over every active public version. It also runs for both models on /sources/ and /collections/, where the repo_type term means only one can match. Could you time it on production? If it's slow, two changes would help: query only the model the search covers, and build the ids from two positive semi-joins, public active versions with Exists(private_heads.filter(mnemonic=..., organization_id=...)) and then the same for user_id, reusing the private_heads queryset from get_viewable_versions_criteria.
What the API answers now
For a source or a collection alike:
…/versions/, GET and HEAD, with any parameternum_foundcounts thoselatestin a URL:…/latest/, its summary and export, and everything read under itversionsin a repository's summary,latest_released_version,previous_version_url/sources/,/collections/and/repos/, an owner's or a member's lists, with or without?version=allVersions=trueStaff, a repository's owner and its organization's members see what they saw. Writes under
latestgo to the same version as before, or are refused: under a collection'slatestwith no release, 404.Where a repository's versions are embedded (pins, an expansion's value set versions, a reference's), the count and the previous version are the requester's too.
How
ConceptContainerModel.get_viewable()(get_viewable_versions_criteria) already says which versions a user can view. These reads now use it.find_latest_release_for(filters, user)is whatlatestmeans to a user.OR, which Postgres couldn't join on. On production's largest versions list (678 versions) that's 3 ms, down from 290 ms, and the reads that used the rule already gain too.RepoLatestVersionMixinandRepoExportVersionMixineach replace copies of one lookup.RepoVersionListMixinreads a page's previous versions in one query, where each row had its own.Cost, on production data
Signed out: the count of
/sources/goes from 2 to 10 ms, that of/collections/from 11 to 86 ms (11,798 rows). A versions list is unchanged.For the reviewer
latestused to be refused when the newest release was private. It's now the newest one the requester can view. The tests that said otherwise are updated (tests_access_control.py,tests_release_map_codes.py).$cascadestarts from a concept of the version the URL names, HEAD's without one: any of its expansions', or the one the URL names./user/collections/<c>/latest/…now reads the signed-in user's own collection's release./repos/search with no hits answers 0, where it failed.Tests
New:
core/integration_tests/tests_viewable_versions.py: signed out, another signed-in user, a member, an admin, an owner and staff, for sources and collections, HEAD and releases apart.Refs OpenConceptLab/ocl_online#747, OpenConceptLab/ocl_online#546, OpenConceptLab/ocl_online#735.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk