Restrict field, What work is this an edition of? to super librarians and admins.
Restrict What work is this an edition of? to super librarians and admins.
This field is frequently misused and can make it difficult to identify works with common titles once all editions are removed from it. This field is only meant to be used for mis-placed editions, but is often used in place of duplicate reporting or to repurpose a work record. The field is documented, but there is no way to be sure someone has read the documentation prior to editing a record.
Context
- The field lives in the edition edit form:
openlibrary/templates/books/edit/edition.html#L399-L416. Today the only permission check applied to it is on the "-- Move to a new work" option ('addnew': is_librarian) — the field itself (searching/reassigning to any existing work) is visible and editable by any logged-in user, with no role check at all. - The template already computes
is_adminandis_super_librarianas local vars (edition.html#L4-L7), and there's a directly analogous precedent later in the same file for gating a whole section behind a role check:$if is_admin:wraps the "Admin Only" fieldset (edition.html#L672-L682). Useralready exposes a combined check for exactly "super librarian or admin":is_super_librarian_or_higher()(openlibrary/core/models.py#L989-L995). Noteis_super_librarian()alone does not include admins, so the fix should useis_super_librarian_or_higher()rather than the existingis_super_librarianvar.- Hiding the field in the template would only be a UI-level restriction — the save path (
SaveBookHelper.save/process_inputinopenlibrary/plugins/upstream/addbook.py) currently applies no permission check to a submittededition--workschange, so a crafted form POST could still reassign the work regardless of the UI. There's an existing precedent for backend enforcement of a similarly sensitive field:_prevent_ocaid_deletionchecksuser.is_super_librarian_or_higher()before allowing an OCAID change, and raisesValidationExceptionotherwise (addbook.py#L748-L768, called fromaddbook.py#L702). - Related open issue: #11346 ("Allow Super Librarians to quickly move an edition to a new work") targets the exact same field/page from a UX-efficiency angle rather than a restriction angle. Worth cross-referencing so the two changes don't conflict.
Issue Assessment
Open questions
- Should this restriction also apply to programmatic edits to an edition's
worksfield (e.g. the generic JSON save API, import/bulk-edit scripts), or only the human-facing edit form? This affects whether enforcement belongs only in the template or also inSaveBookHelper. - How does this interact with #11346, which proposes giving super librarians a faster UI to move editions to a new work on the same page?
Action items
- [x] Is there an existing permission check reusable for this? (Answer: yes —
is_super_librarian_or_higher()onUseralready exists and is used for an analogous restriction (_prevent_ocaid_deletion); no new permission primitive needs to be built.) - [x] Is a template-only (frontend) change sufficient? (Answer: no — the field is currently unenforced server-side, so a template-only hide would not actually stop a non-privileged user from submitting a work change directly; enforcement should mirror the
_prevent_ocaid_deletionpattern inaddbook.py.)
Suggested breakdown
- [ ] Gate the "What work is this an edition of?" field in
edition.htmlbehindis_super_librarian_or_higher()(frontend-only; could be aGood First Issueon its own) - [ ] Add server-side enforcement in
SaveBookHelper(addbook.py) rejecting/ignoring a submitted work reassignment from a non-privileged user, following the_prevent_ocaid_deletionpattern - [ ] Decide scope re: programmatic/API edits vs. the web form only
- [ ] Add test coverage for both the hidden field and the backend rejection path
🔔 Stakeholders
@cdrini — currently the assigned lead on #11346, which touches this exact same field/page; flagging for awareness of potential overlap/conflict between the two issues.
Full triage checklist
- [x] Triage — correct labels applied or removed
- [x] Problem / opportunity — problem is clear, audience identified, actionable
- [x] Scope — issue is well-scoped; does not try to do too many things
- [ ] Justification — reasoning and impact stated; sufficient for leads to prioritize
- [ ] Success & testing criteria — defines what "done" looks like, verifiable by a contributor
- [ ] Proposal & breakdown — concrete plan present; checklist actionable for a contributor
- [ ] If bug: environment & repro steps — browser, version, local vs prod; steps to reproduce
- [ ] Risks, concerns, open questions — identified and surfaced
- [x] Richy context — relevant code, commits, PRs reviewed; no duplicate found
- [ ] References — screenshots, designs, docs, and links present where needed
[!NOTE] This comment was automatically generated by Richy, Open Library's issue enrichment assistant, on behalf of @mekarpeles. This is NOT a sign-off. This issue needs lead review before work begins.
Hi! I'd like to work on this please.
Hi @cdrini, I would like to take up this issue. It seems like a good start for my first contribution
Hi, I’d like to work on this issue. I have gone through the context and suggested breakdown. I’ll restrict the edition-to-work field to super librarians and admins using the existing is_super_librarian_or_higher() permission check, then add matching server-side validation in SaveBookHelper so unauthorized form submissions cannot reassign an edition. I’ll also add test coverage for both the UI restriction and backend enforcement, while preserving the existing super-librarian workflow for moving editions to new works.
Howdy folks thanks for the interest! @iamtanmaybaranwal already opened a PR for this a while back so considering assigned to them :+1:
@iamtanmaybaranwal if you leave a comment on this issue, I can assign you to it.
Thanks @cdrini ! I’ve already opened PR #13711 addressing this issue, including the UI restriction and server-side enforcement. I’d be happy to take ownership of the issue. Please assign it to me. 👍