From d8f9e2feb2f136f51b0e869b8f4acdd3d31d8fbb Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Wed, 6 Oct 2021 18:41:01 +0200 Subject: [PATCH] Bugfixes for user import with default locale and default language Bugfixes from testrun --- cps/admin.py | 17 +- cps/config_sql.py | 2 + cps/kobo.py | 5 +- cps/templates/book_edit.html | 1 + cps/templates/config_view_edit.html | 17 + cps/templates/layout.html | 1 + test/Calibre-Web TestSummary_Linux.html | 2141 ++++++++++++++++------- 7 files changed, 1506 insertions(+), 678 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 6d6c3ba2..f1c3e57a 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -235,8 +235,12 @@ def view_configuration(): .filter(and_(db.Custom_Columns.datatype == 'bool', db.Custom_Columns.mark_for_delete == 0)).all() restrict_columns = calibre_db.session.query(db.Custom_Columns)\ .filter(and_(db.Custom_Columns.datatype == 'text', db.Custom_Columns.mark_for_delete == 0)).all() + languages = calibre_db.speaking_language() + translations = [LC('en')] + babel.list_translations() return render_title_template("config_view_edit.html", conf=config, readColumns=read_column, restrictColumns=restrict_columns, + languages=languages, + translations=translations, title=_(u"UI Configuration"), page="uiconfig") @admi.route("/admin/usertable") @@ -514,16 +518,12 @@ def check_valid_restricted_column(column): return True - @admi.route("/admin/viewconfig", methods=["POST"]) @login_required @admin_required def update_view_configuration(): to_save = request.form.to_dict() - # _config_string = lambda x: config.set_from_dictionary(to_save, x, lambda y: y.strip() if y else y) - # _config_int = lambda x: config.set_from_dictionary(to_save, x, int) - _config_string(to_save, "config_calibre_web_title") _config_string(to_save, "config_columns_to_ignore") if _config_string(to_save, "config_title_regex"): @@ -545,6 +545,8 @@ def update_view_configuration(): _config_int(to_save, "config_random_books") _config_int(to_save, "config_books_per_page") _config_int(to_save, "config_authors_max") + _config_string(to_save, "config_default_language") + _config_string(to_save, "config_default_locale") config.config_default_role = constants.selected_roles(to_save) @@ -1350,6 +1352,8 @@ def _handle_new_user(to_save, content, languages, translations, kobo_support): languages=languages, title=_(u"Add new user"), page="newuser", kobo_support=kobo_support, registered_oauth=oauth_check) try: + content.default_language = config.config_default_language + content.locale = config.config_default_locale content.allowed_tags = config.config_allowed_tags content.denied_tags = config.config_denied_tags content.allowed_column_value = config.config_allowed_column_value @@ -1739,9 +1743,8 @@ def ldap_import_create_user(user, user_data): content.password = '' # dummy password which will be replaced by ldap one content.email = useremail content.kindle_mail = kindlemail - content.kindle_mail = kindlemail - content.default_language = config.default_language - content.locale = config.locale + content.default_language = config.config_default_language + content.locale = config.config_default_locale content.sidebar_view = config.config_default_show content.allowed_tags = config.config_allowed_tags content.denied_tags = config.config_denied_tags diff --git a/cps/config_sql.py b/cps/config_sql.py index 232de145..0b45059d 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -89,6 +89,8 @@ class _Settings(_Base): config_default_role = Column(SmallInteger, default=0) config_default_show = Column(SmallInteger, default=constants.ADMIN_USER_SIDEBAR) + config_default_language = Column(String(3), default="all") + config_default_locale = Column(String(2), default="en") config_columns_to_ignore = Column(String) config_denied_tags = Column(String, default="") diff --git a/cps/kobo.py b/cps/kobo.py index 5ce2b640..ad0771a4 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -538,6 +538,7 @@ def HandleTagCreate(): return make_response(jsonify(str(shelf.uuid)), 201) +@csrf.exempt @kobo.route("/v1/library/tags/", methods=["DELETE", "PUT"]) @requires_kobo_auth def HandleTagUpdate(tag_id): @@ -765,7 +766,7 @@ def create_kobo_tag(shelf): ) return {"Tag": tag} - +@csrf.exempt @kobo.route("/v1/library//state", methods=["GET", "PUT"]) @requires_kobo_auth def HandleStateRequest(book_uuid): @@ -950,6 +951,7 @@ def TopLevelEndpoint(): return make_response(jsonify({})) +@csrf.exempt @kobo.route("/v1/library/", methods=["DELETE"]) @requires_kobo_auth def HandleBookDeletionRequest(book_uuid): @@ -976,6 +978,7 @@ def HandleBookDeletionRequest(book_uuid): # TODO: Implement the following routes +@csrf.exempt @kobo.route("/v1/library/", methods=["DELETE", "GET"]) def HandleUnimplementedRequest(dummy=None): log.debug("Unimplemented Library Request received: %s", request.base_url) diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index a47f400a..f3a1f5ac 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -49,6 +49,7 @@
+
diff --git a/cps/templates/config_view_edit.html b/cps/templates/config_view_edit.html index b2578312..ebfb5362 100644 --- a/cps/templates/config_view_edit.html +++ b/cps/templates/config_view_edit.html @@ -115,6 +115,23 @@
+
+ + +
+
+ + +
diff --git a/cps/templates/layout.html b/cps/templates/layout.html index 7ec79f45..09b3f507 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -62,6 +62,7 @@ {% if g.allow_upload %}
  • +
    {{_('Upload')}} diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index f4ba8f0a..0bcf44a9 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
    -

    Start Time: 2021-09-23 19:58:16

    +

    Start Time: 2021-10-05 19:35:18

    -

    Stop Time: 2021-09-23 23:23:05

    +

    Stop Time: 2021-10-05 22:41:33

    -

    Duration: 2h 40 min

    +

    Duration: 2h 27 min

    @@ -404,13 +404,13 @@ TestEbookConvertCalibre - 13 - 13 + 14 + 14 0 0 0 - Detail + Detail @@ -454,7 +454,7 @@ -
    TestEbookConvertCalibre - test_convert_parameter
    +
    TestEbookConvertCalibre - test_convert_options
    PASS @@ -463,7 +463,7 @@ -
    TestEbookConvertCalibre - test_convert_wrong_excecutable
    +
    TestEbookConvertCalibre - test_convert_parameter
    PASS @@ -472,7 +472,7 @@ -
    TestEbookConvertCalibre - test_convert_xss
    +
    TestEbookConvertCalibre - test_convert_wrong_excecutable
    PASS @@ -481,7 +481,7 @@ -
    TestEbookConvertCalibre - test_email_failed
    +
    TestEbookConvertCalibre - test_convert_xss
    PASS @@ -490,7 +490,7 @@ -
    TestEbookConvertCalibre - test_email_only
    +
    TestEbookConvertCalibre - test_email_failed
    PASS @@ -499,7 +499,7 @@ -
    TestEbookConvertCalibre - test_kindle_send_not_configured
    +
    TestEbookConvertCalibre - test_email_only
    PASS @@ -508,7 +508,7 @@ -
    TestEbookConvertCalibre - test_ssl_smtp_setup_error
    +
    TestEbookConvertCalibre - test_kindle_send_not_configured
    PASS @@ -517,7 +517,7 @@ -
    TestEbookConvertCalibre - test_starttls_smtp_setup_error
    +
    TestEbookConvertCalibre - test_ssl_smtp_setup_error
    PASS @@ -525,6 +525,15 @@ + +
    TestEbookConvertCalibre - test_starttls_smtp_setup_error
    + + PASS + + + + +
    TestEbookConvertCalibre - test_user_convert_xss
    @@ -687,12 +696,12 @@ - + TestEditAdditionalBooks 15 - 14 - 0 - 0 + 8 + 2 + 4 1 Detail @@ -773,29 +782,101 @@ - +
    TestEditAdditionalBooks - test_upload_edit_role
    - PASS + +
    + ERROR +
    + + + + - +
    TestEditAdditionalBooks - test_upload_metadata_cbr
    - PASS + +
    + ERROR +
    + + + + - +
    TestEditAdditionalBooks - test_upload_metadata_cbt
    - PASS + +
    + ERROR +
    + + + + @@ -811,8 +892,8 @@