From 06c15a792e5254b76bbad893739a7563822b4015 Mon Sep 17 00:00:00 2001 From: Michael Shavit Date: Tue, 21 Apr 2020 23:36:47 -0400 Subject: [PATCH] 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