From 6ecf15476a38caa79fc8409680230a060b78563d Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 14 Jan 2022 01:29:15 +0200 Subject: [PATCH] g --- files/classes/submission.py | 4 ++-- files/classes/user.py | 5 +++++ files/routes/admin.py | 17 ++++++++++------- files/routes/static.py | 1 + files/routes/users.py | 1 + files/routes/votes.py | 4 ++-- files/templates/authforms.html | 4 ++-- files/templates/comments.html | 6 ++++++ files/templates/default.html | 4 ++-- files/templates/log.html | 4 ++-- files/templates/login.html | 2 +- files/templates/login_2fa.html | 2 +- files/templates/settings.html | 2 +- files/templates/settings2.html | 4 ++-- files/templates/sign_up.html | 2 +- files/templates/sign_up_failed_ref.html | 2 +- files/templates/submit.html | 4 ++-- files/templates/userpage.html | 8 ++++---- files/templates/votes.html | 2 +- 19 files changed, 47 insertions(+), 31 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index 0b7734aa8..2285531af 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -342,8 +342,8 @@ class Submission(Base): if v.teddit: url = self.url.replace("old.reddit.com", "teddit.net") elif not v.oldreddit: url = self.url.replace("old.reddit.com", "reddit.com") if '/comments/' in url and "sort=" not in url: - if "?" in url: url += "&context=99" - else: url += "?context=99" + if "?" in url: url += "&context=9" + else: url += "?context=9" if v.controversial: url += "&sort=controversial" return url elif self.url: diff --git a/files/classes/user.py b/files/classes/user.py index 56398f3a3..b554c1776 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -561,6 +561,11 @@ class User(Base): def applications(self): return g.db.query(OauthApp).filter_by(author_id=self.id).order_by(OauthApp.id) + @property + @lazy + def created_datetime(self): + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) + @lazy def subscribed_idlist(self, page=1): posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all() diff --git a/files/routes/admin.py b/files/routes/admin.py index d4b3ab22c..646d77df1 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -879,26 +879,29 @@ def ban_user(user_id, v): user = g.db.query(User).filter_by(id=user_id).one_or_none() + if not user: abort(404) + if user.admin_level >= v.admin_level: abort(403) days = float(request.values.get("days")) if request.values.get('days') else 0 - reason = sanitize(request.values.get("reason", ""))[:256] - message = request.values.get("reason", "").strip()[:256] - if not user: abort(400) + reason = request.values.get("reason", "").strip()[:256] + passed_reason = filter_emojis_only(reason) - user.ban(admin=v, reason=reason, days=days) + if len(passed_reason) > 256: passed_reason = reason + + user.ban(admin=v, reason=passed_reason, days=days) if request.values.get("alts"): for x in user.alts: if x.admin_level: break - user.ban(admin=v, reason=reason, days=days) + user.ban(admin=v, reason=passed_reason, days=days) if days: - if message: text = f"Your account has been suspended for {days} days for the following reason:\n\n> {message}" + if reason: text = f"Your account has been suspended for {days} days for the following reason:\n\n> {reason}" else: text = f"Your account has been suspended for {days} days." else: - if message: text = f"Your account has been permanently suspended for the following reason:\n\n> {message}" + if reason: text = f"Your account has been permanently suspended for the following reason:\n\n> {reason}" else: text = "Your account has been permanently suspended." send_repeatable_notification(user.id, text) diff --git a/files/routes/static.py b/files/routes/static.py index 188813f03..0e5ee10c4 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -274,6 +274,7 @@ def contact(v): @app.post("/send_admin") @limiter.limit("1/second") +@limiter.limit("6/hour") @auth_required def submit_contact(v): message = f'This message has been sent automatically to all admins via [/contact](/contact), user email is "{v.email}"\n\nMessage:\n\n' + request.values.get("message", "") diff --git a/files/routes/users.py b/files/routes/users.py index dd5a21464..4aadbf8f3 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -479,6 +479,7 @@ def message2(v, username): @app.post("/reply") @limiter.limit("1/second") @limiter.limit("6/minute") +@limiter.limit("50/hour") @auth_required def messagereply(v): diff --git a/files/routes/votes.py b/files/routes/votes.py index 6c68c299f..1bb45f241 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -28,7 +28,7 @@ def admin_vote_info_get(v): if isinstance(thing, Submission): if thing.author.shadowbanned and not (v and v.admin_level): - thing_id = g.db.query(Submission.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).first()[0] + thing_id = g.db.query(Submission.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Submission.id).first()[0] else: thing_id = thing.id ups = g.db.query(Vote @@ -44,7 +44,7 @@ def admin_vote_info_get(v): elif isinstance(thing, Comment): if thing.author.shadowbanned and not (v and v.admin_level): - thing_id = g.db.query(Comment.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).first()[0] + thing_id = g.db.query(Comment.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Comment.id).first()[0] else: thing_id = thing.id ups = g.db.query(CommentVote diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 461d26f85..5c521456d 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,7 +15,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/comments.html b/files/templates/comments.html index af5eabaf0..492a3ee7b 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -1,3 +1,9 @@ +{% if comment_info and not request.full_path.endswith('#context') %} + +{% endif %} + {% if v %} {% include "award_modal.html" %} {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index c67a680c8..da51fe7b8 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -7,7 +7,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/log.html b/files/templates/log.html index 401e47d1e..ea93986fc 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index febcdd253..fb1ce59f6 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -18,7 +18,7 @@ {% endblock %} - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index ed4ee9fd3..0c7976aff 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -14,7 +14,7 @@ 2-Step Login - {{'SITE_NAME' | app_config}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 6fce61fa1..cde567a71 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -34,7 +34,7 @@ - + {% if v.agendaposter %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index dc9936975..a8ed026cf 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{'SITE_NAME' | app_config}}{% else %}Sign up - {{'SITE_NAME' | app_config}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 599583697..9142f2754 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{'SITE_NAME' | app_config}}{% else %}{{'SITE_NAME' | app_config}}{% endif %} - + diff --git a/files/templates/submit.html b/files/templates/submit.html index e3906987f..fc1523089 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -26,7 +26,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - + {% endif %} {% endblock %} diff --git a/files/templates/userpage.html b/files/templates/userpage.html index f97be6e5e..2c65c816d 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -42,12 +42,12 @@
{% if u.is_suspended %} -
BANNED USER{% if u.ban_reason %}: +
BANNED USER{% if u.ban_reason %}: {% if u.ban_reason_link %}{% endif %} {{ u.ban_reason }} {% if u.ban_reason_link %}{% endif %} {% endif %}
- {% if u.unban_utc %}
{{u.unban_string}}
{% endif %} + {% if u.unban_utc %}
>{{u.unban_string}}
{% endif %} {% endif %}

{{u.username}}

@@ -346,8 +346,8 @@
{% if u.is_suspended %} -
BANNED USER{% if u.ban_reason %}: {{u.ban_reason}}{% endif %}
- {% if u.unban_utc %}
{{u.unban_string}}
{% endif %} +
>BANNED USER{% if u.ban_reason %}: {{u.ban_reason}}{% endif %}
+ {% if u.unban_utc %}
>{{u.unban_string}}
{% endif %} {% endif %} {% if u.verified %} {% endif %}

{{u.username}}

diff --git a/files/templates/votes.html b/files/templates/votes.html index 7a65f8397..1a5831695 100644 --- a/files/templates/votes.html +++ b/files/templates/votes.html @@ -14,7 +14,7 @@

Info

{{thing.permalink}}

Author: @{{thing.author.username}}

-

Author Created At: {{thing.author.created_utc}} ({{thing.author.created_datetime}})

+

Author Created At: ({{thing.author.created_datetime}})

Upvotes: {{ups | length}}

Downvotes: {{downs | length}}