openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Restrict field, What work is this an edition of? to super librarians and admins.

Open seabelis opened this issue 2 months ago • 6 comments

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.

seabelis avatar Sep 16 '26 09:09 seabelis

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_admin and is_super_librarian as 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).
  • User already exposes a combined check for exactly "super librarian or admin": is_super_librarian_or_higher() (openlibrary/core/models.py#L989-L995). Note is_super_librarian() alone does not include admins, so the fix should use is_super_librarian_or_higher() rather than the existing is_super_librarian var.
  • Hiding the field in the template would only be a UI-level restriction — the save path (SaveBookHelper.save / process_input in openlibrary/plugins/upstream/addbook.py) currently applies no permission check to a submitted edition--works change, 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_deletion checks user.is_super_librarian_or_higher() before allowing an OCAID change, and raises ValidationException otherwise (addbook.py#L748-L768, called from addbook.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 works field (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 in SaveBookHelper.
  • 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() on User already 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_deletion pattern in addbook.py.)

Suggested breakdown

  • [ ] Gate the "What work is this an edition of?" field in edition.html behind is_super_librarian_or_higher() (frontend-only; could be a Good First Issue on 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_deletion pattern
  • [ ] 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.

openlibrary-bot avatar Sep 16 '26 09:09 openlibrary-bot

Hi! I'd like to work on this please.

honestlywhoknows avatar Sep 21 '26 21:09 honestlywhoknows

Hi @cdrini, I would like to take up this issue. It seems like a good start for my first contribution

Shreya-S-Jadhav avatar Sep 22 '26 08:09 Shreya-S-Jadhav

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.

Yashhuc avatar Sep 22 '26 17:09 Yashhuc

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.

cdrini avatar Oct 05 '26 16:10 cdrini

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. 👍

iamtanmaybaranwal avatar Oct 05 '26 16:10 iamtanmaybaranwal