diff --git a/files/classes/comment.py b/files/classes/comment.py index bc4d21d84..8384e6aa1 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -398,7 +398,7 @@ class Comment(Base): @lazy def filtered_flags(self, v): - return [f for f in self.flags if (v and v.shadowbanned) or not f.user.shadowbanned] + return [f for f in self.flags if not f.user.shadowbanned or (v and v.id == f.user_id) or (v and v.admin_level)] @lazy def active_flags(self, v): diff --git a/files/classes/submission.py b/files/classes/submission.py index ce42e266f..de708d090 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -365,7 +365,7 @@ class Submission(Base): @lazy def filtered_flags(self, v): - return [f for f in self.flags if (v and v.shadowbanned) or not f.user.shadowbanned] + return [f for f in self.flags if not f.user.shadowbanned or (v and v.id == f.user_id) or (v and v.admin_level)] @lazy def active_flags(self, v): diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 7f3d02630..fcc84276d 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -467,33 +467,47 @@ def execute_antispam_comment_check(body:str, v:User): g.db.commit() abort(403, "Too much spam!") -def execute_under_siege(v:User, target:Optional[Union[Submission, Comment]], body, type:str) -> bool: - if not get_setting("under_siege"): return True +def execute_under_siege(v:User, target:Optional[Union[Submission, Comment]], body, kind:str) -> bool: + if not get_setting("under_siege"): return + if v.shadowbanned: return + if v.admin_level >= PERMS['SITE_BYPASS_UNDER_SIEGE_MODE']: return - unshadowbannedcels = [x[0] for x in g.db.query(ModAction.target_user_id).filter_by(kind='unshadowban').all()] - if v.id in unshadowbannedcels: return True - - if type in ('report', 'message'): + if kind in {'message', 'report'}: threshold = 86400 else: threshold = UNDER_SIEGE_AGE_THRESHOLD - if not v.shadowbanned and v.age < threshold and not v.admin_level >= PERMS['SITE_BYPASS_UNDER_SIEGE_MODE']: - v.shadowbanned = AUTOJANNY_ID + if v.age > threshold: return - ma = ModAction( - kind="shadowban", - user_id=AUTOJANNY_ID, - target_user_id=v.id, - _note=f'reason: "Under Siege ({type}, {v.age} seconds)"' - ) - g.db.add(ma) + unshadowbannedcels = [x[0] for x in g.db.query(ModAction.target_user_id).filter_by(kind='unshadowban').all()] + if v.id in unshadowbannedcels: return + + v.shadowbanned = AUTOJANNY_ID + v.ban_reason = "Under Siege" + g.db.add(v) + + if kind == "report": + if isinstance(target, Submission): + reason = f'report on post' + else: + reason = f'report on comment' + else: + reason = kind + + ma = ModAction( + kind="shadowban", + user_id=AUTOJANNY_ID, + target_user_id=v.id, + _note=f'reason: "Under Siege ({reason}, {v.age} seconds)"' + ) + g.db.add(ma) + + if kind == 'message': + notified_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['BLACKJACK_NOTIFICATIONS'])] + for uid in notified_ids: + n = Notification(comment_id=target.id, user_id=uid) + g.db.add(n) - v.ban_reason = "Under Siege" - g.db.add(v) - t = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time())) - return False - return True def execute_lawlz_actions(v:User, p:Submission): if v.id != LAWLZ_ID: return diff --git a/files/templates/comments.html b/files/templates/comments.html index 02d4d2706..142fdcca5 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -234,16 +234,8 @@ {{c.blackjack_html | safe}} {% endif %} - {% if c.active_flags(v) %} -
- Reported by: - -
- {% endif %} + + {{macros.flags(c)}} {% if c.is_banned and c.ban_reason %}
removed by @{{c.ban_reason}} (Admin)
diff --git a/files/templates/submission.html b/files/templates/submission.html index ed3dac10d..bf4b60090 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -74,18 +74,11 @@
- {{ macros.post_meta(p) }} + {{macros.post_meta(p)}}
- {% if p.active_flags(v) %} -
- Reported by: - -
- {% endif %} + + {{macros.flags(p)}} + {% if p.realurl(v) and not v_forbid_deleted %}

diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index e1dee88e8..aba83d27c 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -26,16 +26,7 @@ {% set v_forbid_deleted = (p.deleted_utc != 0 or p.is_banned) and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == p.author_id) %} -{% if p.active_flags(v) %} -
- Reported by: - -
-{% endif %} +{{macros.flags(p)}}
diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index bb5f8a03f..d3f700cb9 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -196,3 +196,25 @@
{% endif %} {% endmacro %} + +{% macro flags(i) %} +{% if i.active_flags(v) %} +
+ Reported by: +
    + {% for f in i.filtered_flags(v) %} +
  • + {% if v and v.admin_level %} + + {% endif %} + {{f.user.username}} + {% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} + {% if v and v.admin_level >= PERMS['FLAGS_REMOVE'] %} + + {% endif %} +
  • + {% endfor %} +
+
+{% endif %} +{% endmacro %}