Skip to content

feat(modtools): bulk versionTitle rename#3197

Open
dcschreiber wants to merge 3 commits intofeature/sc-36475/modtools-pr1-backendfrom
feature/modtools-bulk-rename-version-title
Open

feat(modtools): bulk versionTitle rename#3197
dcschreiber wants to merge 3 commits intofeature/sc-36475/modtools-pr1-backendfrom
feature/modtools-bulk-rename-version-title

Conversation

@dcschreiber
Copy link
Copy Markdown
Contributor

@dcschreiber dcschreiber commented Mar 29, 2026

Summary

Adds bulk versionTitle rename and bulk permanent delete to the Bulk Version Editor (modtools), and consolidates versionTitle-rename logic into shared tracker.py helpers used by both the bulk and single-version (flag_text_api) endpoints.

What's included

  • Bulk rename (POST /api/version-bulk-edit with newVersionTitle):
    • Pre-checks all selected indices for duplicate conflicts, runs metadata updates first, then renames.
    • Version.save() fires attributeChange handlers via track_pkeys, cascading to history, search, links, topics, notifications, and user profiles.
    • Adds 5 missing cascade handlers for versionTitle changes (marked_up_text_chunks, linker_output, links, topic_links, user_history, profiles).
    • Frontend confirmation dialog lists side effects that cannot be auto-fixed (broken bookmarks, source-sheet refs, user version preferences).
  • Bulk permanent delete (POST /api/version-bulk-delete):
    • Replaces the previous "mark for deletion" soft-delete (which added a [MARKED FOR DELETION] note to versionNotes).
    • Permanently deletes selected Versions and records each via record_version_deletion.
    • Frontend shows a permanent-deletion confirmation; index list refreshes after success.
  • Shared rename helpers in sefaria/tracker.py:
    • validate_version_title_change, check_version_title_conflicts, rename_version_title.
    • Both version_bulk_edit_api and flag_text_api now go through the same code path. flag_text_api previously wrote newVersionTitle as a plain field update; it now properly cascades.
  • Docs (MODTOOLS_GUIDE.md, COMPONENT_LOGIC.md) updated for the new endpoint, the rename behavior, and the permanent-delete flow.

Test plan

  • pytest sefaria/tests/modtools_test.py (rename + cascade tests already cover bulk-edit/rename — bulk-delete tests still TODO)
  • Manual: search a versionTitle, enter new title, confirm rename dialog, verify refresh under the new title
  • Manual: select a few indices, click "Delete Versions", confirm, verify they disappear and history records the deletion
  • Verify old title returns no results after rename; check cascade in mongo (history, links, search)
  • Manual: hit flag_text_api with newVersionTitle for a single version and confirm it cascades the same way as bulk

dcschreiber and others added 2 commits March 29, 2026 13:33
Add the ability to rename versionTitle across multiple indices in the
bulk version editor. This was previously blocked because versionTitle
is part of the Version model's composite primary key, but the model
layer already supports renaming via track_pkeys + dependency handlers.

Backend:
- Extend version_bulk_edit_api to accept optional newVersionTitle
- Pre-check for duplicates across all indices before any modification
- Apply metadata updates first, then rename (two-phase per version)
- Version.save() fires existing attributeChange handlers automatically

New cascade handlers for versionTitle changes:
- marked_up_text_chunks + linker_output (versionTitle is a pkey)
- links.charLevelData + links.versions (essay-type)
- topic_links.charLevelData
- user_history.versions
- profiles.version_preferences_by_corpus

Frontend:
- Add "New Version Title" input in Version Identification section
- Confirmation dialog listing side effects before rename
- Auto-refresh search with new title after successful rename
- Partial success messaging for rename operations
- Changes preview shows rename operation

Tests:
- Rename succeeds across multiple indices
- Duplicate detection rejects conflicting renames
- Combined rename + field updates
- Empty/same title validation
- Cascade to marked_up_text_chunks and links.charLevelData

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add explicit CSRF token check before sending the upload request, and
handle 403 responses with a user-friendly message suggesting a page
refresh. Complements the server-side @ensure_csrf_cookie fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dcschreiber dcschreiber changed the base branch from fix/modtools-rewrite-csv-upload-fix to feature/sc-36475/modtools-pr1-backend March 30, 2026 09:58
Replaces the prior soft-delete ("mark for deletion") flow with a real
bulk delete endpoint: POST /api/version-bulk-delete now permanently
removes selected Versions and records each deletion via
record_version_deletion. The BulkVersionEditor's confirmation dialog
and help text are updated accordingly, and the index list refreshes
after a successful delete.

Also extracts versionTitle rename validation, conflict checking, and
cascading save into tracker.py helpers (validate_version_title_change,
check_version_title_conflicts, rename_version_title) so both
version_bulk_edit_api and the single-version flag_text_api go through
the same code path. flag_text_api now properly cascades a
newVersionTitle rename instead of writing it as a plain field update.

Docs (MODTOOLS_GUIDE, COMPONENT_LOGIC) updated to document the new
endpoint and the permanent-delete behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant