From ed2fa4cdd8369925b373da914cb50d1662a6ed0d Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Wed, 28 Apr 2021 20:49:16 +0200 Subject: [PATCH] Update error handling for user list (#1938) --- cps/admin.py | 24 +++- test/Calibre-Web TestSummary_Linux.html | 152 +++++++++++------------- 2 files changed, 87 insertions(+), 89 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 55ab41ad..695a967b 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -47,7 +47,7 @@ from .helper import check_valid_domain, send_test_mail, reset_password, generate valid_email, check_username from .gdriveutils import is_gdrive_ready, gdrive_support from .render_template import render_title_template, get_sidebar_config -from . import debug_info +from . import debug_info, _BABEL_TRANSLATIONS try: from functools import wraps @@ -369,13 +369,13 @@ def edit_list_user(param): if "pk[]" in vals: users = all_user.filter(ub.User.id.in_(vals['pk[]'])).all() else: - return "" + return _("Malformed request"), 400 if 'field_index' in vals: vals['field_index'] = vals['field_index'][0] if 'value' in vals: vals['value'] = vals['value'][0] elif not ('value[]' in vals): - return "" + return _("Malformed request"), 400 for user in users: try: if param in ['denied_tags', 'allowed_tags', 'allowed_column_value', 'denied_column_value']: @@ -418,9 +418,23 @@ def edit_list_user(param): elif param == 'locale': if user.name == "Guest": raise Exception(_("Guest's Locale is determined automatically and can't be set")) - user.locale = vals['value'] + if vals['value'] in _BABEL_TRANSLATIONS: + user.locale = vals['value'] + else: + raise Exception(_("No Valid Locale Given")) elif param == 'default_language': - user.default_language = vals['value'] + languages = calibre_db.session.query(db.Languages) \ + .join(db.books_languages_link) \ + .join(db.Books) \ + .filter(calibre_db.common_filters()) \ + .group_by(text('books_languages_link.lang_code')).all() + lang_codes = [lang.lang_code for lang in languages] + ["all"] + if vals['value'] in lang_codes: + user.default_language = vals['value'] + else: + raise Exception(_("No Valid Book Language Given")) + else: + return _("Parameter not found"), 400 except Exception as ex: log.debug_or_exception(ex) return str(ex), 400 diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 5f2e97ad..bb999140 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,14 +37,14 @@
-

Start Time: 2021-04-26 08:28:54

+

Start Time: 2021-04-27 20:06:09

-

Stop Time: 2021-04-26 11:26:09

+

Stop Time: 2021-04-27 23:04:55

@@ -1269,12 +1269,12 @@ - + TestEditBooksOnGdrive 20 - 20 - 0 - 0 + 18 + 1 + 1 0 Detail @@ -1292,11 +1292,34 @@ - +
TestEditBooksOnGdrive - test_edit_author
- PASS + +
+ FAIL +
+ + + + @@ -1418,11 +1441,31 @@ - +
TestEditBooksOnGdrive - test_edit_title
- PASS + +
+ ERROR +
+ + + + @@ -2850,13 +2893,13 @@ - + TestUserList 16 - 13 - 2 + 16 + 0 + 0 0 - 1 Detail @@ -2891,28 +2934,11 @@ - +
TestUserList - test_user_list_denied_tags
- -
- SKIP -
- - - - + PASS @@ -2989,31 +3015,11 @@ - +
TestUserList - test_user_list_guest_edit
- -
- FAIL -
- - - - + PASS @@ -3036,33 +3042,11 @@ AssertionError: False is not true - +
TestUserList - test_user_list_sort
- -
- FAIL -
- - - - + PASS @@ -3769,10 +3753,10 @@ AssertionError: 'muki9al@b.com' != 'no@email' Total 331 - 322 - 2 - 0 - 7 + 323 + 1 + 1 + 6   @@ -4178,7 +4162,7 @@ AssertionError: 'muki9al@b.com' != 'no@email'