From 3ac74a77fa69f507945e449053eece69e7711532 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 16 May 2024 23:17:52 +0300 Subject: [PATCH] underage ban age --- files/assets/css/main.css | 4 ++-- files/helpers/config/const.py | 4 ++++ files/routes/errors.py | 1 + files/routes/notifications.py | 15 ++++++++++----- files/routes/static.py | 11 ++++++++++- files/routes/wrappers.py | 3 +++ files/templates/comments.html | 10 +++++----- files/templates/contact.html | 17 +++++++++++++++-- files/templates/errors/error.html | 8 ++++++-- 9 files changed, 56 insertions(+), 17 deletions(-) diff --git a/files/assets/css/main.css b/files/assets/css/main.css index 30e54f660..de17d7f1c 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -4402,11 +4402,11 @@ small, .small { margin-top: 2rem; padding-left: 12px; } -#notifications .comment, #userpage .comment { +#notifications .comment, #userpage .comment, #contact .comment { margin-top: 0.5rem; margin-bottom: 1rem; } -#notifications .comment:last-child, #userpage .comment:last-child { +#notifications .comment:last-child, #userpage .comment:last-child, #contact .comment:last-child { margin-bottom: 0; } .comment .comment-body { diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index f7c8152fe..e8c281a5e 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -464,6 +464,7 @@ WERKZEUG_ERROR_DESCRIPTIONS = { 403: "You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.", 404: "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.", 405: "The method is not allowed for the requested URL.", + 406: "The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.", 409: "A conflict happened while processing the request. The resource might have been modified while the request was being processed.", 410: "The requested URL is no longer available on this server and there is no forwarding address. If you followed a link from a foreign page, please contact the author of this page.", 413: "The data value transmitted exceeds the capacity limit.", @@ -481,6 +482,7 @@ ERROR_TITLES = { 403: "Forbidden🙅‍♀️", 404: "Not Found - where did it go?", 405: "Method Not Allowed, BAD.", + 406: "THIS IS AN 18+ WEBSITE", 409: "Cumflict", 410: "Gone... and Forgotten", 413: "Gayload Too Large", @@ -496,6 +498,7 @@ ERROR_MSGS = { 403: "YOU AREN'T WELCOME HERE GO AWAY", 404: "Someone typed something wrong and it was probably you, please do better.", 405: "idk how anyone gets this error but if you see this, remember to follow @carpathianflorist
the original error text here talked about internet gremlins and wtf", + 406: "You have been banned for being underage.
If this was in error, please contact the admins below.", 409: "There's a conflict between what you're trying to do and what you or someone else has done and because of that you can't do what you're trying to do. So maybe like... don't try and do that? Sorry not sorry", 410: "You were too slow. The link FUCKING DIED. Request a new one and be more efficient.", 413: "That's a heckin' chonker of a file! Please make it smaller or maybe like upload it somewhere else idk
jc wrote this one hi jc!
- carp", @@ -511,6 +514,7 @@ ERROR_MARSEYS = { 403: "marseytroll", 404: "marseyconfused", 405: "marseyretard", + 406: "marseydisagree", 409: "marseynoyou", 410: "marseyrave", 413: "marseychonker2", diff --git a/files/routes/errors.py b/files/routes/errors.py index a6ec6cf89..e8460a915 100644 --- a/files/routes/errors.py +++ b/files/routes/errors.py @@ -20,6 +20,7 @@ from files.__main__ import app, limiter @app.errorhandler(403) @app.errorhandler(404) @app.errorhandler(405) +@app.errorhandler(406) @app.errorhandler(409) @app.errorhandler(410) @app.errorhandler(413) diff --git a/files/routes/notifications.py b/files/routes/notifications.py index 60dd18626..9fa983bdf 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -150,11 +150,7 @@ def notifications_chats(v): return render_template("notifications.html", v=v, notifications=chats) -@app.get("/notifications/modmail") -@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) -@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) -@admin_level_required(PERMS['VIEW_MODMAIL']) -def notifications_modmail(v): +def modmail_listing(v): page = get_page() sq = g.db.query(Comment.top_comment_id, Comment.created_utc).distinct(Comment.top_comment_id).filter_by(sentto=MODMAIL_ID).order_by(Comment.top_comment_id, Comment.created_utc.desc()).subquery() @@ -174,6 +170,15 @@ def notifications_modmail(v): v.last_viewed_modmail_notifs = int(time.time()) g.db.add(v) + return listing, total, page + +@app.get("/notifications/modmail") +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@admin_level_required(PERMS['VIEW_MODMAIL']) +def notifications_modmail(v): + listing, total, page = modmail_listing(v) + if v.client: return {"data":[x.json for x in listing]} return render_template("notifications.html", diff --git a/files/routes/static.py b/files/routes/static.py index 0a732ef6e..350e73d75 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -15,6 +15,7 @@ from files.helpers.alerts import * from files.helpers.config.const import * from files.helpers.config.modaction_types import * from files.routes.wrappers import * +from files.routes.notifications import modmail_listing from files.__main__ import app, cache, limiter @@ -280,7 +281,15 @@ def api(v): @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @auth_desired def contact(v): - return render_template("contact.html", v=v) + listing, total, page = modmail_listing(v) + return render_template("contact.html", + v=v, + listing=listing, + total=total, + page=page, + standalone=True, + render_replies=True, + ) @app.post("/contact") @limiter.limit('1/second', scope=rpath) diff --git a/files/routes/wrappers.py b/files/routes/wrappers.py index 992262c53..47960289c 100644 --- a/files/routes/wrappers.py +++ b/files/routes/wrappers.py @@ -87,6 +87,9 @@ def get_logged_in_user(): else: session.pop("lo_user") + if request.path != '/contact' and v and v.is_suspended and 'underage' in v.ban_reason.lower(): + abort(406) + if request.method != "GET" and get_setting('read_only_mode') and not (v and v.admin_level >= PERMS['BYPASS_SITE_READ_ONLY_MODE']): abort(403, "Site is in read-only mode right now. It will be back shortly!") diff --git a/files/templates/comments.html b/files/templates/comments.html index b2ac05190..7c04a0af4 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -36,7 +36,7 @@ {% if render_replies %}
- {% if level<9 or request.path.startswith('/notifications') %} + {% if level<9 or request.path.startswith('/notifications') or request.path == '/contact' %} {% for reply in replies %} {{single_comment(reply, level=level+1)}} {% endfor %} @@ -61,7 +61,7 @@ {% endif %} {% if standalone and level == 1 %} -