From 8143c16c14e835820d39a16ff3c1462469f0a0bf Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sat, 11 Jan 2020 11:42:30 +0100 Subject: [PATCH] Added texts for allowed denied tags in configuration Removed domain only restriction (now it's also possible to allow/deny name parts of users email) Fix no. of displayed books in unread books section, with applied restrictions --- cps/admin.py | 16 ++++++++-------- cps/cli.py | 2 +- cps/helper.py | 2 +- cps/templates/modal_restriction.html | 2 +- cps/web.py | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 07d39a7a..b84f5a74 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -435,15 +435,15 @@ def delete_restriction(type): @admin_required def list_restriction(type): if type == 0: # Tags as template - restrict = [{'Element': x, 'type':'1', 'id': 'd'+str(i) } + restrict = [{'Element': x, 'type':_('deny'), 'id': 'd'+str(i) } for i,x in enumerate(config.list_restricted_tags()) if x != '' ] - allow = [{'Element': x, 'type':'1', 'id': 'a'+str(i) } + allow = [{'Element': x, 'type':_('allow'), 'id': 'a'+str(i) } for i,x in enumerate(config.list_allowed_tags()) if x != ''] json_dumps = restrict + allow elif type == 1: # CustomC as template - restrict = [{'Element': x, 'type':'1', 'id': 'd'+str(i) } + restrict = [{'Element': x, 'type':_('deny'), 'id': 'd'+str(i) } for i,x in enumerate(config.list_restricted_column_values()) if x != '' ] - allow = [{'Element': x, 'type':'1', 'id': 'a'+str(i) } + allow = [{'Element': x, 'type':_('allow'), 'id': 'a'+str(i) } for i,x in enumerate(config.list_allowed_column_values()) if x != ''] json_dumps = restrict + allow elif type == 2: # Tags per user @@ -452,9 +452,9 @@ def list_restriction(type): usr = ub.session.query(ub.User).filter(ub.User.id == usr_id).first() else: usr = current_user - restrict = [{'Element': x, 'type':'2', 'id': 'd'+str(i) } + restrict = [{'Element': x, 'type':_('deny'), 'id': 'd'+str(i) } for i,x in enumerate(usr.list_restricted_tags()) if x != '' ] - allow = [{'Element': x, 'type':'2', 'id': 'a'+str(i) } + allow = [{'Element': x, 'type':_('allow'), 'id': 'a'+str(i) } for i,x in enumerate(usr.list_allowed_tags()) if x != ''] json_dumps = restrict + allow elif type == 3: # CustomC per user @@ -463,9 +463,9 @@ def list_restriction(type): usr = ub.session.query(ub.User).filter(ub.User.id==usr_id).first() else: usr = current_user - restrict = [{'Element': x, 'type':'2', 'id': 'd'+str(i) } + restrict = [{'Element': x, 'type':_('deny'), 'id': 'd'+str(i) } for i,x in enumerate(usr.list_restricted_column_values()) if x != '' ] - allow = [{'Element': x, 'type':'2', 'id': 'a'+str(i) } + allow = [{'Element': x, 'type':_('allow'), 'id': 'a'+str(i) } for i,x in enumerate(usr.list_allowed_column_values()) if x != ''] json_dumps = restrict + allow else: diff --git a/cps/cli.py b/cps/cli.py index e76a12cc..8d410a90 100644 --- a/cps/cli.py +++ b/cps/cli.py @@ -43,7 +43,7 @@ parser.add_argument('-k', metavar='path', help='path and name to SSL keyfile, e.g. /opt/test.key, works only in combination with certfile') parser.add_argument('-v', '--version', action='version', help='Shows version number and exits Calibre-web', version=version_info()) -parser.add_argument('-i', metavar='ip-adress', help='Server IP-Adress to listen') +parser.add_argument('-i', metavar='ip-address', help='Server IP-Address to listen') parser.add_argument('-s', metavar='user:pass', help='Sets specific username to new password') args = parser.parse_args() diff --git a/cps/helper.py b/cps/helper.py index 9c4865f0..93ce1b07 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -736,7 +736,7 @@ def speaking_language(languages=None): # example SELECT * FROM @TABLE WHERE 'abcdefg' LIKE Name; # from https://code.luasoftware.com/tutorials/flask/execute-raw-sql-in-flask-sqlalchemy/ def check_valid_domain(domain_text): - domain_text = domain_text.split('@', 1)[-1].lower() + # domain_text = domain_text.split('@', 1)[-1].lower() sql = "SELECT * FROM registration WHERE (:domain LIKE domain and allow = 1);" result = ub.session.query(ub.Registration).from_statement(text(sql)).params(domain=domain_text).all() if not len(result): diff --git a/cps/templates/modal_restriction.html b/cps/templates/modal_restriction.html index 70247cb5..bd13e315 100644 --- a/cps/templates/modal_restriction.html +++ b/cps/templates/modal_restriction.html @@ -13,7 +13,7 @@ - + diff --git a/cps/web.py b/cps/web.py index 88291d30..2b442364 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1010,7 +1010,7 @@ def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs) name = _(u'Read Books') + ' (' + str(len(readBookIds)) + ')' pagename = "read" else: - total_books = db.session.query(func.count(db.Books.id)).scalar() + total_books = db.session.query(func.count(db.Books.id)).filter(common_filters()).scalar() name = _(u'Unread Books') + ' (' + str(total_books - len(readBookIds)) + ')' pagename = "unread" return render_title_template('index.html', random=random, entries=entries, pagination=pagination,