From 56c71dd4bfb77ebb5b0e007da36cf30df42a8d3a Mon Sep 17 00:00:00 2001 From: Jonathan Rehm Date: Sat, 30 Sep 2017 10:51:20 -0700 Subject: [PATCH] Disable bookmarking when anonymous users are reading --- cps/static/js/reading/epub.js | 9 +++++++-- cps/templates/read.html | 3 ++- cps/web.py | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cps/static/js/reading/epub.js b/cps/static/js/reading/epub.js index 5a72d767..169c207f 100644 --- a/cps/static/js/reading/epub.js +++ b/cps/static/js/reading/epub.js @@ -10,8 +10,13 @@ restore: true, bookmarks: calibre.bookmark ? [calibre.bookmark] : [] }); - reader.on("reader:bookmarked", updateBookmark.bind(reader, "add")); - reader.on("reader:unbookmarked", updateBookmark.bind(reader, "remove")); + + if (calibre.useBookmarks) { + reader.on("reader:bookmarked", updateBookmark.bind(reader, "add")); + reader.on("reader:unbookmarked", updateBookmark.bind(reader, "remove")); + } else { + $("#bookmark, #show-Bookmarks").remove(); + } /** * @param {string} action - Add or remove bookmark diff --git a/cps/templates/read.html b/cps/templates/read.html index 2fb214f3..d972c2f6 100644 --- a/cps/templates/read.html +++ b/cps/templates/read.html @@ -83,7 +83,8 @@ cssPath: "{{ url_for('static', filename='css/') }}", bookUrl: "{{ url_for('static', filename=bookid) }}/", bookmarkUrl: "{{ url_for('bookmark', book_id=bookid, book_format='EPUB') }}", - bookmark: "{{ bookmark.bookmark_key if bookmark != None }}" + bookmark: "{{ bookmark.bookmark_key if bookmark != None }}", + useBookmarks: {{ g.user.is_authenticated | tojson }} }; diff --git a/cps/web.py b/cps/web.py index 5873bad8..35096070 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1779,7 +1779,9 @@ def read_book(book_id, book_format): book_dir = os.path.join(config.get_main_dir, "cps", "static", str(book_id)) if not os.path.exists(book_dir): os.mkdir(book_dir) - bookmark = ub.session.query(ub.Bookmark).filter(ub.and_(ub.Bookmark.user_id == int(current_user.id), + bookmark = None + if current_user.is_authenticated: + bookmark = ub.session.query(ub.Bookmark).filter(ub.and_(ub.Bookmark.user_id == int(current_user.id), ub.Bookmark.book_id == book_id, ub.Bookmark.format == book_format.upper())).first() if book_format.lower() == "epub":