janeczku / calibre-web

:books: Web app for browsing, reading and downloading eBooks stored in a Calibre database
GNU General Public License v3.0
12.01k stars 1.28k forks source link

Adding a tag to a book doesn't sync to Kobo accounts that have tag view restrictions #2992

Open deviantintegral opened 5 months ago

deviantintegral commented 5 months ago

Describe the bug/problem

We have calibre-web set up with accounts that have view restrictions via tags. For example, we would like to sync only books tagged "kids" to some e-readers.

We noticed that some books were not syncing at all. This appears to be due this logic that causes the book to by synced with ChangedEntitlement instead of NewEntitlement:

https://github.com/janeczku/calibre-web/blob/977f07364be4f47d9aa50fffc0f7169e1ba9d674/cps/kobo.py#L231-L234

This is easiest to see by uncommenting https://github.com/janeczku/calibre-web/blob/977f07364be4f47d9aa50fffc0f7169e1ba9d674/cps/kobo.py#L326 and noting the sync data is not NewEntitlement. If I hack this to always send NewEntitlement, the book syncs correctly.

As a workaround this can be fixed by forcing a full Kobo library sync.

To Reproduce

Steps to reproduce the behaviour:

  1. Set up an account with tag view restrictions and Kobo integration.
  2. Add a book to the library, but make sure it does not have the restricted tag on it.
  3. Sync the kobo device (nothing should sync, this is expected and OK).
  4. Add the restricted tag to the book.
  5. Sync the device again.
  6. Note the book is missing.

Logfile

[2024-01-27 23:10:50,019]  INFO {cps.kobo:143} Kobo library sync request received.
[2024-01-27 23:10:50,020] DEBUG {cps.kobo:144} SyncToken: <REDACTED>
[2024-01-27 23:10:50,020] DEBUG {cps.kobo:145} Download link format <REDACTED>
[2024-01-27 23:10:50,031] DEBUG {cps.kobo:204} Books to Sync: 1
[2024-01-27 23:10:50,076] DEBUG {cps.kobo:258} Remaining books to Sync: 0

Expected behavior

When a tag is added, the book will fully sync to the Kobo.

Environment (please complete the following information):

Additional context

I'm unsure on how to fix this properly. On a first pass, I don't see any metadata that would allow us to identify that the tag visibility results have changed, and to treat those books as new instead of changed.