From 06c15a792e5254b76bbad893739a7563822b4015 Mon Sep 17 00:00:00 2001 From: Michael Shavit Date: Tue, 21 Apr 2020 23:36:47 -0400 Subject: [PATCH 1/3] Minor fixes to the Kobo shelves implementation (mostly typos) --- cps/kobo.py | 10 +++++----- cps/shelf.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cps/kobo.py b/cps/kobo.py index ee0aa810..8be76f8a 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -407,7 +407,7 @@ def HandleTagCreate(): log.debug("Received malformed v1/library/tags request.") abort(400, description="Malformed tags POST request. Data is missing 'Name' or 'Items' field") - shelf = ub.session.query(ub.Shelf).filter(and_(ub.Shelf.name) == name, ub.Shelf.user_id == + shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.name == name, ub.Shelf.user_id == current_user.id).one_or_none() if shelf and not shelf_lib.check_shelf_edit_permissions(shelf): abort(401, description="User is unauthaurized to edit shelf.") @@ -426,7 +426,7 @@ def HandleTagCreate(): @kobo.route("/v1/library/tags/", methods=["DELETE", "PUT"]) def HandleTagUpdate(tag_id): - shelf = ub.session.query(ub.Shelf).filter(and_(ub.Shelf.uuid) == tag_id, + shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.uuid == tag_id, ub.Shelf.user_id == current_user.id).one_or_none() if not shelf: log.debug("Received Kobo tag update request on a collection unknown to CalibreWeb") @@ -487,7 +487,7 @@ def HandleTagAddItem(tag_id): log.debug("Received malformed v1/library/tags//items/delete request.") abort(400, description="Malformed tags POST request. Data is missing 'Items' field") - shelf = ub.session.query(ub.Shelf).filter(and_(ub.Shelf.uuid) == tag_id, + shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.uuid == tag_id, ub.Shelf.user_id == current_user.id).one_or_none() if not shelf: log.debug("Received Kobo request on a collection unknown to CalibreWeb") @@ -498,7 +498,7 @@ def HandleTagAddItem(tag_id): items_unknown_to_calibre = add_items_to_shelf(items, shelf) if items_unknown_to_calibre: - log.debug("Received request to add an unknown book to a collecition. Silently ignoring item.") + log.debug("Received request to add an unknown book to a collection. Silently ignoring item.") ub.session.merge(shelf) ub.session.commit() @@ -600,7 +600,7 @@ def create_kobo_tag(shelf): book = db.session.query(db.Books).filter(db.Books.id == book_shelf.book_id).one_or_none() if not book: log.info(u"Book (id: %s) in BookShelf (id: %s) not found in book database", book_shelf.book_id, shelf.id) - return None + continue tag["Items"].append( { "RevisionId": book.uuid, diff --git a/cps/shelf.py b/cps/shelf.py index 4924a186..7d79724e 100644 --- a/cps/shelf.py +++ b/cps/shelf.py @@ -240,7 +240,7 @@ def create_shelf(): @login_required def edit_shelf(shelf_id): shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first() - if request.method == "POST": + if request.method == "POST": to_save = request.form.to_dict() is_shelf_name_unique = False From 9296d35517493ee928a29f04f903315e15fb43ef Mon Sep 17 00:00:00 2001 From: Michael Shavit Date: Tue, 21 Apr 2020 23:57:20 -0400 Subject: [PATCH 2/3] Fix bug with shelf deletions for Kobo. We were incorrectly setting the user_id field in the ShelfArchive table --- cps/shelf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/shelf.py b/cps/shelf.py index 7d79724e..2801b9b6 100644 --- a/cps/shelf.py +++ b/cps/shelf.py @@ -283,7 +283,7 @@ def delete_shelf_helper(cur_shelf): shelf_id = cur_shelf.id ub.session.delete(cur_shelf) ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).delete() - ub.session.add(ub.ShelfArchive(uuid = cur_shelf.uuid, user_id = cur_shelf.uuid)) + ub.session.add(ub.ShelfArchive(uuid = cur_shelf.uuid, user_id = cur_shelf.user_id)) ub.session.commit() log.info("successfully deleted %s", cur_shelf) From 742ec2b38d59637a12697880fda6bc98ab6b3d4c Mon Sep 17 00:00:00 2001 From: Michael Shavit Date: Wed, 22 Apr 2020 00:19:33 -0400 Subject: [PATCH 3/3] Fix issue with the delete_book changes introduced in 41a3623 --- cps/editbooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 28a8d2a6..8ac7b2c8 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -179,7 +179,7 @@ def delete_book(book_id, book_format): # delete book from Shelfs, Downloads, Read list ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book_id).delete() ub.session.query(ub.ReadBook).filter(ub.ReadBook.book_id == book_id).delete() - ub.session.query(ub.ArchivedBook).filter(ub.ReadBook.book_id == book_id).delete() + ub.session.query(ub.ArchivedBook).filter(ub.ArchivedBook.book_id == book_id).delete() ub.delete_download(book_id) ub.session.commit()