From 8e89d862fb062a3874ce849a9ad8300bf0a43748 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 13 Apr 2018 16:02:10 +0530 Subject: [PATCH] Browser viewer: Show an error message when trying to use the Sync function without being logged in --- src/calibre/srv/books.py | 4 +++- src/pyj/read_book/overlay.pyj | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/srv/books.py b/src/calibre/srv/books.py index 1919117fe7..565b42308b 100644 --- a/src/calibre/srv/books.py +++ b/src/calibre/srv/books.py @@ -148,7 +148,7 @@ def book_manifest(ctx, rd, book_id, fmt): ans = jsonlib.load(f) ans['metadata'] = book_as_json(db, book_id) user = rd.username or None - ans['last_read_positions'] = db.get_last_read_positions(book_id, fmt, user) + ans['last_read_positions'] = db.get_last_read_positions(book_id, fmt, user) if user else [] return ans except EnvironmentError as e: if e.errno != errno.ENOENT: @@ -189,6 +189,8 @@ def get_last_read_position(ctx, rd, library_id, which): ''' db = get_db(ctx, rd, library_id) user = rd.username or None + if not user: + raise HTTPNotFound('login required for sync') ans = {} allowed_book_ids = ctx.allowed_book_ids(rd, db) for item in which.split('_'): diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 4b68732740..7da105ff40 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -137,7 +137,10 @@ class SyncBook: # {{{ return self.overlay.hide() if load_type is not 'load': - error_dialog(_('Failed to fetch sync data'), _('Failed to download last read data from server, click "Show details" for more information.'), xhr.error_html) + if xhr.responseText is 'login required for sync': + error_dialog(_('Failed to fetch sync data'), _('You must setup user accounts and login to use the sync functionality')) + else: + error_dialog(_('Failed to fetch sync data'), _('Failed to download last read data from server, click "Show details" for more information.'), xhr.error_html) return data = JSON.parse(xhr.responseText) book = self.overlay.view.book