fix: keep rating, tags and custom_metadata out of the book form #39

Merged
jfro merged 2 commits from jtk/book-internal-fields into main 2026-10-18 17:49:01 +00:00
Owner

Closes #25.

Problem: since #17, Book.changeset/2 also cast rating, tags and custom_metadata. Those are meant to be filled in by ebook processing (OPF/Calibre metadata), but the same changeset backs the book create/edit forms, so a user could set them by adding params to the form post.

Fix:

  • Book.changeset/2 casts only the user-editable fields again (rating validation moved out with the field).
  • New Book.metadata_changeset/2: runs changeset/2 (so all its validations, including the cover-key check from #20, still apply), then casts the three metadata fields and validates rating 0–10.
  • New Catalog.create_book_from_metadata/1 and Catalog.update_book_metadata/2 use it. The ebook ProcessWorker is the only caller. Sync, import and the controllers keep the user changeset.

Tests: 4 new in book_test.exs (user changeset ignores the fields with atom and string keys, metadata changeset sets them and rejects rating 11, metadata changeset keeps the cover-key validation). The existing ProcessWorker test that checks rating == 10 still passes through the new path. mix precommit green.

Closes #25. **Problem:** since #17, `Book.changeset/2` also cast `rating`, `tags` and `custom_metadata`. Those are meant to be filled in by ebook processing (OPF/Calibre metadata), but the same changeset backs the book create/edit forms, so a user could set them by adding params to the form post. **Fix:** - `Book.changeset/2` casts only the user-editable fields again (rating validation moved out with the field). - New `Book.metadata_changeset/2`: runs `changeset/2` (so all its validations, including the cover-key check from #20, still apply), then casts the three metadata fields and validates rating 0–10. - New `Catalog.create_book_from_metadata/1` and `Catalog.update_book_metadata/2` use it. The ebook ProcessWorker is the only caller. Sync, import and the controllers keep the user changeset. **Tests:** 4 new in `book_test.exs` (user changeset ignores the fields with atom and string keys, metadata changeset sets them and rejects rating 11, metadata changeset keeps the cover-key validation). The existing ProcessWorker test that checks `rating == 10` still passes through the new path. `mix precommit` green.
fix: keep rating, tags and custom_metadata out of the book form
All checks were successful
CI / test (pull_request) Successful in 42s
7821bf8bd4
Book.changeset/2 casts only user-editable fields again. Ebook processing
uses the new Book.metadata_changeset/2 through
Catalog.create_book_from_metadata/1 and Catalog.update_book_metadata/2.

Closes #25
jfro left a comment

Review from Nye: APPROVE at 7821bf8 (posted by Upper Wolfjaw; Nye's token is read-only)

CI green. Every caller in lib/ checked: only the ebook ProcessWorker sets rating/tags/custom_metadata (now through create_book_from_metadata/update_book_metadata). ExternalLibrarySync, import, export, find_or_create_book and the controllers/LiveViews never set those fields, so nothing loses data. MetadataExtractor only builds the map ProcessWorker passes on. metadata_changeset keeps the user changeset's validations (cover_key format etc.), and the 4 tests cover atom and string keys.

**Review from Nye: APPROVE** at 7821bf8 (posted by Upper Wolfjaw; Nye's token is read-only) CI green. Every caller in lib/ checked: only the ebook ProcessWorker sets rating/tags/custom_metadata (now through create_book_from_metadata/update_book_metadata). ExternalLibrarySync, import, export, find_or_create_book and the controllers/LiveViews never set those fields, so nothing loses data. MetadataExtractor only builds the map ProcessWorker passes on. metadata_changeset keeps the user changeset's validations (cover_key format etc.), and the 4 tests cover atom and string keys.
Merge branch 'main' into jtk/book-internal-fields
All checks were successful
CI / test (pull_request) Successful in 43s
a177a76cf5
jfro merged commit aece619cae into main 2026-10-18 17:49:01 +00:00
jfro deleted branch jtk/book-internal-fields 2026-10-18 17:49:01 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/fuzzy_catalog!39
No description provided.