diff --git a/files/classes/comment.py b/files/classes/comment.py index 39c113026..5c27257d4 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -22,6 +22,7 @@ class Comment(Base): created_utc = Column(Integer, default=0) edited_utc = Column(Integer, default=0) is_banned = Column(Boolean, default=False) + ghost = Column(Boolean) bannedfor = Column(Boolean) distinguish_level = Column(Integer, default=0) deleted_utc = Column(Integer, default=0) @@ -224,7 +225,7 @@ class Comment(Base): @property @lazy def author_name(self): - if self.award_count('ghosts') or self.post and self.post.award_count('ghosts'): return '👻' + if self.ghost: return '👻' else: return self.author.username @property @@ -310,7 +311,7 @@ class Comment(Base): if self.deleted_utc or self.is_banned: return data - data["author"]=self.author.json_core if self.author_name != '👻' else '👻' + data["author"]='👻' if self.ghost else self.author.json_core data["post"]=self.post.json_core if self.post else '' if self.level >= 2: diff --git a/files/classes/submission.py b/files/classes/submission.py index 258805f08..b61765a59 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -23,6 +23,7 @@ class Submission(Base): thumburl = Column(String) is_banned = Column(Boolean, default=False) bannedfor = Column(Boolean) + ghost = Column(Boolean) views = Column(Integer, default=0) deleted_utc = Column(Integer, default=0) distinguish_level = Column(Integer, default=0) @@ -53,6 +54,7 @@ class Submission(Base): approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True) awards = relationship("AwardRelationship", viewonly=True) reports = relationship("Flag", viewonly=True) + comments = relationship("Comment", primaryjoin="Comment.parent_submission==Submission.id", viewonly=True) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -62,7 +64,7 @@ class Submission(Base): @property @lazy - def comments(self): + def comments2(self): return g.db.query(Comment.author_id, Comment.created_utc, Comment.id).filter(Comment.parent_submission == self.id, Comment.author_id.notin_((AUTOPOLLER_ID,AUTOBETTER_ID))).all() @property @@ -222,7 +224,7 @@ class Submission(Base): @property @lazy def author_name(self): - if self.award_count('ghosts'): return '👻' + if self.ghost: return '👻' else: return self.author.username @property @@ -321,7 +323,7 @@ class Submission(Base): if self.deleted_utc or self.is_banned: return data - data["author"]=self.author.json_core + data["author"]='👻' if self.ghost else self.author.json_core data["comment_count"]=self.comment_count diff --git a/files/routes/awards.py b/files/routes/awards.py index 8e07386d3..3571f1aa6 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -268,6 +268,9 @@ def award_post(pid, v): else: post.stickied_utc = t g.db.add(post) elif kind == "agendaposter" and not (author.agendaposter and author.agendaposter_expires_utc == 0): + if author.marseyawarded: + return {"error": "This user is the under the effect of a conflicting award: Marsey award."}, 404 + if author.username == "911roofer": abort(403) if author.agendaposter_expires_utc and time.time() < author.agendaposter_expires_utc: author.agendaposter_expires_utc += 86400 else: author.agendaposter_expires_utc = int(time.time()) + 86400 @@ -366,6 +369,12 @@ def award_post(pid, v): badge = Badge(user_id=v.id, badge_id=103) g.db.add(badge) send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n![]({badge.path})\n\n{badge.name}") + elif kind == "ghosts": + post.ghost = True + g.db.add(post) + for c in post.comments: + c.ghost = True + g.db.add(c) if post.author.received_award_count: post.author.received_award_count += 1 else: post.author.received_award_count = 1 @@ -466,6 +475,9 @@ def award_comment(cid, v): else: c.is_pinned_utc = t g.db.add(c) elif kind == "agendaposter" and not (author.agendaposter and author.agendaposter_expires_utc == 0): + if author.marseyawarded: + return {"error": "This user is the under the effect of a conflicting award: Marsey award."}, 404 + if author.username == "911roofer": abort(403) if author.agendaposter_expires_utc and time.time() < author.agendaposter_expires_utc: author.agendaposter_expires_utc += 86400 else: author.agendaposter_expires_utc = int(time.time()) + 86400 @@ -564,6 +576,9 @@ def award_comment(cid, v): badge = Badge(user_id=v.id, badge_id=103) g.db.add(badge) send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n![]({badge.path})\n\n{badge.name}") + elif kind == "ghosts": + c.ghost = True + g.db.add(c) if c.author.received_award_count: c.author.received_award_count += 1 else: c.author.received_award_count = 1 diff --git a/files/routes/users.py b/files/routes/users.py index 1263e6a73..15af102a1 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -111,13 +111,12 @@ def downvoters(v, username): @app.get("/@/upvoting") @auth_required -@cache.memoize(timeout=3600) def upvoting(v, username): id = get_user(username).id - votes = g.db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==1, Vote.user_id==id).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all() + votes = g.db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost==None, Vote.vote_type==1, Vote.user_id==id).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all() - votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==1, CommentVote.user_id==id).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all() + votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost==None, CommentVote.vote_type==1, CommentVote.user_id==id).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all() votes = Counter(dict(votes)) + Counter(dict(votes2)) @@ -131,13 +130,12 @@ def upvoting(v, username): @app.get("/@/downvoting") @auth_required -@cache.memoize(timeout=3600) def downvoting(v, username): id = get_user(username).id - votes = g.db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==-1, Vote.user_id==id).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all() + votes = g.db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost==None, Vote.vote_type==-1, Vote.user_id==id).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all() - votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==-1, CommentVote.user_id==id).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all() + votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost==None, CommentVote.vote_type==-1, CommentVote.user_id==id).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all() votes = Counter(dict(votes)) + Counter(dict(votes2)) diff --git a/files/routes/votes.py b/files/routes/votes.py index 7f2d2aa6d..522c21adc 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -22,7 +22,7 @@ def admin_vote_info_get(v): else: abort(400) except: abort(400) - if thing.author_name == '👻': abort(403) + if thing.ghost: abort(403) if isinstance(thing, Submission): if thing.author.shadowbanned and not (v and v.admin_level): diff --git a/files/templates/comments.html b/files/templates/comments.html index 698eb8625..89f022122 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -178,9 +178,9 @@ {% set isreply = False %} {% endif %} -
+
{% if not isreply %} - + {% endif %}
@@ -207,15 +207,15 @@ {% endif %} {% if c.distinguish_level %}{% endif %} - {% if c.is_op and c.author_name != '👻' %}{% endif %} + {% if c.is_op and not c.ghost %}{% endif %} {% if c.is_bot %}{% endif %} {% if c.is_blocking %}{% endif %} {% if c.is_blocked %}{% endif %} - {% if c.author.verified and c.author_name != '👻' %} + {% if c.author.verified and not c.ghost %} {% endif %} - {% if c.author_name == '👻' %} + {% if c.ghost %} 👻 {% else %} @{{c.author_name}}'s profile picture{{c.author_name}} @@ -251,7 +251,7 @@
{{c.realbody(v) | safe}} - {% if c.author.sig_html and c.author_name != '👻' and (c.author_id == MOOSE_ID or not (v and v.sigs_disabled)) %} + {% if c.author.sig_html and not c.ghost and (c.author_id == MOOSE_ID or not (v and v.sigs_disabled)) %}
{{c.author.sig_html | safe}} {% endif %} @@ -397,7 +397,7 @@ {% endif %} - {% if c.author_name != '👻' %}Votes{% endif %} + {% if not c.ghost %}Votes{% endif %} {% if v %} @@ -436,7 +436,7 @@ {% endif %} - {% if v and v.id != c.author_id and c.author_name != '👻' %} + {% if v and v.id != c.author_id and not c.ghost %} @@ -579,7 +579,7 @@