From 3ec36603c8195744ae559eeef984e772633ac390 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 11:56:18 +0200 Subject: [PATCH 01/27] sneed --- drama/templates/award_modal.html | 152 +++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 drama/templates/award_modal.html diff --git a/drama/templates/award_modal.html b/drama/templates/award_modal.html new file mode 100644 index 0000000000..15d7a68461 --- /dev/null +++ b/drama/templates/award_modal.html @@ -0,0 +1,152 @@ + + + + + + + + \ No newline at end of file From c3e99fb6a7c0a91ebeb0ce70d3389a37a6caf5e4 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:06:34 +0200 Subject: [PATCH 02/27] sneed --- drama/routes/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drama/routes/__init__.py b/drama/routes/__init__.py index 438666d820..bf40d037f2 100644 --- a/drama/routes/__init__.py +++ b/drama/routes/__init__.py @@ -12,4 +12,5 @@ from .settings import * from .static import * from .users import * from .votes import * -from .feeds import * \ No newline at end of file +from .feeds import * +from .awards import * \ No newline at end of file From af5f2ea9d5080cc11e018326ab800691dfe91c33 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:06:43 +0200 Subject: [PATCH 03/27] sneed --- drama/classes/award.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drama/classes/award.py b/drama/classes/award.py index f8e3cc8359..b0c0dd2104 100644 --- a/drama/classes/award.py +++ b/drama/classes/award.py @@ -3,16 +3,18 @@ from sqlalchemy import * from sqlalchemy.orm import relationship #from .mix_ins import * -from drama.__main__ import Base +from drama.__main__ import Base, app AWARDS = { "ban": { + "kind": "ban", "title": "1-Day Ban", "description": "Ban the author for a day.", "icon": "fas fa-gavel", "color": "text-danger" }, "shit": { + "kind": "shit", "title": "Literal Shitpost", "description": "Let OP know how much their post sucks ass.", "icon": "fas fa-poop", @@ -28,8 +30,8 @@ class AwardRelationship(Base): id = Column(Integer, primary_key=True) user_id = Column(Integer, ForeignKey("users.id")) - submission_id = Column(Integer, ForeignKey("submissions.id")) - comment_id = Column(Integer, ForeignKey("comments.id")) + submission_id = Column(Integer, ForeignKey("submissions.id"), default=None) + comment_id = Column(Integer, ForeignKey("comments.id"), default=None) kind = Column(String(20)) user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", lazy="joined") @@ -44,6 +46,18 @@ class AwardRelationship(Base): lazy="joined" ) + @property + def given(self): + return bool(self.submission_id) or bool(self.comment_id) + @property def type(self): return AWARDS[self.kind] + + @property + def title(self): + return self.type['title'] + + @property + def class_list(self): + return self.type['icon']+' '+self.type['color'] From 9fcbccafdd58be8372398d55b2463e3032da707c Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:06:52 +0200 Subject: [PATCH 04/27] sneed --- drama/routes/awards.py | 156 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 drama/routes/awards.py diff --git a/drama/routes/awards.py b/drama/routes/awards.py new file mode 100644 index 0000000000..3c50c3a820 --- /dev/null +++ b/drama/routes/awards.py @@ -0,0 +1,156 @@ +from drama.__main__ import app +from drama.helpers.wrappers import * +from drama.helpers.alerts import * +from drama.helpers.get import * +from drama.classes.award import * +from flask import g, jsonify, request + + +def banaward_trigger(post=None, comment=None): + + author = post.author if post else comment.author + + if not author.is_suspended or author.admin_level < 1: + author.ban(reason="1-day ban award used", days=1) + + link = f"[this post]({post.permalink})" if post else f"[this comment]({comment.permalink})" + + send_notification(1046, author, f"Your Drama account has been suspended for a day for {link}. It sucked and you should feel bad.") + + +ACTIONS = { + "ban": banaward_trigger +} + + +@app.get("/api/awards") +@auth_required +def get_awards(v): + + return_value = list(AWARDS.values()) + + user_awards = v.awards + for val in return_value: + val['owned'] = len([x for x in user_awards if x.kind == val['kind'] and not x.given]) + + return jsonify(return_value) + + +@app.put("/api/post//awards") +@auth_required +@validate_formkey +def award_post(pid, v): + + if v.is_suspended and v.unban_utc == 0: + return jsonify({"error": "forbidden"}), 403 + + kind = request.form.get("kind", "") + + if kind not in AWARDS: + return jsonify({"error": "That award doesn't exist."}), 404 + + post_award = g.db.query(AwardRelationship).filter( + and_( + AwardRelationship.kind == kind, + AwardRelationship.user_id == v.id, + AwardRelationship.submission_id == None, + AwardRelationship.comment_id == None + ) + ).first() + + if not post_award: + return jsonify({"error": "You don't have that award."}), 404 + + post = g.db.query(Submission).filter_by(id=pid).first() + + if not post or post.is_banned or post.deleted_utc > 0: + return jsonify({"error": "That post doesn't exist or has been deleted or removed."}), 404 + + if post.author_id == v.id: + return jsonify({"error": "You can't award yourself."}), 403 + + existing_award = g.db.query(AwardRelationship).filter( + and_( + AwardRelationship.submission_id == post.id, + AwardRelationship.user_id == v.id + ) + ).first() + + if existing_award: + return jsonify({"error": "You already awarded this post."}), 409 + + post_award.submission_id = post.id + g.db.add(post_award) + + msg = f"Your [post]({post.permalink}) was given the {AWARDS[kind]['title']} Award!" + + note = request.form.get("note", "") + if note: + msg += f"\n\n> {note}" + + send_notification(1046, post.author, msg) + + if kind in ACTIONS: + ACTIONS[kind](post=post) + + return "", 204 + + +@app.put("/api/comment//awards") +@auth_required +@validate_formkey +def award_comment(cid, v): + + if v.is_suspended and v.unban_utc == 0: + return jsonify({"error": "forbidden"}), 403 + + kind = request.form.get("kind", "") + + if kind not in AWARDS: + return jsonify({"error": "That award doesn't exist."}), 404 + + comment_award = g.db.query(AwardRelationship).filter( + and_( + AwardRelationship.kind == kind, + AwardRelationship.user_id == v.id, + AwardRelationship.submission_id == None, + AwardRelationship.comment_id == None + ) + ).first() + + if not comment_award: + return jsonify({"error": "You don't have that award."}), 404 + + c = g.db.query(Comment).filter_by(id=cid).first() + + if not c or c.is_banned or c.deleted_utc > 0: + return jsonify({"error": "That comment doesn't exist or has been deleted or removed."}), 404 + + if c.author_id == v.id: + return jsonify({"error": "You can't award yourself."}), 403 + + existing_award = g.db.query(AwardRelationship).filter( + and_( + AwardRelationship.comment_id == c.id, + AwardRelationship.user_id == v.id + ) + ).first() + + if existing_award: + return jsonify({"error": "You already awarded this comment."}), 409 + + comment_award.comment_id = c.id + g.db.add(comment_award) + + msg = f"Your [comment]({c.permalink}) was given the {AWARDS[kind]['title']} Award!" + + note = request.form.get("note", "") + if note: + msg += f"\n\n> {note}" + + send_notification(1046, c.author, msg) + + if kind in ACTIONS: + ACTIONS[kind](comment=c) + + return "", 204 From b437044cc2e9d9ba5f04d21efb23c108930a4628 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:07:00 +0200 Subject: [PATCH 05/27] sneed --- drama/classes/comment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drama/classes/comment.py b/drama/classes/comment.py index 6ac8639508..8a93e34b2c 100644 --- a/drama/classes/comment.py +++ b/drama/classes/comment.py @@ -67,7 +67,7 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing): parent_comment = relationship("Comment", remote_side=[id]) child_comments = relationship("Comment", remote_side=[parent_comment_id]) - #awards = relationship("AwardRelationship", lazy="joined") + awards = relationship("AwardRelationship", lazy="joined") # These are virtual properties handled as postgres functions server-side # There is no difference to SQLAlchemy, but they cannot be written to From d3f59ab47d7cdadf250fc1e1b2dd441f3bc1071f Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:07:09 +0200 Subject: [PATCH 06/27] sneed --- drama/templates/comments.html | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drama/templates/comments.html b/drama/templates/comments.html index 5b4b560bbe..f94654d1fa 100644 --- a/drama/templates/comments.html +++ b/drama/templates/comments.html @@ -130,7 +130,13 @@ {% if c.edited_utc %} · Edited {{c.edited_string}} {% endif %} - + + {% if c.awards %} + {% for a in c.awards[:5] %} + + {% endfor %} + {% endif %} + {% if c.is_banned and c.ban_reason %} @@ -241,14 +247,6 @@
  • Votes
  • - {% if v and v.id!=c.author_id and v.admin_level == 0 %} - {% if v.banawards > 0 %} -
  • Give ban award
  • - {% else %} -
  • Give ban award
  • - {% endif %} - {% endif %} - {% if v and c.id in v.saved_comment_idlist() %}
  • Unsave
  • {% else %} @@ -259,6 +257,11 @@
  • Reply
  • + {% if v.id!=c.author_id %} +
  • Give Award
  • + {% endif %} + {% endif %}
  • Context
  • Copy link
  • From 73b45852bbb0fe33cfa89d5c435b08c3fac7cc92 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:07:17 +0200 Subject: [PATCH 07/27] sneed --- drama/templates/default.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drama/templates/default.html b/drama/templates/default.html index ea7d3e1946..344f220731 100644 --- a/drama/templates/default.html +++ b/drama/templates/default.html @@ -408,6 +408,14 @@ } } + // award modal + + function awardModal(link) { + var target = document.getElementById("awardTarget"); + + target.value = link; + } + // Expand Images on Desktop function expandDesktopImage(image, link) { @@ -1072,6 +1080,7 @@ {% if v %} +{% include "award_modal.html" %} {% include "flag_post_modal.html" %} {% include "flag_comment_modal.html" %} {% include "gif_modal.html" %} From c4be5dde4fb227f018d5338cb6201efab57791d2 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:07:27 +0200 Subject: [PATCH 08/27] sneed --- drama/templates/submission.html | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drama/templates/submission.html b/drama/templates/submission.html index a5b0652025..0ec5ed5b82 100644 --- a/drama/templates/submission.html +++ b/drama/templates/submission.html @@ -116,12 +116,8 @@ - {% if v and v.id!=p.author_id and v.admin_level == 0 %} - {% if v.banawards > 0 %} - - {% else %} - - {% endif %} + {% if v and v.id!=p.author_id %} + {% endif %} {% if v and p.id in v.subscribed_idlist() %} @@ -224,6 +220,12 @@ {% if p.edited_utc %}  Edited {{p.edited_string}}{% endif %}   {{p.views}} views + + {% if p.awards %} + {% for a in p.awards[:5] %} + + {% endfor %} + {% endif %} {% if p.realurl(v) %} @@ -308,12 +310,8 @@
  • Votes
  • - {% if v and v.id!=p.author_id and v.admin_level == 0 %} - {% if v.banawards > 0 %} -
  • Give ban award
  • - {% else %} -
  • Give ban award
  • - {% endif %} + {% if v and v.id!=p.author_id %} +
  • Give Award
  • {% endif %}
  • Copy link
  • From 3d39d49d4da92d5d8aea128449b3b4ff9d874a8d Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:07:36 +0200 Subject: [PATCH 09/27] sneed --- drama/classes/submission.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drama/classes/submission.py b/drama/classes/submission.py index 6ab17d0767..3cb13d0e41 100644 --- a/drama/classes/submission.py +++ b/drama/classes/submission.py @@ -90,7 +90,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): comment_count = Column(Integer, server_default=FetchedValue()) score = deferred(Column(Float, server_default=FetchedValue())) - #awards = relationship("AwardRelationship", lazy="joined") + awards = relationship("AwardRelationship", lazy="joined") def __init__(self, *args, **kwargs): From c44a501ed4af5fadc19b9518332c0c3ccf5fbe2e Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:07:50 +0200 Subject: [PATCH 10/27] sneed --- drama/templates/submission_listing.html | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drama/templates/submission_listing.html b/drama/templates/submission_listing.html index 07c3b7da3a..912f667ca4 100644 --- a/drama/templates/submission_listing.html +++ b/drama/templates/submission_listing.html @@ -145,6 +145,12 @@ {% if p.edited_utc %}  Edited {{p.edited_string}}{% endif %}   {{p.views}} views + {% if p.awards %} + {% for a in p.awards[:5] %} + + {% endfor %} + {% endif %} +
    @@ -168,12 +174,8 @@
  • Votes
  • - {% if v and v.id!=p.author_id and v.admin_level == 0 %} - {% if v.banawards > 0 %} -
  • Give ban award
  • - {% else %} -
  • Give ban award
  • - {% endif %} + {% if v and v.id!=p.author_id %} +
  • Give Award
  • {% endif %}
  • Copy link
  • @@ -353,12 +355,8 @@
      - {% if v and v.id!=p.author_id and v.admin_level == 0 %} - {% if v.banawards > 0 %} - - {% else %} - - {% endif %} + {% if v and v.id!=p.author_id %} +
    • Give Award
    • {% endif %} {% if v and p.id in v.subscribed_idlist() %} From 9f9c306541b7603582954181f5ff0e44142d1994 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:07:57 +0200 Subject: [PATCH 11/27] sneed --- drama/classes/user.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drama/classes/user.py b/drama/classes/user.py index 8f253eb42c..0abcd06926 100644 --- a/drama/classes/user.py +++ b/drama/classes/user.py @@ -104,6 +104,12 @@ class User(Base, Stndrd, Age_times): lazy="dynamic", primaryjoin="User.id==SaveRelationship.user_id") + awards = relationship( + "AwardRelationship", + lazy="dynamic", + primaryjoin="User.id==AwardRelationship.user_id" + ) + # properties defined as SQL server-side functions referral_count = deferred(Column(Integer, server_default=FetchedValue())) From 7d2fcc751b091601b9dc7be400bf2b4302d94d4c Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 13:10:27 +0200 Subject: [PATCH 12/27] sneed --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index aee51b3dc9..af0747b346 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,4 @@ package-lock.json local.txt *.scssc .idea/* +disablesignups From adbe8037168db7e4c75f07634b846f5dca29c382 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 18:50:40 +0200 Subject: [PATCH 13/27] sneed --- drama/routes/awards.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drama/routes/awards.py b/drama/routes/awards.py index 3c50c3a820..50f473b159 100644 --- a/drama/routes/awards.py +++ b/drama/routes/awards.py @@ -82,7 +82,7 @@ def award_post(pid, v): post_award.submission_id = post.id g.db.add(post_award) - msg = f"Your [post]({post.permalink}) was given the {AWARDS[kind]['title']} Award!" + msg = f"@{v.username} has given your [post]({post.permalink}) was given the {AWARDS[kind]['title']} Award!" note = request.form.get("note", "") if note: @@ -142,7 +142,7 @@ def award_comment(cid, v): comment_award.comment_id = c.id g.db.add(comment_award) - msg = f"Your [comment]({c.permalink}) was given the {AWARDS[kind]['title']} Award!" + msg = f"@{v.username} has given your [comment]({c.permalink}) was given the {AWARDS[kind]['title']} Award!" note = request.form.get("note", "") if note: From 85198e495173e382ae0c5ff0ccd046cb4c7aa044 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 18:50:50 +0200 Subject: [PATCH 14/27] sneed --- drama/templates/comments.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drama/templates/comments.html b/drama/templates/comments.html index f94654d1fa..9ac063a263 100644 --- a/drama/templates/comments.html +++ b/drama/templates/comments.html @@ -133,7 +133,7 @@ {% if c.awards %} {% for a in c.awards[:5] %} - + {% endfor %} {% endif %} From 84e2d7a4857dfd3bf169110b4fb5733466fe1524 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 18:51:01 +0200 Subject: [PATCH 15/27] sneed --- drama/templates/submission.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drama/templates/submission.html b/drama/templates/submission.html index 0ec5ed5b82..99d53ba661 100644 --- a/drama/templates/submission.html +++ b/drama/templates/submission.html @@ -223,7 +223,7 @@ {% if p.awards %} {% for a in p.awards[:5] %} - + {% endfor %} {% endif %} From 4e2b4f46a5e5cf18eb1dab3ffc8eed0929af1e40 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 18:51:13 +0200 Subject: [PATCH 16/27] sneed --- drama/templates/submission_listing.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drama/templates/submission_listing.html b/drama/templates/submission_listing.html index 912f667ca4..0ee90c262e 100644 --- a/drama/templates/submission_listing.html +++ b/drama/templates/submission_listing.html @@ -147,7 +147,7 @@ {% if p.awards %} {% for a in p.awards[:5] %} - + {% endfor %} {% endif %} From 145711a40248b25b98a8b7bf594c57b9c429de7b Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 18:56:43 +0200 Subject: [PATCH 17/27] sneed --- drama/routes/awards.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drama/routes/awards.py b/drama/routes/awards.py index 50f473b159..34cb27a889 100644 --- a/drama/routes/awards.py +++ b/drama/routes/awards.py @@ -82,7 +82,7 @@ def award_post(pid, v): post_award.submission_id = post.id g.db.add(post_award) - msg = f"@{v.username} has given your [post]({post.permalink}) was given the {AWARDS[kind]['title']} Award!" + msg = f"@{v.username} has given your [post]({post.permalink}) the {AWARDS[kind]['title']} Award!" note = request.form.get("note", "") if note: @@ -142,7 +142,7 @@ def award_comment(cid, v): comment_award.comment_id = c.id g.db.add(comment_award) - msg = f"@{v.username} has given your [comment]({c.permalink}) was given the {AWARDS[kind]['title']} Award!" + msg = f"@{v.username} has given your [comment]({c.permalink}) the {AWARDS[kind]['title']} Award!" note = request.form.get("note", "") if note: From 3ec7098f35eb737247b2dcdd6eac66dc68ad529a Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 23:07:41 +0200 Subject: [PATCH 18/27] sneed --- drama/routes/awards.py | 52 ++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/drama/routes/awards.py b/drama/routes/awards.py index 34cb27a889..a450fc7fa1 100644 --- a/drama/routes/awards.py +++ b/drama/routes/awards.py @@ -9,19 +9,29 @@ from flask import g, jsonify, request def banaward_trigger(post=None, comment=None): author = post.author if post else comment.author + link = f"[this post]({post.permalink})" if post else f"[this comment]({comment.permalink})" - if not author.is_suspended or author.admin_level < 1: - author.ban(reason="1-day ban award used", days=1) + if author.admin_level < 1: + if not author.is_suspended: + author.ban(reason="1-day ban award used", days=1) - link = f"[this post]({post.permalink})" if post else f"[this comment]({comment.permalink})" + send_notification(1046, author, f"Your Drama account has been suspended for a day for {link}. It sucked and you should feel bad.") + elif author.unban_utc > 0: + author.unban_utc += 24*60*60 + g.db.add(author) - send_notification(1046, author, f"Your Drama account has been suspended for a day for {link}. It sucked and you should feel bad.") + send_notification(1046, author, + f"Your Drama account has been suspended for yet another day for {link}. Seriously man?") ACTIONS = { "ban": banaward_trigger } +ALLOW_MULTIPLE = ( + "ban", +) + @app.get("/api/awards") @auth_required @@ -69,17 +79,19 @@ def award_post(pid, v): if post.author_id == v.id: return jsonify({"error": "You can't award yourself."}), 403 - existing_award = g.db.query(AwardRelationship).filter( - and_( - AwardRelationship.submission_id == post.id, - AwardRelationship.user_id == v.id - ) - ).first() + # existing_award = g.db.query(AwardRelationship).filter( + # and_( + # AwardRelationship.submission_id == post.id, + # AwardRelationship.user_id == v.id, + # AwardRelationship.kind == kind + # ) + # ).first() - if existing_award: - return jsonify({"error": "You already awarded this post."}), 409 + if kind not in ALLOW_MULTIPLE: + return jsonify({"error": "You can't give that award multiple times to the same post."}), 409 post_award.submission_id = post.id + print(f"give award to pid {post_award.submission_id} ({post.id})") g.db.add(post_award) msg = f"@{v.username} has given your [post]({post.permalink}) the {AWARDS[kind]['title']} Award!" @@ -129,15 +141,15 @@ def award_comment(cid, v): if c.author_id == v.id: return jsonify({"error": "You can't award yourself."}), 403 - existing_award = g.db.query(AwardRelationship).filter( - and_( - AwardRelationship.comment_id == c.id, - AwardRelationship.user_id == v.id - ) - ).first() + # existing_award = g.db.query(AwardRelationship).filter( + # and_( + # AwardRelationship.comment_id == c.id, + # AwardRelationship.user_id == v.id + # ) + # ).first() - if existing_award: - return jsonify({"error": "You already awarded this comment."}), 409 + if kind not in ALLOW_MULTIPLE: + return jsonify({"error": "You can't give that award multiple times to the same comment."}), 409 comment_award.comment_id = c.id g.db.add(comment_award) From 95b2fbe8336c05c86c81bb1608aea3cef4134c55 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 23:16:32 +0200 Subject: [PATCH 19/27] sneed --- drama/routes/awards.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drama/routes/awards.py b/drama/routes/awards.py index a450fc7fa1..6db9d20959 100644 --- a/drama/routes/awards.py +++ b/drama/routes/awards.py @@ -79,15 +79,15 @@ def award_post(pid, v): if post.author_id == v.id: return jsonify({"error": "You can't award yourself."}), 403 - # existing_award = g.db.query(AwardRelationship).filter( - # and_( - # AwardRelationship.submission_id == post.id, - # AwardRelationship.user_id == v.id, - # AwardRelationship.kind == kind - # ) - # ).first() + existing_award = g.db.query(AwardRelationship).filter( + and_( + AwardRelationship.submission_id == post.id, + AwardRelationship.user_id == v.id, + AwardRelationship.kind == kind + ) + ).first() - if kind not in ALLOW_MULTIPLE: + if existing_award and kind not in ALLOW_MULTIPLE: return jsonify({"error": "You can't give that award multiple times to the same post."}), 409 post_award.submission_id = post.id @@ -141,14 +141,15 @@ def award_comment(cid, v): if c.author_id == v.id: return jsonify({"error": "You can't award yourself."}), 403 - # existing_award = g.db.query(AwardRelationship).filter( - # and_( - # AwardRelationship.comment_id == c.id, - # AwardRelationship.user_id == v.id - # ) - # ).first() + existing_award = g.db.query(AwardRelationship).filter( + and_( + AwardRelationship.comment_id == c.id, + AwardRelationship.user_id == v.id, + AwardRelationship.kind == kind + ) + ).first() - if kind not in ALLOW_MULTIPLE: + if existing_award and kind not in ALLOW_MULTIPLE: return jsonify({"error": "You can't give that award multiple times to the same comment."}), 409 comment_award.comment_id = c.id From bf08f1bbf69165c5960a912ff25879369244ae60 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Tue, 27 Jul 2021 23:17:01 +0200 Subject: [PATCH 20/27] sneed --- drama/routes/awards.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drama/routes/awards.py b/drama/routes/awards.py index 6db9d20959..364d4354a0 100644 --- a/drama/routes/awards.py +++ b/drama/routes/awards.py @@ -91,7 +91,7 @@ def award_post(pid, v): return jsonify({"error": "You can't give that award multiple times to the same post."}), 409 post_award.submission_id = post.id - print(f"give award to pid {post_award.submission_id} ({post.id})") + #print(f"give award to pid {post_award.submission_id} ({post.id})") g.db.add(post_award) msg = f"@{v.username} has given your [post]({post.permalink}) the {AWARDS[kind]['title']} Award!" From 749716dbcc2d7e751a341ade99df454cc7e41dfa Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Wed, 28 Jul 2021 00:28:08 +0200 Subject: [PATCH 21/27] sneed --- drama/templates/admin/admin_home.html | 1 + 1 file changed, 1 insertion(+) diff --git a/drama/templates/admin/admin_home.html b/drama/templates/admin/admin_home.html index ebfe2c2e44..0481b96a65 100644 --- a/drama/templates/admin/admin_home.html +++ b/drama/templates/admin/admin_home.html @@ -10,6 +10,7 @@
      
       

       Admin Tools

      {% filter markdown %} +* [Grant User Award](/admin/user_award) * [Advanced Stats](/api/user_stat_data) * [Ban Domain](/admin/domain/enter%20domain%20here) * [Shadowbanned Users](/admin/shadowbanned) From 72e3aabe1dc8c337ea1ed5b8d4b74d7e80391899 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Wed, 28 Jul 2021 00:28:21 +0200 Subject: [PATCH 22/27] sneed --- drama/routes/awards.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drama/routes/awards.py b/drama/routes/awards.py index 364d4354a0..79a6193fdf 100644 --- a/drama/routes/awards.py +++ b/drama/routes/awards.py @@ -167,3 +167,45 @@ def award_comment(cid, v): ACTIONS[kind](comment=c) return "", 204 + +@app.get("/admin/user_award") +@auth_required +def admin_userawards_get(v): + + if v.admin_level < 6: + abort(403) + + return render_template("admin/user_award.html", awards=list(AWARDS.values()), v=v) + +@app.post("/admin/user_award") +@auth_required +@validate_formkey +def admin_userawards_post(v): + + if v.admin_level < 6: + abort(403) + + u = get_user(request.form.get("username", '1'), graceful=False, v=v) + + awards = [] + + latest = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first() + thing = latest.id + + for key, value in request.form.items(): + if key not in AWARDS: + continue + + if value: + for x in range(int(value)): + thing += 1 + + awards.append(AwardRelationship( + id=thing, + user_id=u.id, + kind=key + )) + + g.db.bulk_save_objects(awards) + + return redirect(f'/@{u.username}') From fe5f94db94fb9435658ae867beb2dc5700e42b12 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Wed, 28 Jul 2021 00:28:30 +0200 Subject: [PATCH 23/27] sneed --- drama/templates/admin/user_award.html | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 drama/templates/admin/user_award.html diff --git a/drama/templates/admin/user_award.html b/drama/templates/admin/user_award.html new file mode 100644 index 0000000000..b089690039 --- /dev/null +++ b/drama/templates/admin/user_award.html @@ -0,0 +1,66 @@ +{% extends "default.html" %} + +{% block title %} +Grant User Award +{% endblock %} + +{% block pagetype %}message{% endblock %} + +{% block content %} + + {% if error %} + + {% endif %} + {% if msg %} + + {% endif %} + +
      
      +
      
      +
      User Award Grant
      + +
      + + + +
      + + + + + + + + + + + +{% for a in awards %} + + + + + +{% endfor %} +
      IconTitleAmount
      {{ a['title'] }}
      + + + +
      +{% endblock %} From 164aaf7edadc45873cca7727e96c09ffdf6b54bb Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Wed, 28 Jul 2021 01:16:21 +0200 Subject: [PATCH 24/27] sneed --- drama/classes/award.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drama/classes/award.py b/drama/classes/award.py index b0c0dd2104..fb62bf188f 100644 --- a/drama/classes/award.py +++ b/drama/classes/award.py @@ -16,7 +16,7 @@ AWARDS = { "shit": { "kind": "shit", "title": "Literal Shitpost", - "description": "Let OP know how much their post sucks ass.", + "description": "Let OP know how much their post sucks ass. Flies will swarm their idiotic post. (flies only work on posts lol!!)", "icon": "fas fa-poop", "color": "text-black-50" } From eee45ba85deb8281a9b9715ed3b83f5da7d230a3 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Wed, 28 Jul 2021 01:16:33 +0200 Subject: [PATCH 25/27] sneed --- drama/templates/submission.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drama/templates/submission.html b/drama/templates/submission.html index 99d53ba661..38d7ace3e4 100644 --- a/drama/templates/submission.html +++ b/drama/templates/submission.html @@ -185,6 +185,20 @@ {% endblock %} {% block content %} + +{% if p.has_award("shit") %} + + +{% endif %} +
      From f83a7db565b0b4f03d9b335c98c9cbd2fd79a733 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Wed, 28 Jul 2021 01:16:41 +0200 Subject: [PATCH 26/27] sneed --- drama/classes/submission.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drama/classes/submission.py b/drama/classes/submission.py index 3cb13d0e41..2966c50668 100644 --- a/drama/classes/submission.py +++ b/drama/classes/submission.py @@ -287,6 +287,9 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): return data + def has_award(self, kind): + return bool(len([x for x in self.awards if x.kind == kind])) + @property def voted(self): return self._voted if "_voted" in self.__dict__ else 0 From d4f801007a5395cfc4bd082ac79aba0a7c3716d9 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Wed, 28 Jul 2021 02:23:37 +0200 Subject: [PATCH 27/27] sneed --- drama/templates/submission.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drama/templates/submission.html b/drama/templates/submission.html index 02d289b3a8..0c3a676007 100644 --- a/drama/templates/submission.html +++ b/drama/templates/submission.html @@ -192,8 +192,8 @@ new BugController({ imageSprite: "/assets/js/fly-sprite.png", canDie: false, - minBugs: 80, - maxBugs: 100, + minBugs: 10, + maxBugs: 20, mouseOver: "multiply" });