From a75a95fcf8024dec5eb5fb18c6da4907a9d8294b Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 12 Oct 2021 15:42:10 +0200 Subject: [PATCH] dfs --- files/classes/user.py | 2 +- files/helpers/filters.py | 11 ++++------- files/routes/comments.py | 15 ++------------- files/routes/front.py | 6 +++--- files/routes/posts.py | 21 ++++----------------- files/routes/search.py | 4 ++-- files/routes/settings.py | 2 -- files/routes/users.py | 2 +- files/templates/admin/app.html | 2 +- files/templates/admin/apps.html | 2 +- files/templates/changelog.html | 2 +- files/templates/comments.html | 13 +------------ files/templates/default.html | 4 ++-- files/templates/settings.html | 2 +- files/templates/settings2.html | 2 +- files/templates/submission.html | 2 +- files/templates/userpage.html | 2 +- 17 files changed, 27 insertions(+), 67 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 50bd508cf..e7bd734e3 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -266,7 +266,7 @@ class User(Base): elif sort == "old": posts = posts.order_by(Submission.created_utc.asc()) elif sort == "controversial": - posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes) + posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes * Submission.downvotes) elif sort == "top": posts = posts.order_by(Submission.downvotes - Submission.upvotes) elif sort == "bottom": diff --git a/files/helpers/filters.py b/files/helpers/filters.py index 2a25ef96b..d03166277 100644 --- a/files/helpers/filters.py +++ b/files/helpers/filters.py @@ -14,9 +14,8 @@ def filter_comment_html(html_text): for link in links: - href=link.get("href", None) - if not href: - continue + href = link.get("href") + if not href: continue domain = urlparse(href).netloc @@ -30,7 +29,5 @@ def filter_comment_html(html_text): bans = [x for x in g.db.query(BannedDomain).options(lazyload('*')).filter(BannedDomain.domain.in_(list(domain_list))).all()] - if bans: - return bans - else: - return [] + if bans: return bans + else: return [] diff --git a/files/routes/comments.py b/files/routes/comments.py index 137440641..f187f548a 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -166,13 +166,7 @@ def api_comment(v): if bans: ban = bans[0] reason = f"Remove the {ban.domain} link from your comment and try again." - if ban.reason: - reason += f" {ban.reason}" - - if any([x.reason==4 for x in bans]): - v.ban(days=30, reason="Digitally malicious content") - if any([x.reason==7 for x in bans]): - v.ban( reason="Sexualizing minors") + if ban.reason: reason += f" {ban.reason}" return {"error": reason}, 401 existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == v.id, @@ -590,13 +584,8 @@ def edit_comment(cid, v): ban = bans[0] reason = f"Remove the {ban.domain} link from your comment and try again." - - if any([x.reason==4 for x in bans]): - v.ban(days=30, reason="Digitally malicious content is not allowed.") - return {"error":"Digitally malicious content is not allowed."} - if ban.reason: - reason += f" {ban.reason}" + if ban.reason: reason += f" {ban.reason}" if request.headers.get("Authorization"): return {'error': f'A blacklisted domain was used.'}, 400 else: return render_template("comment_failed.html", diff --git a/files/routes/front.py b/files/routes/front.py index 7a79f755b..bee1202e0 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -199,7 +199,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' elif sort == "old": posts = posts.order_by(Submission.created_utc.asc()) elif sort == "controversial": - posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes) + posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes * Submission.downvotes) elif sort == "top": posts = posts.order_by(Submission.downvotes - Submission.upvotes) elif sort == "bottom": @@ -297,7 +297,7 @@ def changeloglist(v=None, sort="new", page=1 ,t="all"): elif sort == "old": posts = posts.order_by(Submission.created_utc.asc()) elif sort == "controversial": - posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes) + posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes * Submission.downvotes) elif sort == "top": posts = posts.order_by(Submission.downvotes - Submission.upvotes) elif sort == "bottom": @@ -367,7 +367,7 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all"): elif sort == "old": comments = comments.order_by(Comment.created_utc.asc()) elif sort == "controversial": - comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes) + comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes) elif sort == "top": comments = comments.order_by(Comment.downvotes - Comment.upvotes) elif sort == "bottom": diff --git a/files/routes/posts.py b/files/routes/posts.py index c8c2733ee..ee9ff6cd7 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -143,7 +143,7 @@ def post_id(pid, anything=None, v=None): elif sort == "old": comments = comments.order_by(Comment.created_utc.asc()) elif sort == "controversial": - comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes) + comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes) elif sort == "top": comments = comments.order_by(Comment.downvotes - Comment.upvotes) elif sort == "bottom": @@ -168,7 +168,7 @@ def post_id(pid, anything=None, v=None): elif sort == "old": comments = comments.order_by(Comment.created_utc.asc()) elif sort == "controversial": - comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes) + comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes) elif sort == "top": comments = comments.order_by(Comment.downvotes - Comment.upvotes) elif sort == "bottom": @@ -217,11 +217,7 @@ def edit_post(pid, v): reason = f"Remove the {ban.domain} link from your post and try again." if ban.reason: reason += f" {ban.reason}" - - if any([x.reason==4 for x in bans]): - v.ban(days=30, reason="Digitally malicious content is not allowed.") - abort(403) - + return {"error": reason}, 403 p.body = body @@ -536,9 +532,6 @@ def submit_post(v): domain_obj = get_domain(domain) if domain_obj: - if domain_obj.reason==4: v.ban(days=30, reason="Digitally malicious content") - elif domain_obj.reason==7: v.ban(reason="Sexualizing minors") - if request.headers.get("Authorization"): return {"error":"ToS violation"}, 400 else: return render_template("submit.html", v=v, error="ToS Violation", title=title, url=url, body=request.values.get("body", "")), 400 elif "twitter.com" in domain: @@ -668,13 +661,7 @@ def submit_post(v): if bans: ban = bans[0] reason = f"Remove the {ban.domain} link from your post and try again." - if ban.reason: - reason += f" {ban.reason}" - - if any([x.reason==4 for x in bans]): - v.ban(days=30, reason="Digitally malicious content is not allowed.") - abort(403) - + if ban.reason: reason += f" {ban.reason}" if request.headers.get("Authorization"): return {"error": reason}, 403 else: return render_template("submit.html", v=v, error=reason, title=title, url=url, body=request.values.get("body", "")), 403 diff --git a/files/routes/search.py b/files/routes/search.py index cb812bb9e..22bbbe99d 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -132,7 +132,7 @@ def searchposts(v): elif sort == "old": posts = posts.order_by(Submission.created_utc.asc()) elif sort == "controversial": - posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes) + posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes * Submission.downvotes) elif sort == "top": posts = posts.order_by(Submission.downvotes - Submission.upvotes) elif sort == "bottom": @@ -235,7 +235,7 @@ def searchcomments(v): elif sort == "old": comments = comments.order_by(Comment.created_utc.asc()) elif sort == "controversial": - comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes) + comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes) elif sort == "top": comments = comments.order_by(Comment.downvotes - Comment.upvotes) elif sort == "bottom": diff --git a/files/routes/settings.py b/files/routes/settings.py index b2ddc106b..181bf30f7 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -135,8 +135,6 @@ def settings_profile_post(v): if ban.reason: reason += f" {ban.reason}" - if any([x.reason==4 for x in bans]): - v.ban(days=30, reason="Digitally malicious content is not allowed.") return {"error": reason}, 401 if len(bio_html) > 10000: abort(400) diff --git a/files/routes/users.py b/files/routes/users.py index a18a18a41..23ebea3ef 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -572,7 +572,7 @@ def u_username_comments(username, v=None): elif sort == "old": comments = comments.order_by(Comment.created_utc.asc()) elif sort == "controversial": - comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes) + comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes) elif sort == "top": comments = comments.order_by(Comment.downvotes - Comment.upvotes) elif sort == "bottom": diff --git a/files/templates/admin/app.html b/files/templates/admin/app.html index 4bc1a9420..6c9573e75 100644 --- a/files/templates/admin/app.html +++ b/files/templates/admin/app.html @@ -63,7 +63,7 @@ diff --git a/files/templates/admin/apps.html b/files/templates/admin/apps.html index 1539b36ad..7033255da 100644 --- a/files/templates/admin/apps.html +++ b/files/templates/admin/apps.html @@ -63,7 +63,7 @@ diff --git a/files/templates/changelog.html b/files/templates/changelog.html index 2c746aaa7..3a7541bf3 100644 --- a/files/templates/changelog.html +++ b/files/templates/changelog.html @@ -3,7 +3,7 @@ {% block pagetitle %}Changelog{% endblock %} {% block desktopBanner %} - +
diff --git a/files/templates/comments.html b/files/templates/comments.html index 60327eb66..c88c80c8f 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -26,7 +26,7 @@ {% if v %} {% include "award_modal.html" %} - + {% endif %} @@ -593,17 +593,6 @@ {% endfor %} - - - {% if v %} {% include "gif_modal.html" %} {% include "emoji_modal.html" %} diff --git a/files/templates/default.html b/files/templates/default.html index 860862ec5..adccb13ae 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -69,7 +69,7 @@ {% if v %} - + {% endif %} @@ -343,7 +343,7 @@
diff --git a/files/templates/settings.html b/files/templates/settings.html index 81cd4d74f..191551aa2 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -259,7 +259,7 @@
diff --git a/files/templates/settings2.html b/files/templates/settings2.html index fb887b2cb..534f550cb 100644 --- a/files/templates/settings2.html +++ b/files/templates/settings2.html @@ -147,7 +147,7 @@ diff --git a/files/templates/submission.html b/files/templates/submission.html index 81b2e680c..b7b4fba55 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -53,7 +53,7 @@ {% if v %} - + {% include "award_modal.html" %} {% include "emoji_modal.html" %} {% include "gif_modal.html" %} diff --git a/files/templates/userpage.html b/files/templates/userpage.html index f77018f45..bad6c6b47 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -15,7 +15,7 @@ } - + {{u.username}}'s profile - {{'SITE_NAME' | app_config}} {% if u.is_private %}