From ec7c2db9712a0598474e854a13746088700522a7 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 27 Nov 2021 12:26:28 +0100 Subject: [PATCH 1/3] Added package variable for generating "exe" file with pyinstaller --- cps/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cps/__init__.py b/cps/__init__.py index 118b46ff..34ccf438 100644 --- a/cps/__init__.py +++ b/cps/__init__.py @@ -19,6 +19,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +__package__ = "cps" import sys import os From 7f9da94a18daadb9e6b4c9cede41667a1402b5af Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Wed, 24 Nov 2021 17:35:09 +0100 Subject: [PATCH 2/3] Tie visibility of upload buttons to upload right only --- cps/editbooks.py | 2 +- cps/templates/book_edit.html | 8 +- cps/templates/config_edit.html | 2 +- cps/templates/layout.html | 4 +- test/Calibre-Web TestSummary_Linux.html | 488 ++++++++++++++++-------- 5 files changed, 340 insertions(+), 164 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 929aa1a7..75f1c96e 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -67,7 +67,7 @@ log = logger.create() def upload_required(f): @wraps(f) def inner(*args, **kwargs): - if current_user.role_upload() or current_user.role_admin(): + if current_user.role_upload(): return f(*args, **kwargs) abort(403) diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index 21ae98e6..cac3219c 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -98,8 +98,7 @@ - {% if g.user.role_upload() or g.user.role_admin()%} - {% if g.allow_upload %} + {% if g.user.role_upload() and g.allow_upload %}
@@ -109,7 +108,6 @@
- {% endif %} {% endif %}
@@ -197,14 +195,12 @@
{% endfor %} {% endif %} - {% if g.user.role_upload() or g.user.role_admin()%} - {% if g.allow_upload %} + {% if g.user.role_upload() and g.allow_upload %}
- {% endif %} {% endif %}
diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 4d6c68ce..f61ca9a5 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -105,7 +105,7 @@
- +
diff --git a/cps/templates/layout.html b/cps/templates/layout.html index 09b3f507..8cb6b76e 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -58,8 +58,7 @@ {% endif %}
- {% endif %} {% endif %} {% if not g.user.is_anonymous %}
  • diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 55c6bf1e..60fa4514 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
    -

    Start Time: 2021-11-22 21:51:33

    +

    Start Time: 2021-11-24 20:41:04

    -

    Stop Time: 2021-11-23 01:35:04

    +

    Stop Time: 2021-11-25 00:24:57

    -

    Duration: 3h 2 min

    +

    Duration: 3h 3 min

    @@ -102,12 +102,12 @@ - + TestAnonymous 13 - 12 + 13 + 0 0 - 1 0 Detail @@ -224,31 +224,11 @@ - +
    TestAnonymous - test_guest_visibility_sidebar
    - -
    - ERROR -
    - - - - + PASS @@ -901,12 +881,12 @@ AttributeError: 'TestAnonymous' object has no attribute 'assertFtest - + TestEditBooks 35 - 33 - 1 + 26 0 + 8 1 Detail @@ -1166,98 +1146,26 @@ AttributeError: 'TestAnonymous' object has no attribute 'assertFtest - +
    TestEditBooks - test_upload_book_cbr
    - PASS - - - - - - -
    TestEditBooks - test_upload_book_cbt
    - - PASS - - - - - - -
    TestEditBooks - test_upload_book_cbz
    - - PASS - - - - - - -
    TestEditBooks - test_upload_book_epub
    - - PASS - - - - - - -
    TestEditBooks - test_upload_book_fb2
    - - PASS - - - - - - -
    TestEditBooks - test_upload_book_lit
    - - PASS - - - - - - -
    TestEditBooks - test_upload_book_mobi
    - - PASS - - - - - - -
    TestEditBooks - test_upload_book_pdf
    - - PASS - - - - - - -
    TestEditBooks - test_upload_cover_hdd
    -
    - FAIL + ERROR
    - @@ -1722,12 +1862,12 @@ AssertionError: 'series' unexpectedly found in {'id': 5, 're - + TestSSL 7 - 7 - 0 + 6 0 + 1 0 Detail @@ -1781,11 +1921,31 @@ AssertionError: 'series' unexpectedly found in {'id': 5, 're - +
    TestSSL - test_email_limit
    - PASS + +
    + ERROR +
    + + + + @@ -2888,12 +3048,12 @@ AssertionError: 'series' unexpectedly found in {'id': 5, 're - + TestReader 5 - 5 - 0 + 4 0 + 1 0 Detail @@ -2929,11 +3089,33 @@ AssertionError: 'series' unexpectedly found in {'id': 5, 're - +
    TestReader - test_sound_listener
    - PASS + +
    + ERROR +
    + + + + @@ -4268,9 +4450,9 @@ AssertionError: 'series' unexpectedly found in {'id': 5, 're Total 376 - 366 - 3 + 357 1 + 12 6   @@ -4677,7 +4859,7 @@ AssertionError: 'series' unexpectedly found in {'id': 5, 're From 87e526642cbbb2491ecdcf6c616479481ca817d0 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 27 Nov 2021 18:19:25 +0100 Subject: [PATCH 3/3] Bugfix edit series_index Bugfix invalid languages --- cps/editbooks.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 75f1c96e..31e38d2a 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -31,7 +31,6 @@ try: except ImportError: pass - # Improve this to check if scholarly is available in a global way, like other pythonic libraries try: from scholarly import scholarly @@ -454,7 +453,7 @@ def edit_book_series_index(series_index, book): if not series_index.replace('.', '', 1).isdigit(): flash(_("%(seriesindex)s is not a valid number, skipping", seriesindex=series_index), category="warning") return False - if book.series_index != series_index: + if str(book.series_index) != series_index: book.series_index = series_index modif_date = True return modif_date @@ -484,11 +483,11 @@ def edit_book_languages(languages, book, upload=False, invalid=None): else: input_l = isoLanguages.get_valid_language_codes(get_locale(), input_languages, unknown_languages) for l in unknown_languages: - log.error('%s is not a valid language', l) + log.error("'%s' is not a valid language", l) if isinstance(invalid, list): invalid.append(l) else: - flash(_(u"%(langname)s is not a valid language", langname=l), category="warning") + raise ValueError(_(u"'%(langname)s' is not a valid language", langname=l)) # ToDo: Not working correct if upload and len(input_l) == 1: # If the language of the file is excluded from the users view, it's not imported, to allow the user to view @@ -848,6 +847,10 @@ def edit_book(book_id): calibre_db.session.rollback() flash(error, category="error") return render_edit_book(book_id) + except ValueError as e: + calibre_db.session.rollback() + flash(str(e), category="error") + return redirect(url_for('web.show_book', book_id=book.id)) except Exception as ex: log.debug_or_exception(ex) calibre_db.session.rollback() @@ -944,7 +947,11 @@ def create_book_on_upload(modif_date, meta): modif_date |= edit_book_series_index(meta.series_id, db_book) # add languages - modif_date |= edit_book_languages(meta.languages, db_book, upload=True) + invalid=[] + modif_date |= edit_book_languages(meta.languages, db_book, upload=True, invalid=invalid) + if invalid: + for l in invalid: + flash(_(u"'%(langname)s' is not a valid language", langname=l), category="warning") # handle tags modif_date |= edit_book_tags(meta.tags, db_book)