diff --git a/cps/admin.py b/cps/admin.py index c859eef5..633ee0f2 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -473,6 +473,21 @@ def update_table_settings(): return "Invalid request", 400 return "" +def check_valid_read_column(column): + if column != "0": + if not calibre_db.session.query(db.Custom_Columns).filter(db.Custom_Columns.id == column) \ + .filter(and_(db.Custom_Columns.datatype == 'bool', db.Custom_Columns.mark_for_delete == 0)).all(): + return False + return True + +def check_valid_restricted_column(column): + if column != "0": + if not calibre_db.session.query(db.Custom_Columns).filter(db.Custom_Columns.id == column) \ + .filter(and_(db.Custom_Columns.datatype == 'text', db.Custom_Columns.mark_for_delete == 0)).all(): + return False + return True + + @admi.route("/admin/viewconfig", methods=["POST"]) @login_required @@ -488,12 +503,23 @@ def update_view_configuration(): if _config_string("config_title_regex"): calibre_db.update_title_sort(config) + if not check_valid_read_column(to_save.get("config_read_column", "0")): + flash(_(u"Invalid Read Column"), category="error") + log.debug("Invalid Read column") + return view_configuration() _config_int("config_read_column") + + if not check_valid_restricted_column(to_save.get("config_restricted_column", "0")): + flash(_(u"Invalid Restricted Column"), category="error") + log.debug("Invalid Restricted Column") + return view_configuration() + _config_int("config_restricted_column") + _config_int("config_theme") _config_int("config_random_books") _config_int("config_books_per_page") _config_int("config_authors_max") - _config_int("config_restricted_column") + config.config_default_role = constants.selected_roles(to_save) config.config_default_role &= ~constants.ROLE_ANONYMOUS @@ -723,10 +749,10 @@ def add_restriction(res_type, user_id): usr = current_user if 'submit_allow' in element: usr.allowed_tags = restriction_addition(element, usr.list_allowed_tags) - ub.session_commit("Changed allowed tags of user {} to {}".format(usr.name, usr.list_allowed_tags)) + ub.session_commit("Changed allowed tags of user {} to {}".format(usr.name, usr.list_allowed_tags())) elif 'submit_deny' in element: usr.denied_tags = restriction_addition(element, usr.list_denied_tags) - ub.session_commit("Changed denied tags of user {} to {}".format(usr.name, usr.list_denied_tags)) + ub.session_commit("Changed denied tags of user {} to {}".format(usr.name, usr.list_denied_tags())) if res_type == 3: # CustomC per user if isinstance(user_id, int): usr = ub.session.query(ub.User).filter(ub.User.id == int(user_id)).first() @@ -735,11 +761,11 @@ def add_restriction(res_type, user_id): if 'submit_allow' in element: usr.allowed_column_value = restriction_addition(element, usr.list_allowed_column_values) ub.session_commit("Changed allowed columns of user {} to {}".format(usr.name, - usr.list_allowed_column_values)) + usr.list_allowed_column_values())) elif 'submit_deny' in element: usr.denied_column_value = restriction_addition(element, usr.list_denied_column_values) ub.session_commit("Changed denied columns of user {} to {}".format(usr.name, - usr.list_denied_column_values)) + usr.list_denied_column_values())) return "" diff --git a/cps/db.py b/cps/db.py index 39adcd4b..66c289dd 100644 --- a/cps/db.py +++ b/cps/db.py @@ -44,6 +44,7 @@ from flask_login import current_user from babel import Locale as LC from babel.core import UnknownLocaleError from flask_babel import gettext as _ +from flask import flash from . import logger, ub, isoLanguages from .pagination import Pagination @@ -122,7 +123,7 @@ class Identifiers(Base): elif format_type == "goodreads": return u"Goodreads" elif format_type == "babelio": - return u"Babelio" + return u"Babelio" elif format_type == "google": return u"Google Books" elif format_type == "kobo": @@ -151,7 +152,7 @@ class Identifiers(Base): elif format_type == "goodreads": return u"https://www.goodreads.com/book/show/{0}".format(self.val) elif format_type == "babelio": - return u"https://www.babelio.com/livres/titre/{0}".format(self.val) + return u"https://www.babelio.com/livres/titre/{0}".format(self.val) elif format_type == "douban": return u"https://book.douban.com/subject/{0}".format(self.val) elif format_type == "google": @@ -606,14 +607,24 @@ class CalibreDB(): neg_content_tags_filter = false() if negtags_list == [''] else Books.tags.any(Tags.name.in_(negtags_list)) pos_content_tags_filter = true() if postags_list == [''] else Books.tags.any(Tags.name.in_(postags_list)) if self.config.config_restricted_column: - pos_cc_list = current_user.allowed_column_value.split(',') - pos_content_cc_filter = true() if pos_cc_list == [''] else \ - getattr(Books, 'custom_column_' + str(self.config.config_restricted_column)). \ - any(cc_classes[self.config.config_restricted_column].value.in_(pos_cc_list)) - neg_cc_list = current_user.denied_column_value.split(',') - neg_content_cc_filter = false() if neg_cc_list == [''] else \ - getattr(Books, 'custom_column_' + str(self.config.config_restricted_column)). \ - any(cc_classes[self.config.config_restricted_column].value.in_(neg_cc_list)) + try: + pos_cc_list = current_user.allowed_column_value.split(',') + pos_content_cc_filter = true() if pos_cc_list == [''] else \ + getattr(Books, 'custom_column_' + str(self.config.config_restricted_column)). \ + any(cc_classes[self.config.config_restricted_column].value.in_(pos_cc_list)) + neg_cc_list = current_user.denied_column_value.split(',') + neg_content_cc_filter = false() if neg_cc_list == [''] else \ + getattr(Books, 'custom_column_' + str(self.config.config_restricted_column)). \ + any(cc_classes[self.config.config_restricted_column].value.in_(neg_cc_list)) + except (KeyError, AttributeError): + pos_content_cc_filter = false() + neg_content_cc_filter = true() + log.error(u"Custom Column No.%d is not existing in calibre database", + self.config.config_restricted_column) + flash(_("Custom Column No.%(column)d is not existing in calibre database", + column=self.config.config_restricted_column), + category="error") + else: pos_content_cc_filter = true() neg_content_cc_filter = false() diff --git a/cps/static/js/details.js b/cps/static/js/details.js index 395518cb..81c1a395 100644 --- a/cps/static/js/details.js +++ b/cps/static/js/details.js @@ -22,7 +22,21 @@ $(function() { }); $("#have_read_cb").on("change", function() { - $(this).closest("form").submit(); + $.post({ + url: this.closest("form").action, + error: function(response) { + var data = [{type:"danger", message:response.responseText}] + $("#flash_success").remove(); + $("#flash_danger").remove(); + if (!jQuery.isEmptyObject(data)) { + data.forEach(function (item) { + $(".navbar").after('