From 42707a19bd62fddb6b7097c45166b3cf09d7696b Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 14 Mar 2021 16:57:33 +0100 Subject: [PATCH 1/4] Code cosmetics --- cps/static/css/listen.css | 13 +- cps/static/css/main.css | 358 ++++++++++++++++++----------------- cps/static/css/style.css | 84 ++++---- cps/static/js/edit_books.js | 2 +- cps/static/js/filter_grid.js | 8 +- cps/static/js/main.js | 2 +- 6 files changed, 230 insertions(+), 237 deletions(-) diff --git a/cps/static/css/listen.css b/cps/static/css/listen.css index a69af72e..9e1d3bb4 100644 --- a/cps/static/css/listen.css +++ b/cps/static/css/listen.css @@ -66,19 +66,12 @@ body { right: 40px; } -xmp, -pre, -plaintext { - display: block; - font-family: -moz-fixed; - white-space: pre; - margin: 1em 0; -} - pre { + display: block; + margin: 1em 0; white-space: pre-wrap; word-wrap: break-word; - font-family: -moz-fixed; + font-family: -moz-fixed, sans-serif; column-count: 2; -webkit-columns: 2; -moz-columns: 2; diff --git a/cps/static/css/main.css b/cps/static/css/main.css index 94b04ce0..e97497de 100644 --- a/cps/static/css/main.css +++ b/cps/static/css/main.css @@ -72,6 +72,16 @@ body { padding: 3px; } +#panels a { + visibility: hidden; + width: 18px; + height: 20px; + overflow: hidden; + display: inline-block; + color: #ccc; + margin-left: 6px; +} + #titlebar a:active { opacity: 1; color: rgba(0, 0, 0, 0.6); @@ -189,19 +199,24 @@ body { #title-controls { float: right; } -#panels a { - visibility: hidden; - width: 18px; - height: 20px; - overflow: hidden; - display: inline-block; - color: #ccc; - margin-left: 6px; -} - #panels a::before { visibility: visible; } #panels a:hover { color: #aaa; } +.list_item.currentChapter > a, +.list_item a:hover { + color: #f1f1f1; +} + +.list_item a { + color: #aaa; + text-decoration: none; +} + +#searchResults a { + color: #aaa; + text-decoration: none; +} + #panels a:active { color: #aaa; margin: 1px 0 -1px 6px; @@ -274,6 +289,17 @@ input:-moz-placeholder { color: #454545; } display: block; } +.list_item ul { + padding-left: 10px; + margin-top: 8px; + display: none; +} + +.list_item.currentChapter > ul, +.list_item.openChapter > ul { + display: block; +} + #tocView > ul, #bookmarksView > ul { margin-top: 15px; @@ -291,14 +317,34 @@ input:-moz-placeholder { color: #454545; } text-transform: capitalize; } -#tocView li:active, -#tocView li.currentChapter { +.md-content > div ul li { + padding: 5px 0; +} + +#settingsPanel li { + font-size: 1em; + color: #f1f1f1; +} + +#searchResults li { + margin-bottom: 10px; + width: 225px; + font-family: Georgia, "Times New Roman", Times, serif; list-style: none; } -.list_item a { - color: #aaa; - text-decoration: none; +#notes li { + color: #eee; + font-size: 12px; + width: 240px; + border-top: 1px #fff solid; + padding-top: 6px; + margin-bottom: 6px; +} + +#tocView li:active, +#tocView li.currentChapter { + list-style: none; } .list_item a.chapter { @@ -309,27 +355,11 @@ input:-moz-placeholder { color: #454545; } font-size: 0.8em; } -.list_item.currentChapter > a, -.list_item a:hover { - color: #f1f1f1; -} - /* #tocView li.openChapter > a, */ .list_item a:hover { color: #e2e2e2; } -.list_item ul { - padding-left: 10px; - margin-top: 8px; - display: none; -} - -.list_item.currentChapter > ul, -.list_item.openChapter > ul { - display: block; -} - #tocView.hidden { display: none; } @@ -344,14 +374,14 @@ input:-moz-placeholder { color: #454545; } user-select: none; } -.toc_toggle:before { +.toc_toggle::before { content: '▸'; color: #fff; margin-right: -4px; } -.currentChapter > .toc_toggle:before, -.openChapter > .toc_toggle:before { +.currentChapter > .toc_toggle::before, +.openChapter > .toc_toggle::before { content: '▾'; } @@ -369,18 +399,6 @@ input:-moz-placeholder { color: #454545; } display: block; } -#searchResults li { - margin-bottom: 10px; - width: 225px; - font-family: Georgia, "Times New Roman", Times, serif; - list-style: none; -} - -#searchResults a { - color: #aaa; - text-decoration: none; -} - #searchResults p { text-decoration: none; font-size: 12px; @@ -392,10 +410,21 @@ input:-moz-placeholder { color: #454545; } color: #000; } +.md-content > div p { + margin: 0; + padding: 10px 0; +} + #searchResults li > p { color: #aaa; } +#notes li a { + color: #fff; + display: inline-block; + margin-left: 6px; +} + #searchResults li a:hover { color: #e2e2e2; } @@ -409,21 +438,6 @@ input:-moz-placeholder { color: #454545; } padding: 0 0 0 34px; } -#notes li { - color: #eee; - font-size: 12px; - width: 240px; - border-top: 1px #fff solid; - padding-top: 6px; - margin-bottom: 6px; -} - -#notes li a { - color: #fff; - display: inline-block; - margin-left: 6px; -} - #notes li a:hover { text-decoration: underline; } @@ -442,7 +456,7 @@ input:-moz-placeholder { color: #454545; } } #note-text[disabled], -#note-text[disabled="disabled"]{ +#note-text[disabled="disabled"] { opacity: 0.5; } @@ -455,6 +469,22 @@ input:-moz-placeholder { color: #454545; } display: none; } +.md-content h3 { + margin: 0; + padding: 6px; + text-align: center; + font-size: 22px; + font-weight: 300; + opacity: 0.8; + background: rgba(0, 0, 0, 0.1); + border-radius: 3px 3px 0 0; +} + +.md-content > div ul { + margin: 0; + padding: 0 0 30px 20px; +} + #settingsPanel h3 { color: #f1f1f1; font-family: Georgia, "Times New Roman", Times, serif; @@ -466,11 +496,6 @@ input:-moz-placeholder { color: #454545; } list-style-type: none; } -#settingsPanel li { - font-size: 1em; - color: #f1f1f1; -} - #settingsPanel .xsmall { font-size: x-small; } #settingsPanel .small { font-size: small; } #settingsPanel .medium { font-size: medium; } @@ -525,17 +550,6 @@ input:-moz-placeholder { color: #454545; } height: 320px; } -.md-content h3 { - margin: 0; - padding: 6px; - text-align: center; - font-size: 22px; - font-weight: 300; - opacity: 0.8; - background: rgba(0, 0, 0, 0.1); - border-radius: 3px 3px 0 0; -} - .md-content > div { padding: 15px 40px 30px; margin: 0; @@ -543,20 +557,6 @@ input:-moz-placeholder { color: #454545; } font-size: 14px; } -.md-content > div p { - margin: 0; - padding: 10px 0; -} - -.md-content > div ul { - margin: 0; - padding: 0 0 30px 20px; -} - -.md-content > div ul li { - padding: 5px 0; -} - .md-content button { display: block; margin: 0 auto; @@ -619,7 +619,7 @@ input:-moz-placeholder { color: #454545; } } @media only screen and (max-width: 550px) { - #viewer{ + #viewer { width: 80%; margin-left: 10%; } @@ -654,11 +654,6 @@ input:-moz-placeholder { color: #454545; } -ms-transform: translate(260px, 0); } - #titlebar { - /* font-size: 16px; */ - /* margin: 0 50px 0 50px; */ - } - #metainfo { font-size: 10px; } @@ -678,115 +673,122 @@ input:-moz-placeholder { color: #454545; } /* For iPad portrait layouts only */ @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation: portrait) { - #viewer iframe { - width: 460px; - height: 740px; - } + #viewer iframe { + width: 460px; + height: 740px; + } } @media only screen -and (min-device-width : 768px) -and (max-device-width : 1024px) -and (orientation : landscape) -/*and (-webkit-min-device-pixel-ratio: 2)*/ { + and (min-device-width: 768px) + and (max-device-width: 1024px) + and (orientation: landscape) + /* and (-webkit-min-device-pixel-ratio: 2)*/ { #viewer { width: 80%; margin-left: 10%; } + #divider, #divider.show { display: none; } } - /*For iPad landscape layouts only */ +/* For iPad landscape layouts only */ @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation: landscape) { - #viewer iframe { - width: 960px; - height: 515px; - } + #viewer iframe { + width: 960px; + height: 515px; + } } /* For iPhone 6\6s portrait layouts only */ -@media only screen and (min-device-width : 375px) and (max-device-width : 667px) and (orientation: portrait) { - #viewer { - width: 300px; - height: 480px; - } - #viewer iframe { - width: 300px; - height: 480px; - } +@media only screen and (min-device-width: 375px) and (max-device-width: 667px) and (orientation: portrait) { + #viewer { + width: 300px; + height: 480px; + } + + #viewer iframe { + width: 300px; + height: 480px; + } } /* For iPhone 6\6s landscape layouts only */ -@media only screen and (min-device-width : 375px) and (max-device-width : 667px) and (orientation: landscape) { - #viewer { - width: 450px; - height: 300px; - } - #viewer iframe { - width: 450px; - height: 300px; - } +@media only screen and (min-device-width: 375px) and (max-device-width: 667px) and (orientation: landscape) { + #viewer { + width: 450px; + height: 300px; + } + + #viewer iframe { + width: 450px; + height: 300px; + } } /* For iPhone portrait layouts only */ @media only screen and (max-device-width: 374px) and (orientation: portrait) { - #viewer { - width: 256px; - height: 432px; - } - #viewer iframe { - width: 256px; - height: 432px; - } + #viewer { + width: 256px; + height: 432px; + } + + #viewer iframe { + width: 256px; + height: 432px; + } } /* For iPhone landscape layouts only */ @media only screen and (max-device-width: 374px) and (orientation: landscape) { - #viewer iframe { - width: 256px; - height: 124px; - } + #viewer iframe { + width: 256px; + height: 124px; + } } -[class^="icon-"]:before, [class*=" icon-"]:before { - font-family: "fontello", serif; - font-style: normal; - font-weight: normal; - speak: none; - display: inline-block; - text-decoration: inherit; - width: 1em; - margin-right: 0.2em; - text-align: center; - /* For safety - reset parent styles, that can break glyph codes*/ - font-variant: normal; - text-transform: none; - /* you can be more comfortable with increased icons size */ - font-size: 112%; +[class^="icon-"]::before, +[class*=" icon-"]::before { + font-family: "fontello", serif; + font-style: normal; + font-weight: normal; + speak: none; + display: inline-block; + text-decoration: inherit; + width: 1em; + margin-right: 0.2em; + text-align: center; + + /* For safety - reset parent styles, that can break glyph codes */ + font-variant: normal; + text-transform: none; + + /* you can be more comfortable with increased icons size */ + font-size: 112%; } -.icon-search:before { content: '\e807'; } /* '' */ -.icon-resize-full-1:before { content: '\e804'; } /* '' */ -.icon-cancel-circled2:before { content: '\e80f'; } /* '' */ -.icon-link:before { content: '\e80d'; } /* '' */ -.icon-bookmark:before { content: '\e805'; } /* '' */ -.icon-bookmark-empty:before { content: '\e806'; } /* '' */ -.icon-download-cloud:before { content: '\e811'; } /* '' */ -.icon-edit:before { content: '\e814'; } /* '' */ -.icon-menu:before { content: '\e802'; } /* '' */ -.icon-cog:before { content: '\e813'; } /* '' */ -.icon-resize-full:before { content: '\e812'; } /* '' */ -.icon-cancel-circled:before { content: '\e80e'; } /* '' */ -.icon-up-dir:before { content: '\e80c'; } /* '' */ -.icon-right-dir:before { content: '\e80b'; } /* '' */ -.icon-angle-right:before { content: '\e809'; } /* '' */ -.icon-angle-down:before { content: '\e80a'; } /* '' */ -.icon-right:before { content: '\e815'; } /* '' */ -.icon-list-1:before { content: '\e803'; } /* '' */ -.icon-list-numbered:before { content: '\e801'; } /* '' */ -.icon-columns:before { content: '\e810'; } /* '' */ -.icon-list:before { content: '\e800'; } /* '' */ -.icon-resize-small:before { content: '\e808'; } /* '' */ +.icon-search::before { content: '\e807'; } /* '' */ +.icon-resize-full-1::before { content: '\e804'; } /* '' */ +.icon-cancel-circled2::before { content: '\e80f'; } /* '' */ +.icon-link::before { content: '\e80d'; } /* '' */ +.icon-bookmark::before { content: '\e805'; } /* '' */ +.icon-bookmark-empty::before { content: '\e806'; } /* '' */ +.icon-download-cloud::before { content: '\e811'; } /* '' */ +.icon-edit::before { content: '\e814'; } /* '' */ +.icon-menu::before { content: '\e802'; } /* '' */ +.icon-cog::before { content: '\e813'; } /* '' */ +.icon-resize-full::before { content: '\e812'; } /* '' */ +.icon-cancel-circled::before { content: '\e80e'; } /* '' */ +.icon-up-dir::before { content: '\e80c'; } /* '' */ +.icon-right-dir::before { content: '\e80b'; } /* '' */ +.icon-angle-right::before { content: '\e809'; } /* '' */ +.icon-angle-down::before { content: '\e80a'; } /* '' */ +.icon-right::before { content: '\e815'; } /* '' */ +.icon-list-1::before { content: '\e803'; } /* '' */ +.icon-list-numbered::before { content: '\e801'; } /* '' */ +.icon-columns::before { content: '\e810'; } /* '' */ +.icon-list::before { content: '\e800'; } /* '' */ +.icon-resize-small::before { content: '\e808'; } /* '' */ diff --git a/cps/static/css/style.css b/cps/static/css/style.css index 8f54beff..02658771 100644 --- a/cps/static/css/style.css +++ b/cps/static/css/style.css @@ -28,6 +28,11 @@ html.http-error { height: 100%; } +body { + background: #f2f2f2; + margin-bottom: 40px; +} + .http-error body { margin: 0; height: 100%; @@ -41,11 +46,6 @@ html.http-error { text-align: center; } -body { - background: #f2f2f2; - margin-bottom: 40px; -} - body h2 { font-weight: normal; color: #444; @@ -56,10 +56,16 @@ a, .book-remove, .editable-empty, .editable-empty:hover { color: #45b29d; } - -.book-remove:hover { color: #23527c; } - +.user-remove:hover { color: #23527c; } .btn-default a { color: #444; } +.panel-title > a { text-decoration: none; } + +.navigation li a { + color: #444; + text-decoration: none; + display: block; + padding: 10px; +} .btn-default a:hover { color: #45b29d; @@ -85,11 +91,17 @@ a.editable-click:hover { border-bottom: None; } padding-top: 20px; } -.navigation li a { - color: #444; +.book-meta .tags a { display: inline; } +table .bg-primary a { color: #fff; } +table .bg-dark-danger a { color: #fff; } +.book-meta .identifiers a { display: inline; } + +.navigation .create-shelf a { + color: #fff; + background: #45b29d; + padding: 10px 20px; + border-radius: 5px; text-decoration: none; - display: block; - padding: 10px; } .navigation li a:hover { @@ -105,14 +117,6 @@ a.editable-click:hover { border-bottom: None; } text-align: center; } -.navigation .create-shelf a { - color: #fff; - background: #45b29d; - padding: 10px 20px; - border-radius: 5px; - text-decoration: none; -} - .row.display-flex { display: flex; flex-wrap: wrap; @@ -134,17 +138,32 @@ a.editable-click:hover { border-bottom: None; } display: flex; flex-direction: column; } +.cover { margin-bottom: 10px; } .container-fluid .book .cover { height: 225px; position: relative; } +.author-link img { + display: block; + height: 100%; +} + .container-fluid .book .cover span.img { bottom: 0; height: 100%; position: absolute; } +.author-bio img { margin: 0 1em 1em 0; } + +.container-fluid .single .cover img { + border: 1px solid #fff; + box-sizing: border-box; + -webkit-box-shadow: 0 5px 8px -6px #777; + -moz-box-shadow: 0 5px 8px -6px #777; + box-shadow: 0 5px 8px -6px #777; +} .container-fluid .book .cover span img { position: relative; @@ -159,6 +178,7 @@ a.editable-click:hover { border-bottom: None; } } .container-fluid .book .meta { margin-top: 10px; } +.media-body p { text-align: justify; } .container-fluid .book .meta p { margin: 0; } .container-fluid .book .meta .title { @@ -208,20 +228,9 @@ span.glyphicon.glyphicon-tags { } .book-meta { padding-bottom: 20px; } -.book-meta .tags a { display: inline; } -.book-meta .identifiers a { display: inline; } - -.container-fluid .single .cover img { - border: 1px solid #fff; - box-sizing: border-box; - -webkit-box-shadow: 0 5px 8px -6px #777; - -moz-box-shadow: 0 5px 8px -6px #777; - box-shadow: 0 5px 8px -6px #777; -} .navbar-default .navbar-toggle .icon-bar { background-color: #000; } .navbar-default .navbar-toggle { border-color: #000; } -.cover { margin-bottom: 10px; } .cover .badge { position: absolute; @@ -308,10 +317,8 @@ table .bg-dark-danger { background-color: #d9534f; color: #fff; } -table .bg-dark-danger a { color: #fff; } table .bg-dark-danger:hover { background-color: #c9302c; } table .bg-primary:hover { background-color: #1c5484; } -table .bg-primary a { color: #fff; } .block-label { display: block; } .fake-input { @@ -345,19 +352,12 @@ input.pill:checked + label { input.pill:not(:checked) + label .glyphicon { display: none; } -.author-bio img { margin: 0 1em 1em 0; } - .author-link { display: inline-block; margin-top: 10px; width: 100px; } -.author-link img { - display: block; - height: 100%; -} - #remove-from-shelves .btn, #shelf-action-errors { margin-left: 5px; } @@ -371,7 +371,6 @@ input.pill:not(:checked) + label .glyphicon { display: none; } } .media-list { padding-right: 15px; } -.media-body p { text-align: justify; } #meta-info img { max-height: 150px; @@ -384,7 +383,7 @@ input.pill:not(:checked) + label .glyphicon { display: none; } #btn-upload-format { display: none; } .upload-cover-input-text { display: initial; } #btn-upload-cover { display: none; } -.panel-title > a { text-decoration: none; } + .editable-buttons { display: inline-block; margin-left: 7px; @@ -417,4 +416,3 @@ div.log { white-space: nowrap; padding: 0.5em; } - diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index 8f683be4..8cedf688 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -265,7 +265,7 @@ $("#search").on("change input.typeahead:selected", function(event) { } }); $("#include_tag option:selected").each(function () { - $("#exclude_tag").find("[value="+$(this).val() + "]").prop("disabled", true); + $("#exclude_tag").find("[value=" + $(this).val() + "]").prop("disabled", true); }); $("#include_tag").selectpicker("refresh"); $("#exclude_tag").selectpicker("refresh"); diff --git a/cps/static/js/filter_grid.js b/cps/static/js/filter_grid.js index f5ccd3de..d57d155f 100644 --- a/cps/static/js/filter_grid.js +++ b/cps/static/js/filter_grid.js @@ -56,15 +56,15 @@ $("#asc").click(function() { $("#all").click(function() { // go through all elements and make them visible $list.isotope({ filter: function() { - return true; - } + return true; + } }); }); $(".char").click(function() { var character = this.innerText; $list.isotope({ filter: function() { - return this.attributes["data-id"].value.charAt(0).toUpperCase() == character; - } + return this.attributes["data-id"].value.charAt(0).toUpperCase() === character; + } }); }); diff --git a/cps/static/js/main.js b/cps/static/js/main.js index dd2efe52..fea85990 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -55,7 +55,7 @@ $(document).on("change", "select[data-control]", function() { $(document).on("change", "select[data-controlall]", function() { var $this = $(this); var name = $this.data("controlall"); - var showOrHide = parseInt($this.val()); + var showOrHide = parseInt($this.val(), 10); if (showOrHide) { $("[data-related=" + name + "]").show(); } else { From 53ee0aaee1aafa3f0eda8288e9fe2ec2c6058da9 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 14 Mar 2021 17:34:47 +0100 Subject: [PATCH 2/4] Some functions refactored --- cps/admin.py | 206 +++++++++++++++++++++++++++++---------------------- 1 file changed, 119 insertions(+), 87 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 767aece3..b932bd8e 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -61,6 +61,7 @@ feature_support = { } try: + # pylint: disable=unused-import import rarfile feature_support['rar'] = True except (ImportError, SyntaxError): @@ -184,10 +185,10 @@ def admin(): else: commit = version['version'] - allUser = ub.session.query(ub.User).all() + all_user = ub.session.query(ub.User).all() email_settings = config.get_mail_settings() kobo_support = feature_support['kobo'] and config.config_kobo_sync - return render_title_template("admin.html", allUser=allUser, email=email_settings, config=config, commit=commit, + return render_title_template("admin.html", allUser=all_user, email=email_settings, config=config, commit=commit, feature_support=feature_support, kobo_support=kobo_support, title=_(u"Admin page"), page="admin") @@ -729,35 +730,13 @@ def _configuration_logfile_helper(to_save, gdrive_error): return reboot_required, None -def _configuration_ldap_helper(to_save, gdrive_error): - reboot_required = False - reboot_required |= _config_string(to_save, "config_ldap_provider_url") - reboot_required |= _config_int(to_save, "config_ldap_port") - reboot_required |= _config_int(to_save, "config_ldap_authentication") - reboot_required |= _config_string(to_save, "config_ldap_dn") - reboot_required |= _config_string(to_save, "config_ldap_serv_username") - reboot_required |= _config_string(to_save, "config_ldap_user_object") - reboot_required |= _config_string(to_save, "config_ldap_group_object_filter") - reboot_required |= _config_string(to_save, "config_ldap_group_members_field") - reboot_required |= _config_string(to_save, "config_ldap_member_user_object") - reboot_required |= _config_checkbox(to_save, "config_ldap_openldap") - reboot_required |= _config_int(to_save, "config_ldap_encryption") - reboot_required |= _config_string(to_save, "config_ldap_cacert_path") - reboot_required |= _config_string(to_save, "config_ldap_cert_path") - reboot_required |= _config_string(to_save, "config_ldap_key_path") - _config_string(to_save, "config_ldap_group_name") - if "config_ldap_serv_password" in to_save and to_save["config_ldap_serv_password"] != "": - reboot_required |= 1 - config.set_from_dictionary(to_save, "config_ldap_serv_password", base64.b64encode, encode='UTF-8') - config.save() - +def _configuration_ldap_check(reboot_required, to_save, gdrive_error): if not config.config_ldap_provider_url \ - or not config.config_ldap_port \ - or not config.config_ldap_dn \ - or not config.config_ldap_user_object: + or not config.config_ldap_port \ + or not config.config_ldap_dn \ + or not config.config_ldap_user_object: return reboot_required, _configuration_result(_('Please Enter a LDAP Provider, ' 'Port, DN and User Object Identifier'), gdrive_error) - if config.config_ldap_authentication > constants.LDAP_AUTH_ANONYMOUS: if config.config_ldap_authentication > constants.LDAP_AUTH_UNAUTHENTICATE: if not config.config_ldap_serv_username or not bool(config.config_ldap_serv_password): @@ -767,6 +746,14 @@ def _configuration_ldap_helper(to_save, gdrive_error): if not config.config_ldap_serv_username: return reboot_required, _configuration_result('Please Enter a LDAP Service Account', gdrive_error) + if config.config_ldap_group_object_filter: + if config.config_ldap_group_object_filter.count("%s") != 1: + return reboot_required, \ + _configuration_result(_('LDAP Group Object Filter Needs to Have One "%s" Format Identifier'), + gdrive_error) + if config.config_ldap_group_object_filter.count("(") != config.config_ldap_group_object_filter.count(")"): + return reboot_required, _configuration_result(_('LDAP Group Object Filter Has Unmatched Parenthesis'), + gdrive_error) if config.config_ldap_group_object_filter: if config.config_ldap_group_object_filter.count("%s") != 1: return reboot_required, \ @@ -806,6 +793,31 @@ def _configuration_ldap_helper(to_save, gdrive_error): return reboot_required, None +def _configuration_ldap_helper(to_save, gdrive_error): + reboot_required = False + reboot_required |= _config_string(to_save, "config_ldap_provider_url") + reboot_required |= _config_int(to_save, "config_ldap_port") + reboot_required |= _config_int(to_save, "config_ldap_authentication") + reboot_required |= _config_string(to_save, "config_ldap_dn") + reboot_required |= _config_string(to_save, "config_ldap_serv_username") + reboot_required |= _config_string(to_save, "config_ldap_user_object") + reboot_required |= _config_string(to_save, "config_ldap_group_object_filter") + reboot_required |= _config_string(to_save, "config_ldap_group_members_field") + reboot_required |= _config_string(to_save, "config_ldap_member_user_object") + reboot_required |= _config_checkbox(to_save, "config_ldap_openldap") + reboot_required |= _config_int(to_save, "config_ldap_encryption") + reboot_required |= _config_string(to_save, "config_ldap_cacert_path") + reboot_required |= _config_string(to_save, "config_ldap_cert_path") + reboot_required |= _config_string(to_save, "config_ldap_key_path") + _config_string(to_save, "config_ldap_group_name") + if "config_ldap_serv_password" in to_save and to_save["config_ldap_serv_password"] != "": + reboot_required |= 1 + config.set_from_dictionary(to_save, "config_ldap_serv_password", base64.b64encode, encode='UTF-8') + config.save() + + return _configuration_ldap_check(reboot_required, to_save, gdrive_error) + + def _configuration_update_helper(configured): reboot_required = False db_change = False @@ -1011,18 +1023,33 @@ def _handle_new_user(to_save, content, languages, translations, kobo_support): ub.session.rollback() flash(_(u"Settings DB is not Writeable"), category="error") +def delete_user(content): + if ub.session.query(ub.User).filter(ub.User.role.op('&')(constants.ROLE_ADMIN) == constants.ROLE_ADMIN, + ub.User.id != content.id).count(): + ub.session.query(ub.User).filter(ub.User.id == content.id).delete() + ub.session_commit() + flash(_(u"User '%(nick)s' deleted", nick=content.nickname), category="success") + return redirect(url_for('admin.admin')) + else: + flash(_(u"No admin user remaining, can't delete user", nick=content.nickname), category="error") + return redirect(url_for('admin.admin')) + + +def save_edited_user(content): + try: + ub.session_commit() + flash(_(u"User '%(nick)s' updated", nick=content.nickname), category="success") + except IntegrityError: + ub.session.rollback() + flash(_(u"An unknown error occured."), category="error") + except OperationalError: + ub.session.rollback() + flash(_(u"Settings DB is not Writeable"), category="error") + def _handle_edit_user(to_save, content, languages, translations, kobo_support): if "delete" in to_save: - if ub.session.query(ub.User).filter(ub.User.role.op('&')(constants.ROLE_ADMIN) == constants.ROLE_ADMIN, - ub.User.id != content.id).count(): - ub.session.query(ub.User).filter(ub.User.id == content.id).delete() - ub.session_commit() - flash(_(u"User '%(nick)s' deleted", nick=content.nickname), category="success") - return redirect(url_for('admin.admin')) - else: - flash(_(u"No admin user remaining, can't delete user", nick=content.nickname), category="error") - return redirect(url_for('admin.admin')) + return delete_user(content) else: if not ub.session.query(ub.User).filter(ub.User.role.op('&')(constants.ROLE_ADMIN) == constants.ROLE_ADMIN, ub.User.id != content.id).count() and 'admin_role' not in to_save: @@ -1090,15 +1117,7 @@ def _handle_edit_user(to_save, content, languages, translations, kobo_support): if "kindle_mail" in to_save and to_save["kindle_mail"] != content.kindle_mail: content.kindle_mail = to_save["kindle_mail"] - try: - ub.session_commit() - flash(_(u"User '%(nick)s' updated", nick=content.nickname), category="success") - except IntegrityError: - ub.session.rollback() - flash(_(u"An unknown error occured."), category="error") - except OperationalError: - ub.session.rollback() - flash(_(u"Settings DB is not Writeable"), category="error") + return save_edited_user(content) @admi.route("/admin/user/new", methods=["GET", "POST"]) @@ -1310,6 +1329,55 @@ def get_updater_status(): return '' +def create_ldap_user(user, user_data, config): + imported = 0 + showtext = None + + user_login_field = extract_dynamic_field_from_filter(user, config.config_ldap_user_object) + + username = user_data[user_login_field][0].decode('utf-8') + # check for duplicate username + if ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == username.lower()).first(): + # if ub.session.query(ub.User).filter(ub.User.nickname == username).first(): + log.warning("LDAP User %s Already in Database", user_data) + return imported, showtext + + kindlemail = '' + if 'mail' in user_data: + useremail = user_data['mail'][0].decode('utf-8') + if len(user_data['mail']) > 1: + kindlemail = user_data['mail'][1].decode('utf-8') + + else: + log.debug('No Mail Field Found in LDAP Response') + useremail = username + '@email.com' + # check for duplicate email + if ub.session.query(ub.User).filter(func.lower(ub.User.email) == useremail.lower()).first(): + log.warning("LDAP Email %s Already in Database", user_data) + return imported, showtext + + content = ub.User() + content.nickname = username + content.password = '' # dummy password which will be replaced by ldap one + content.email = useremail + content.kindle_mail = kindlemail + content.role = config.config_default_role + content.sidebar_view = config.config_default_show + content.allowed_tags = config.config_allowed_tags + content.denied_tags = config.config_denied_tags + content.allowed_column_value = config.config_allowed_column_value + content.denied_column_value = config.config_denied_column_value + ub.session.add(content) + try: + ub.session.commit() + imported = 1 + except Exception as e: + log.warning("Failed to create LDAP user: %s - %s", user, e) + ub.session.rollback() + showtext = _(u'Failed to Create at Least One LDAP User') + return imported, showtext + + @admi.route('/import_ldap_users') @login_required @admin_required @@ -1349,47 +1417,11 @@ def import_ldap_users(): log.debug_or_exception(e) continue if user_data: - user_login_field = extract_dynamic_field_from_filter(user, config.config_ldap_user_object) - - username = user_data[user_login_field][0].decode('utf-8') - # check for duplicate username - if ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == username.lower()).first(): - # if ub.session.query(ub.User).filter(ub.User.nickname == username).first(): - log.warning("LDAP User %s Already in Database", user_data) - continue - - kindlemail = '' - if 'mail' in user_data: - useremail = user_data['mail'][0].decode('utf-8') - if len(user_data['mail']) > 1: - kindlemail = user_data['mail'][1].decode('utf-8') - - else: - log.debug('No Mail Field Found in LDAP Response') - useremail = username + '@email.com' - # check for duplicate email - if ub.session.query(ub.User).filter(func.lower(ub.User.email) == useremail.lower()).first(): - log.warning("LDAP Email %s Already in Database", user_data) - continue - content = ub.User() - content.nickname = username - content.password = '' # dummy password which will be replaced by ldap one - content.email = useremail - content.kindle_mail = kindlemail - content.role = config.config_default_role - content.sidebar_view = config.config_default_show - content.allowed_tags = config.config_allowed_tags - content.denied_tags = config.config_denied_tags - content.allowed_column_value = config.config_allowed_column_value - content.denied_column_value = config.config_denied_column_value - ub.session.add(content) - try: - ub.session.commit() - imported += 1 - except Exception as e: - log.warning("Failed to create LDAP user: %s - %s", user, e) - ub.session.rollback() - showtext['text'] = _(u'Failed to Create at Least One LDAP User') + success, txt = create_ldap_user(user, user_data, config) + # In case of error store text for showing it + if txt: + showtext['text'] = txt + imported += success else: log.warning("LDAP User: %s Not Found", user) showtext['text'] = _(u'At Least One LDAP User Not Found in Database') From d42bf44fad5c9636dc93c99a32073d0f11fa0074 Mon Sep 17 00:00:00 2001 From: Northguy <1189058+Northguy@users.noreply.github.com> Date: Sun, 14 Mar 2021 23:46:33 +0100 Subject: [PATCH 3/4] Added same color for series name and series number --- cps/static/css/caliBlur.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cps/static/css/caliBlur.css b/cps/static/css/caliBlur.css index ffa5ecca..165cc328 100644 --- a/cps/static/css/caliBlur.css +++ b/cps/static/css/caliBlur.css @@ -1783,6 +1783,12 @@ body > div.container-fluid > div > div.col-sm-10 > div.discover { margin-top: 0 } +.container-fluid .book .meta .series { + /* font-weight: 400; */ + /* font-size: 12px; */ + color: #ffffff73; +} + .container-fluid .book .meta > p { -o-text-overflow: ellipsis; text-overflow: ellipsis; From bfe36d3f4ac854dd11f57d870940093858608d01 Mon Sep 17 00:00:00 2001 From: Northguy <1189058+Northguy@users.noreply.github.com> Date: Mon, 15 Mar 2021 00:12:02 +0100 Subject: [PATCH 4/4] change in color definition Making color the same as in: .container-fluid .book .meta .author, .container-fluid .book .meta .author > a { color: hsla(0, 0%, 100%, .45) } --- cps/static/css/caliBlur.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/static/css/caliBlur.css b/cps/static/css/caliBlur.css index 165cc328..14e5c286 100644 --- a/cps/static/css/caliBlur.css +++ b/cps/static/css/caliBlur.css @@ -1786,7 +1786,7 @@ body > div.container-fluid > div > div.col-sm-10 > div.discover { .container-fluid .book .meta .series { /* font-weight: 400; */ /* font-size: 12px; */ - color: #ffffff73; + color: hsla(0, 0%, 100%, .45); } .container-fluid .book .meta > p {