fix: keep rating, tags and custom_metadata out of the book form #39
Loading…
Reference in a new issue
No description provided.
Delete branch "jtk/book-internal-fields"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #25.
Problem: since #17,
Book.changeset/2also castrating,tagsandcustom_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/2casts only the user-editable fields again (rating validation moved out with the field).Book.metadata_changeset/2: runschangeset/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.Catalog.create_book_from_metadata/1andCatalog.update_book_metadata/2use 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 checksrating == 10still passes through the new path.mix precommitgreen.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.