From 2383019663ff868ae52e33e67a81aaa29f70100b Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 20 Oct 2021 23:06:25 +0200 Subject: [PATCH] fsd --- files/classes/award.py | 18 +++++++- files/classes/comment.py | 2 +- files/classes/mod_logs.py | 8 ++-- files/classes/user.py | 20 ++++++++- files/routes/admin.py | 4 +- files/routes/awards.py | 58 ++++++++++++++++++++----- files/routes/front.py | 2 +- files/routes/votes.py | 4 ++ files/templates/award_modal.html | 2 +- files/templates/comments.html | 10 ++--- files/templates/submission.html | 4 +- files/templates/submission_listing.html | 4 +- 12 files changed, 105 insertions(+), 31 deletions(-) diff --git a/files/classes/award.py b/files/classes/award.py index 9c7910793..01c12374d 100755 --- a/files/classes/award.py +++ b/files/classes/award.py @@ -48,6 +48,14 @@ if site_name == "Drama": "color": "text-pink", "price": 500 }, + "pin": { + "kind": "pin", + "title": "1-Hour Pin", + "description": "Pins the post.", + "icon": "fas fa-thumbtack", + "color": "text-warning", + "price": 750 + }, } else: AWARDS = { @@ -74,7 +82,15 @@ else: "icon": "fas fa-train", "color": "text-pink", "price": 500 - } + }, + "pin": { + "kind": "pin", + "title": "1-Hour Pin", + "description": "Pins the post.", + "icon": "fas fa-thumbtack", + "color": "text-warning", + "price": 750 + }, } diff --git a/files/classes/comment.py b/files/classes/comment.py index 3cb35b363..a517e8a03 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -52,7 +52,7 @@ class Comment(Base): senttouser = relationship("User", primaryjoin="User.id==Comment.sentto", viewonly=True) parent_comment = relationship("Comment", remote_side=[id], viewonly=True) child_comments = relationship("Comment", remote_side=[parent_comment_id], viewonly=True) - #awards = relationship("AwardRelationship", viewonly=True) + awards = relationship("AwardRelationship", viewonly=True) awards = None diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index 23a9caafd..1e097c269 100755 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -175,22 +175,22 @@ ACTIONTYPES={ }, "pin_comment":{ "str":'pinned a {self.target_link}', - "icon":"fa-thumbtack fa-rotate--45", + "icon":"fa-thumbtack", "color": "bg-info", }, "unpin_comment":{ "str":'un-pinned a {self.target_link}', - "icon":"fa-thumbtack fa-rotate--45", + "icon":"fa-thumbtack", "color": "bg-muted", }, "pin_post":{ "str":'pinned post {self.target_link}', - "icon":"fa-thumbtack fa-rotate--45", + "icon":"fa-thumbtack", "color": "bg-success", }, "unpin_post":{ "str":'un-pinned post {self.target_link}', - "icon":"fa-thumbtack fa-rotate--45", + "icon":"fa-thumbtack", "color": "bg-muted", }, "set_nsfw":{ diff --git a/files/classes/user.py b/files/classes/user.py index 8f24727f7..8954c71b4 100755 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -64,7 +64,15 @@ if site_name == "Drama": "icon": "fas fa-train", "color": "text-pink", "price": 500 - } + }, + "pin": { + "kind": "pin", + "title": "1-Hour Pin", + "description": "Pins the post.", + "icon": "fas fa-thumbtack", + "color": "text-warning", + "price": 750 + }, } else: AWARDS = { @@ -91,7 +99,15 @@ else: "icon": "fas fa-train", "color": "text-pink", "price": 500 - } + }, + "pin": { + "kind": "pin", + "title": "1-Hour Pin", + "description": "Pins the post.", + "icon": "fas fa-thumbtack", + "color": "text-warning", + "price": 750 + }, } class User(Base): diff --git a/files/routes/admin.py b/files/routes/admin.py index 4daf94042..a279047a7 100755 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1040,7 +1040,9 @@ def api_sticky_post(post_id, v): post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first() if post: - if post.stickied: post.stickied = None + if post.stickied: + if post.stickied.startswith("t:"): abort(403) + else: post.stickied = None else: post.stickied = v.username g.db.add(post) diff --git a/files/routes/awards.py b/files/routes/awards.py index e650a5f97..124c378bf 100755 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -51,7 +51,15 @@ def shop(v): "icon": "fas fa-train", "color": "text-pink", "price": 500 - } + }, + "pin": { + "kind": "pin", + "title": "1-Hour Pin", + "description": "Pins the post.", + "icon": "fas fa-thumbtack", + "color": "text-warning", + "price": 750 + }, } else: AWARDS = { @@ -77,8 +85,16 @@ def shop(v): "description": "Summons a train on the post.", "icon": "fas fa-train", "color": "text-pink", - "price": 500 - } + "price": 50 + }, + "pin": { + "kind": "pin", + "title": "1-Hour Pin", + "description": "Pins the post.", + "icon": "fas fa-thumbtack", + "color": "text-warning", + "price": 750 + }, } query = g.db.query( @@ -152,7 +168,15 @@ def buy(v, award): "icon": "fas fa-train", "color": "text-pink", "price": 500 - } + }, + "pin": { + "kind": "pin", + "title": "1-Hour Pin", + "description": "Pins the post.", + "icon": "fas fa-thumbtack", + "color": "text-warning", + "price": 750 + }, } else: AWARDS = { @@ -179,7 +203,15 @@ def buy(v, award): "icon": "fas fa-train", "color": "text-pink", "price": 500 - } + }, + "pin": { + "kind": "pin", + "title": "1-Hour Pin", + "description": "Pins the post.", + "icon": "fas fa-thumbtack", + "color": "text-warning", + "price": 750 + }, } if award not in AWARDS: abort(400) @@ -233,8 +265,8 @@ def award_post(pid, v): post = g.db.query(Submission).options(lazyload('*')).filter_by(id=pid).first() - if not post or post.is_banned or post.deleted_utc > 0: - return {"error": "That post doesn't exist or has been deleted or removed."}, 404 + if not post: + return {"error": "That post doesn't exist."}, 404 existing_award = g.db.query(AwardRelationship).options(lazyload('*')).filter( and_( @@ -272,6 +304,11 @@ def award_post(pid, v): g.db.add(author) link = f"[this post]({post.permalink})" send_notification(NOTIFICATIONS_ACCOUNT, author, f"Your account has been suspended permanently for {link}. You must [provide the admins](/contact) a timestamped picture of you touching grass to get unbanned!") + elif kind == "pin": + if post.stickied and post.stickied.startswith("t:"): t = int(post.stickied[2:]) + 600 + else: t = int(time.time()) + 3600 + post.stickied = f"t:{t}" + g.db.add(post) post.author.received_award_count += 1 g.db.add(post.author) @@ -307,8 +344,8 @@ def award_comment(cid, v): c = g.db.query(Comment).options(lazyload('*')).filter_by(id=cid).first() - if not c or c.is_banned or c.deleted_utc > 0: - return {"error": "That comment doesn't exist or has been deleted or removed."}, 404 + if not c: + return {"error": "That comment doesn't exist."}, 404 existing_award = g.db.query(AwardRelationship).options(lazyload('*')).filter( and_( @@ -324,8 +361,7 @@ def award_comment(cid, v): msg = f"@{v.username} has given your [comment]({c.permalink}) the {AWARDS[kind]['title']} Award!" note = request.values.get("note", "").strip() - if note: - msg += f"\n\n> {note}" + if note: msg += f"\n\n> {note}" send_notification(NOTIFICATIONS_ACCOUNT, c.author, msg) diff --git a/files/routes/front.py b/files/routes/front.py index 9611fc7fd..8c9392703 100755 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -213,7 +213,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' posts = posts[:size] - pins = g.db.query(Submission.id).options(lazyload('*')).filter(Submission.stickied != None) + pins = g.db.query(Submission.id).options(lazyload('*')).filter(Submission.stickied != None, Submission.is_banned == False) if v and v.admin_level == 0: blocking = [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=v.id).all()] blocked = [x[0] for x in g.db.query(UserBlock.user_id).filter_by(target_id=v.id).all()] diff --git a/files/routes/votes.py b/files/routes/votes.py index 18dd13044..10c113b3a 100755 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -104,6 +104,10 @@ def api_vote_post(post_id, new, v): g.db.add(post) g.db.commit() except: g.db.rollback() + + if post.stickied and post.stickied.startswith("t:") and int(time.time()) > int(post.stickied[2:]): + post.stickied = None + g.db.add(post) return "", 204 @app.post("/vote/comment//") diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index 4c5e9f0e7..8190eaf74 100755 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -64,7 +64,7 @@ @media (min-width: 767.98px) { .award-columns { - column-count: 5 !important; + column-count: 6 !important; } } \ No newline at end of file diff --git a/files/templates/comments.html b/files/templates/comments.html index f40616faa..d79b4554d 100755 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -263,7 +263,7 @@ {% if c.active_flags %}{{c.active_flags}} Reports{% endif %} {% if c.over_18 %}+18{% endif %} {% if v and v.admin_level==6 and c.author.shadowbanned %}{% endif %} - {% if c.is_pinned %}{% endif %} + {% if c.is_pinned %}{% endif %} {% if c.distinguish_level %}{% endif %} {% if c.is_op %}{% endif %} {% if c.is_bot %}{% endif %} @@ -435,9 +435,9 @@ {% endif %} {% if v and c.post and (v.admin_level >= 1 or v.id == c.post.author_id) and c.level == 1 %} - Unpin + Unpin - Pin + Pin {% endif %} @@ -579,8 +579,8 @@ {% endif %} {% if v and c.post and (v.admin_level >= 1 or v.id == c.post.author_id) and c.level == 1 %} - Pin - Unpin + Pin + Unpin {% endif %} {% if v %} diff --git a/files/templates/submission.html b/files/templates/submission.html index d6223bda2..4340ddb9e 100755 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -375,8 +375,8 @@ {% endfor %} {% endif %} {% if v and v.admin_level==6 and p.author.shadowbanned %}{% endif %} - {% if p.stickied %}{% endif %} - {% if p.is_pinned %}{% endif %} + {% if p.stickied %}{% endif %} + {% if p.is_pinned %}{% endif %} {% if p.distinguish_level %} {% endif %} {% if p.is_bot %} {% endif %} {% if p.over_18 %}+18{% endif %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index d1ac07feb..2e2b16afa 100755 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -174,9 +174,9 @@ {% endfor %} {% endif %} {% if v and v.admin_level==6 and p.author.shadowbanned %}{% endif %} - {% if p.stickied %}{% endif %} + {% if p.stickied %}{% endif %} {% if p.distinguish_level %}{% endif %} - {% if p.is_pinned and request.path.startswith('/@') %}{% endif %} + {% if p.is_pinned and request.path.startswith('/@') %}{% endif %} {% if p.over_18 %}+18{% endif %} {% if p.is_bot %} {% endif %} {% if p.is_blocking %}{% endif %}