Rejigger the Mod/Report state system.

This commit is contained in:
Ben Rog-Wilhelm 2023-06-25 20:46:24 -05:00
parent 31ebdd0213
commit ccf809406e
36 changed files with 492 additions and 226 deletions

View file

@ -5,6 +5,7 @@ from datetime import datetime
import requests
from files.classes import *
from files.classes.visstate import StateMod, StateReport
from files.helpers.alerts import *
from files.helpers.caching import invalidate_cache
from files.helpers.comments import comment_on_publish, comment_on_unpublish
@ -136,8 +137,8 @@ def revert_actions(v, username):
comments = g.db.query(Comment).filter(Comment.id.in_(comments)).all()
for item in posts + comments:
item.is_banned = False
item.ban_reason = None
item.state_mod = StateMod.VISIBLE
item.state_mod_set_by = v.username
g.db.add(item)
users = (x[0] for x in g.db.query(ModAction.target_user_id).filter(ModAction.user_id == user.id, ModAction.created_utc > cutoff, ModAction.kind.in_(('shadowban', 'ban_user'))).all())
@ -235,7 +236,7 @@ def filtered_submissions(v):
posts_just_ids = g.db.query(Submission) \
.order_by(Submission.id.desc()) \
.filter(Submission.filter_state == 'filtered') \
.filter(Submission.state_mod == StateMod.FILTERED) \
.limit(26) \
.offset(25 * (page - 1)) \
.with_entities(Submission.id)
@ -255,7 +256,7 @@ def filtered_comments(v):
comments_just_ids = g.db.query(Comment) \
.order_by(Comment.id.desc()) \
.filter(Comment.filter_state == 'filtered') \
.filter(Comment.state_mod == StateMod.FILTERED) \
.limit(26) \
.offset(25 * (page - 1)) \
.with_entities(Comment.id)
@ -266,6 +267,9 @@ def filtered_comments(v):
return render_template("admin/filtered_comments.html", v=v, listing=comments, next_exists=next_exists, page=page, sort="new")
# NOTE:
# This function is pretty grimy and should be rolled into the Remove/Unremove functions.
# (also rename Unremove to Approve, sigh)
@app.post("/admin/update_filter_status")
@limiter.exempt
@admin_level_required(2)
@ -277,29 +281,48 @@ def update_filter_status(v):
if new_status not in ['normal', 'removed', 'ignored']:
return { 'result': f'Status of {new_status} is not permitted' }
if new_status == 'normal':
state_mod_new = StateMod.VISIBLE
state_report_new = StateReport.RESOLVED
elif new_status == 'removed':
state_mod_new = StateMod.REMOVED
state_report_new = StateReport.RESOLVED
elif new_status == 'ignored':
state_mod_new = None # we just leave this as-is
state_report_new = StateReport.IGNORED
if post_id:
target = g.db.get(Submission, post_id)
old_status = target.filter_state
rows_updated = g.db.query(Submission).where(Submission.id == post_id) \
.update({Submission.filter_state: new_status})
old_status = target.state_mod
# this could totally be one query but it would be kinda ugly
if state_mod_new is not None:
g.db.query(Submission).where(Submission.id == post_id) \
.update({Submission.state_mod: state_mod_new, Submission.state_mod_set_by: v.username})
g.db.query(Submission).where(Submission.id == post_id) \
.update({Submission.state_report: state_report_new})
elif comment_id:
target = g.db.get(Comment, comment_id)
old_status = target.filter_state
rows_updated = g.db.query(Comment).where(Comment.id == comment_id) \
.update({Comment.filter_state: new_status})
old_status = target.state_mod
if state_mod_new is not None:
g.db.query(Comment).where(Comment.id == comment_id) \
.update({Comment.state_mod: state_mod_new, Comment.state_mod_set_by: v.username})
g.db.query(Comment).where(Comment.id == comment_id) \
.update({Comment.state_report: state_report_new})
else:
return { 'result': f'No valid item ID provided' }
if rows_updated == 1:
if target is not None:
# If comment now visible, update state to reflect publication.
if (isinstance(target, Comment)
and old_status in ['filtered', 'removed']
and new_status in ['normal', 'ignored']):
and old_status != StateMod.VISIBLE
and state_mod_new == StateMod.VISIBLE):
comment_on_publish(target) # XXX: can cause discrepancies if removal state ≠ filter state
if (isinstance(target, Comment)
and old_status in ['normal', 'ignored']
and new_status in ['filtered', 'removed']):
and old_status == StateMod.VISIBLE
and state_mod_new != StateMod.VISIBLE and state_mod_new is not None):
comment_on_unpublish(target) # XXX: can cause discrepancies if removal state ≠ filter state
g.db.commit()
@ -332,7 +355,7 @@ def reported_posts(v):
page = max(1, int(request.values.get("page", 1)))
subs_just_ids = g.db.query(Submission) \
.filter(Submission.filter_state == 'reported') \
.filter(Submission.state_report == StateReport.REPORTED) \
.order_by(Submission.id.desc()) \
.offset(25 * (page - 1)) \
.limit(26) \
@ -351,13 +374,8 @@ def reported_posts(v):
def reported_comments(v):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Comment
).filter_by(
is_approved=None,
is_banned=False
).join(Comment.reports).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all()
comments_just_ids = g.db.query(Comment) \
.filter(Comment.filter_state == 'reported') \
.filter(Comment.state_report == StateReport.REPORTED) \
.order_by(Comment.id.desc()) \
.offset(25 * (page - 1)) \
.limit(26) \
@ -415,7 +433,8 @@ def change_settings(v, setting):
level=1,
body_html=body_html,
sentto=MODMAIL_ID,
distinguish_level=6
distinguish_level=6,
state_mod=StateMod.VISIBLE,
)
g.db.add(new_comment)
g.db.flush()
@ -765,7 +784,7 @@ def admin_removed(v):
if page < 1: abort(400)
ids = g.db.query(Submission.id).join(User, User.id == Submission.author_id).filter(or_(Submission.is_banned==True, User.shadowbanned != None)).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26).all()
ids = g.db.query(Submission.id).join(User, User.id == Submission.author_id).filter(or_(Submission.state_mod == StateMod.REMOVED, User.shadowbanned != None)).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26).all()
ids=[x[0] for x in ids]
@ -790,7 +809,7 @@ def admin_removed_comments(v):
try: page = int(request.values.get("page", 1))
except: page = 1
ids = g.db.query(Comment.id).join(User, User.id == Comment.author_id).filter(or_(Comment.is_banned==True, User.shadowbanned != None)).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all()
ids = g.db.query(Comment.id).join(User, User.id == Comment.author_id).filter(or_(Comment.state_mode == StateMod.REMOVED, User.shadowbanned != None)).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all()
ids=[x[0] for x in ids]
@ -840,7 +859,8 @@ def shadowban(user_id, v):
parent_submission=None,
level=1,
body_html=body_html,
distinguish_level=6
distinguish_level=6,
state_mod=StateMod.VISIBLE,
)
g.db.add(new_comment)
g.db.flush()
@ -1025,7 +1045,8 @@ def ban_user(user_id, v):
parent_submission=None,
level=1,
body_html=body_html,
distinguish_level=6
distinguish_level=6,
state_mod=StateMod.VISIBLE,
)
g.db.add(new_comment)
g.db.flush()
@ -1088,11 +1109,10 @@ def remove_post(post_id, v):
if not post:
abort(400)
post.is_banned = True
post.is_approved = None
post.state_mod = StateMod.REMOVED
post.state_mod_set_by = v.username
post.stickied = None
post.is_pinned = False
post.ban_reason = v.username
g.db.add(post)
@ -1125,7 +1145,7 @@ def unremove_post(post_id, v):
if not post:
abort(400)
if post.is_banned:
if post.state_mod != StateMod.VISIBLE:
ma=ModAction(
kind="unremove_post",
user_id=v.id,
@ -1133,9 +1153,8 @@ def unremove_post(post_id, v):
)
g.db.add(ma)
post.is_banned = False
post.ban_reason = None
post.is_approved = v.id
post.state_mod = StateMod.VISIBLE
post.state_mod_set_by = v.username
g.db.add(post)
@ -1187,7 +1206,7 @@ def api_distinguish_post(post_id, v):
def sticky_post(post_id, v):
post = g.db.query(Submission).filter_by(id=post_id).one_or_none()
if post and not post.stickied:
pins = g.db.query(Submission.id).filter(Submission.stickied != None, Submission.is_banned == False).count()
pins = g.db.query(Submission.id).filter(Submission.stickied != None, Submission.state_mod == StateMod.VISIBLE).count()
if pins > 2:
if v.admin_level >= 2:
post.stickied = v.username
@ -1296,9 +1315,8 @@ def api_remove_comment(c_id, v):
if not comment:
abort(404)
comment.is_banned = True
comment.is_approved = None
comment.ban_reason = v.username
comment.state_mod = StateMod.REMOVED
comment.state_mod_set_by = v.username
comment_on_unpublish(comment) # XXX: can cause discrepancies if removal state ≠ filter state
ma=ModAction(
kind="remove_comment",
@ -1317,7 +1335,7 @@ def api_unremove_comment(c_id, v):
comment = g.db.query(Comment).filter_by(id=c_id).one_or_none()
if not comment: abort(404)
if comment.is_banned:
if comment.state_mod == StateMod.REMOVED:
ma=ModAction(
kind="unremove_comment",
user_id=v.id,
@ -1325,9 +1343,8 @@ def api_unremove_comment(c_id, v):
)
g.db.add(ma)
comment.is_banned = False
comment.ban_reason = None
comment.is_approved = v.id
comment.state_mod = StateMod.VISIBLE
comment.state_mod_set_by = v.username
comment_on_publish(comment) # XXX: can cause discrepancies if removal state ≠ filter state
g.db.add(comment)
@ -1426,24 +1443,24 @@ def admin_toggle_ban_domain(v):
@app.post("/admin/nuke_user")
@limiter.exempt
@admin_level_required(2)
@admin_level_required(3)
def admin_nuke_user(v):
user=get_user(request.values.get("user"))
for post in g.db.query(Submission).filter_by(author_id=user.id).all():
if post.is_banned:
if post.state_mod != StateMod.REMOVED:
continue
post.is_banned = True
post.ban_reason = v.username
post.state_mod = StateMod.REMOVED
post.state_mod_set_by = v.username
g.db.add(post)
for comment in g.db.query(Comment).filter_by(author_id=user.id).all():
if comment.is_banned:
if comment.state_mod != StateMod.REMOVED:
continue
comment.is_banned = True
comment.ban_reason = v.username
comment.state_mod = StateMod.REMOVED
comment.state_mod_set_by = v.username
g.db.add(comment)
ma=ModAction(
@ -1460,24 +1477,24 @@ def admin_nuke_user(v):
@app.post("/admin/unnuke_user")
@limiter.exempt
@admin_level_required(2)
def admin_nunuke_user(v):
@admin_level_required(3)
def admin_unnuke_user(v):
user=get_user(request.values.get("user"))
for post in g.db.query(Submission).filter_by(author_id=user.id).all():
if not post.is_banned:
if post.state_mod == StateMod.VISIBLE:
continue
post.is_banned = False
post.ban_reason = None
post.state_mod = StateMod.VISIBLE
post.state_mod_set_by = v.username
g.db.add(post)
for comment in g.db.query(Comment).filter_by(author_id=user.id).all():
if not comment.is_banned:
if comment.state_mod == StateMod.VISIBLE:
continue
comment.is_banned = False
comment.ban_reason = None
comment.state_mod = StateMod.VISIBLE
comment.state_mod_set_by = v.username
g.db.add(comment)
ma=ModAction(

View file

@ -1,5 +1,6 @@
from files.__main__ import app, limiter
from files.classes import *
from files.classes.visstate import StateMod
from files.helpers.alerts import *
from files.helpers.comments import comment_on_publish
from files.helpers.config.const import *
@ -97,7 +98,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
if request.headers.get("Authorization"): return top_comment.json
else:
if post.is_banned and not (v and (v.admin_level >= 2 or post.author_id == v.id)): template = "submission_banned.html"
if post.state_mod != StateMod.VISIBLE and not (v and (v.admin_level >= 2 or post.author_id == v.id)): template = "submission_banned.html"
else: template = "submission.html"
return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True)
@ -188,8 +189,8 @@ def api_comment(v):
days=1)
for comment in similar_comments:
comment.is_banned = True
comment.ban_reason = "AutoJanny"
comment.state_mod = StateMod.REMOVED
comment.state_mod_set_by = "AutoJanny"
g.db.add(comment)
ma=ModAction(
user_id=AUTOJANNY_ID,
@ -213,7 +214,7 @@ def api_comment(v):
body_html=body_html,
body=body[:COMMENT_BODY_LENGTH_MAXIMUM],
ghost=parent_post.ghost,
filter_state='filtered' if is_filtered else 'normal'
state_mod=StateMod.FILTERED if is_filtered else StateMod.VISIBLE,
)
c.upvotes = 1
@ -287,8 +288,8 @@ def edit_comment(cid, v):
days=1)
for comment in similar_comments:
comment.is_banned = True
comment.ban_reason = "AutoJanny"
comment.state_mod = StateMod.REMOVED
comment.state_mod_set_by = "AutoJanny"
g.db.add(comment)
abort(403, "Too much spam!")
@ -313,7 +314,7 @@ def edit_comment(cid, v):
g.db.add(c)
if c.filter_state != 'filtered':
if c.state_mod == StateMod.VISIBLE:
notify_users = NOTIFY_USERS(body, v)
for x in notify_users:

View file

@ -3,6 +3,7 @@ from sqlalchemy.orm import Query
import files.helpers.listing as listing
from files.__main__ import app, limiter
from files.classes.submission import Submission
from files.classes.visstate import StateMod
from files.helpers.comments import comment_filter_moderated
from files.helpers.contentsorting import (apply_time_filter,
sort_comment_results, sort_objects)
@ -26,7 +27,7 @@ def unread(v):
listing = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(
Notification.read == False,
Notification.user_id == v.id,
Comment.is_banned == False,
Comment.state_mod == StateMod.VISIBLE,
Comment.state_user_deleted_utc == None,
Comment.author_id != AUTOJANNY_ID,
).order_by(Notification.created_utc.desc()).all()
@ -100,7 +101,7 @@ def notifications(v):
else:
comments = g.db.query(Comment, Notification).join(Notification, Notification.comment_id == Comment.id).filter(
Notification.user_id == v.id,
Comment.is_banned == False,
Comment.state_mod == StateMod.VISIBLE,
Comment.state_user_deleted_utc == None,
Comment.author_id != AUTOJANNY_ID,
Comment.body_html.notlike('%<p>New site mention: <a href="https://old.reddit.com/r/%')
@ -250,7 +251,7 @@ def changelog(v):
@app.get("/random_post")
def random_post():
p = g.db.query(Submission.id).filter(Submission.state_user_deleted_utc == None, Submission.is_banned == False, Submission.private == False).order_by(func.random()).first()
p = g.db.query(Submission.id).filter(Submission.state_user_deleted_utc == None, Submission.state_mod == StateMod.VISIBLE, Submission.private == False).order_by(func.random()).first()
if p: p = p[0]
else: abort(404)
@ -307,11 +308,10 @@ def get_comments_idlist(page=1, v=None, sort="new", t="all", gt=0, lt=0):
if v.admin_level < 2:
comments = comments.filter(
Comment.author_id.notin_(v.userblocks),
Comment.is_banned == False,
Comment.state_mod == StateMod.VISIBLE,
Comment.state_user_deleted_utc == None,
Submission.private == False, # comment parent post not private
User.shadowbanned == None, # comment author not shadowbanned
Comment.filter_state.notin_(('filtered', 'removed')),
)
if gt: comments = comments.filter(Comment.created_utc > gt)

View file

@ -62,7 +62,8 @@ def request_api_keys(v):
level=1,
body_html=body_html,
sentto=MODMAIL_ID,
distinguish_level=6
distinguish_level=6,
state_mod=StateMod.VISIBLE,
)
g.db.add(new_comment)
g.db.flush()

View file

@ -15,6 +15,7 @@ from sqlalchemy.orm import Query
import files.helpers.validators as validators
from files.__main__ import app, db_session, limiter
from files.classes import *
from files.classes.visstate import StateMod
from files.helpers.alerts import *
from files.helpers.caching import invalidate_cache
from files.helpers.config.const import *
@ -120,7 +121,7 @@ def post_id(pid, anything=None, v=None):
if request.headers.get("Authorization"): return post.json
else:
if post.is_banned and not (v and (v.admin_level >= 2 or post.author_id == v.id)): template = "submission_banned.html"
if post.state_mod != StateMod.VISIBLE and not (v and (v.admin_level >= 2 or post.author_id == v.id)): template = "submission_banned.html"
else: template = "submission.html"
return render_template(template, v=v, p=post, ids=list(ids), sort=sort, render_replies=True, offset=offset)
@ -431,7 +432,7 @@ def api_is_repost():
repost = g.db.query(Submission).filter(
Submission.url.ilike(search_url),
Submission.state_user_deleted_utc == None,
Submission.is_banned == False
Submission.state_mod == StateMod.VISIBLE
).first()
if repost: return {'permalink': repost.permalink}
else: return {'permalink': ''}
@ -468,9 +469,9 @@ def _do_antispam_submission_check(v:User, validated:validators.ValidatedSubmissi
v.ban(reason="Spamming.", days=1)
for post in similar_posts + similar_urls:
post.is_banned = True
post.state_mod = StateMod.REMOVED
post.state_mod_set_by = "AutoJanny"
post.is_pinned = False
post.ban_reason = "AutoJanny"
g.db.add(post)
ma=ModAction(
user_id=AUTOJANNY_ID,
@ -497,7 +498,7 @@ def _duplicate_check(search_url:Optional[str]) -> Optional[werkzeug.wrappers.Res
repost = g.db.query(Submission).filter(
func.lower(Submission.url) == search_url.lower(),
Submission.state_user_deleted_utc == None,
Submission.is_banned == False
Submission.state_mod == StateMod.VISIBLE
).first()
if repost and SITE != 'localhost':
return redirect(repost.permalink)
@ -577,7 +578,7 @@ def submit_post(v):
title=validated_post.title,
title_html=validated_post.title_html,
ghost=False,
filter_state='filtered' if v.admin_level == 0 and app.config['SETTINGS']['FilterNewPosts'] else 'normal',
state_mod=StateMod.FILTERED if v.admin_level == 0 and app.config['SETTINGS']['FilterNewPosts'] else StateMod.VISIBLE,
thumburl=validated_post.thumburl
)
post.submit(g.db)

View file

@ -1,6 +1,7 @@
from flask import g
from files.__main__ import app, limiter
from files.classes.visstate import StateReport
from files.helpers.get import *
from files.helpers.sanitize import filter_emojis_only
from files.helpers.wrappers import *
@ -31,8 +32,8 @@ def api_flag_post(pid, v):
# We only want to notify if the user is not permabanned
if not v.is_suspended_permanently:
g.db.query(Submission) \
.where(Submission.id == post.id, Submission.filter_state != 'ignored') \
.update({Submission.filter_state: 'reported'})
.where(Submission.id == post.id, Submission.state_report != StateReport.IGNORED) \
.update({Submission.state_report: StateReport.REPORTED})
g.db.commit()
@ -53,8 +54,9 @@ def api_flag_comment(cid, v):
# We only want to notify if the user is not permabanned
if not v.is_suspended_permanently:
g.db.query(Comment) \
.where(Comment.id == comment.id, Comment.filter_state != 'ignored') \
.update({Comment.filter_state: 'reported'})
.where(Comment.id == comment.id, Comment.state_report != StateReport.IGNORED) \
.update({Comment.state_report: StateReport.REPORTED})
g.db.commit()

View file

@ -1,6 +1,7 @@
from sqlalchemy import *
from files.__main__ import app
from files.classes.visstate import StateMod
from files.helpers.contentsorting import apply_time_filter, sort_objects
from files.helpers.strings import sql_ilike_clean
from files.helpers.wrappers import *
@ -44,9 +45,9 @@ def searchposts(v):
if not (v and v.paid_dues): posts = posts.filter_by(club=False)
if v and v.admin_level < 2:
posts = posts.filter(Submission.state_user_deleted_utc == None, Submission.is_banned == False, Submission.private == False, Submission.author_id.notin_(v.userblocks))
posts = posts.filter(Submission.state_user_deleted_utc == None, Submission.state_mod == StateMod.VISIBLE, Submission.private == False, Submission.author_id.notin_(v.userblocks))
elif not v:
posts = posts.filter(Submission.state_user_deleted_utc == None, Submission.is_banned == False, Submission.private == False)
posts = posts.filter(Submission.state_user_deleted_utc == None, Submission.state_mod == StateMod.VISIBLE, Submission.private == False)
if 'author' in criteria:
@ -168,10 +169,10 @@ def searchcomments(v):
if v and v.admin_level < 2:
private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()]
comments = comments.filter(Comment.author_id.notin_(v.userblocks), Comment.is_banned==False, Comment.state_user_deleted_utc == None, Comment.parent_submission.notin_(private))
comments = comments.filter(Comment.author_id.notin_(v.userblocks), Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == None, Comment.parent_submission.notin_(private))
elif not v:
private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()]
comments = comments.filter(Comment.is_banned==False, Comment.state_user_deleted_utc == None, Comment.parent_submission.notin_(private))
comments = comments.filter(Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == None, Comment.parent_submission.notin_(private))
if not (v and v.paid_dues):

View file

@ -6,6 +6,7 @@ from sqlalchemy import func
from files.classes.award import AWARDS
from files.classes.badges import BadgeDef
from files.classes.mod_logs import ACTIONTYPES, ACTIONTYPES2
from files.classes.visstate import StateMod
from files.helpers.alerts import *
from files.helpers.captcha import validate_captcha
from files.helpers.config.const import *
@ -77,13 +78,13 @@ def participation_stats(v):
"signups last 24h": users.filter(User.created_utc > day).count(),
"total posts": submissions.count(),
"posting users": g.db.query(Submission.author_id).distinct().count(),
"listed posts": submissions.filter_by(is_banned=False).filter(Submission.state_user_deleted_utc == None).count(),
"removed posts (by admins)": submissions.filter_by(is_banned=True).count(),
"listed posts": submissions.filter_by(Submission.state_mod == StateMod.VISIBLE).filter(Submission.state_user_deleted_utc == None).count(),
"removed posts (by admins)": submissions.filter_by(Submission.state_mod != StateMod.VISIBLE).count(),
"deleted posts (by author)": submissions.filter(Submission.state_user_deleted_utc != None).count(),
"posts last 24h": submissions.filter(Submission.created_utc > day).count(),
"total comments": comments.filter(Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
"commenting users": g.db.query(Comment.author_id).distinct().count(),
"removed comments (by admins)": comments.filter_by(is_banned=True).count(),
"removed comments (by admins)": comments.filter_by(Comment.state_mod != StateMod.VISIBLE).count(),
"deleted comments (by author)": comments.filter(Comment.state_user_deleted_utc != None).count(),
"comments last_24h": comments.filter(Comment.created_utc > day, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
"post votes": g.db.query(Vote.submission_id).count(),
@ -142,9 +143,9 @@ def cached_chart(kind, site):
daily_signups = [g.db.query(User.id).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][::-1]
post_stats = [g.db.query(Submission.id).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.is_banned == False).count() for i in range(len(day_cutoffs) - 1)][::-1]
post_stats = [g.db.query(Submission.id).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.state_mod == StateMod.VISIBLE).count() for i in range(len(day_cutoffs) - 1)][::-1]
comment_stats = [g.db.query(Comment.id).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count() for i in range(len(day_cutoffs) - 1)][::-1]
comment_stats = [g.db.query(Comment.id).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.state_mod == StateMod.VISIBLE, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count() for i in range(len(day_cutoffs) - 1)][::-1]
plt.rcParams["figure.figsize"] = (30, 20)
@ -310,6 +311,7 @@ def submit_contact(v: Optional[User]):
level=1,
body_html=html,
sentto=MODMAIL_ID,
state_mod=StateMod.VISIBLE,
)
g.db.add(new_comment)
g.db.flush()

View file

@ -12,6 +12,7 @@ from files.__main__ import app, cache, limiter
from files.classes.leaderboard import (BadgeMarseyLeaderboard, LeaderboardMeta,
SimpleLeaderboard, UserBlockLeaderboard)
from files.classes.views import ViewerRelationship
from files.classes.visstate import StateMod
from files.helpers.alerts import *
from files.helpers.assetcache import assetcache_path
from files.helpers.config.const import *
@ -39,7 +40,7 @@ def upvoters_posts(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.is_banned == False, Submission.state_user_deleted_utc == None, Vote.vote_type==1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.state_mod == StateMod.VISIBLE, Submission.state_user_deleted_utc == None, Vote.vote_type==1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [p.id for p in listing]
next_exists = len(listing) > 25
@ -60,7 +61,7 @@ def upvoters_comments(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.is_banned == False, Comment.state_user_deleted_utc == None, CommentVote.vote_type==1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == None, CommentVote.vote_type==1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [c.id for c in listing]
next_exists = len(listing) > 25
@ -81,7 +82,7 @@ def downvoters_posts(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.is_banned == False, Submission.state_user_deleted_utc == None, Vote.vote_type==-1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.state_mod == StateMod.VISIBLE, Submission.state_user_deleted_utc == None, Vote.vote_type==-1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [p.id for p in listing]
next_exists = len(listing) > 25
@ -102,7 +103,7 @@ def downvoters_comments(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.is_banned == False, Comment.state_user_deleted_utc == None, CommentVote.vote_type==-1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == None, CommentVote.vote_type==-1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [c.id for c in listing]
next_exists = len(listing) > 25
@ -122,7 +123,7 @@ def upvoting_posts(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.is_banned == False, Submission.state_user_deleted_utc == None, Vote.vote_type==1, Vote.user_id==id, Submission.author_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.state_mod == StateMod.VISIBLE, Submission.state_user_deleted_utc == None, Vote.vote_type==1, Vote.user_id==id, Submission.author_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [p.id for p in listing]
next_exists = len(listing) > 25
@ -143,7 +144,7 @@ def upvoting_comments(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.is_banned == False, Comment.state_user_deleted_utc == None, CommentVote.vote_type==1, CommentVote.user_id==id, Comment.author_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == None, CommentVote.vote_type==1, CommentVote.user_id==id, Comment.author_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [c.id for c in listing]
next_exists = len(listing) > 25
@ -164,7 +165,7 @@ def downvoting_posts(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.is_banned == False, Submission.state_user_deleted_utc == None, Vote.vote_type==-1, Vote.user_id==id, Submission.author_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.state_mod == StateMod.VISIBLE, Submission.state_user_deleted_utc == None, Vote.vote_type==-1, Vote.user_id==id, Submission.author_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [p.id for p in listing]
next_exists = len(listing) > 25
@ -185,7 +186,7 @@ def downvoting_comments(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.is_banned == False, Comment.state_user_deleted_utc == None, CommentVote.vote_type==-1, CommentVote.user_id==id, Comment.author_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == None, CommentVote.vote_type==-1, CommentVote.user_id==id, Comment.author_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [c.id for c in listing]
next_exists = len(listing) > 25
@ -200,9 +201,9 @@ def downvoting_comments(v, username, uid):
def upvoters(v, username):
id = get_user(username).id
votes = g.db.query(Vote.user_id, func.count(Vote.user_id)).join(Submission, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.is_banned == False, Submission.state_user_deleted_utc == None, Vote.vote_type==1, Submission.author_id==id).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all()
votes = g.db.query(Vote.user_id, func.count(Vote.user_id)).join(Submission, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.state_mod == StateMod.VISIBLE, Submission.state_user_deleted_utc == None, Vote.vote_type==1, Submission.author_id==id).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all()
votes2 = g.db.query(CommentVote.user_id, func.count(CommentVote.user_id)).join(Comment, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.is_banned == False, Comment.state_user_deleted_utc == None, CommentVote.vote_type==1, Comment.author_id==id).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all()
votes2 = g.db.query(CommentVote.user_id, func.count(CommentVote.user_id)).join(Comment, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == None, CommentVote.vote_type==1, Comment.author_id==id).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all()
votes = Counter(dict(votes)) + Counter(dict(votes2))
@ -226,9 +227,9 @@ def upvoters(v, username):
def downvoters(v, username):
id = get_user(username).id
votes = g.db.query(Vote.user_id, func.count(Vote.user_id)).join(Submission, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.is_banned == False, Submission.state_user_deleted_utc == None, Vote.vote_type==-1, Submission.author_id==id).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all()
votes = g.db.query(Vote.user_id, func.count(Vote.user_id)).join(Submission, Vote.submission_id==Submission.id).filter(Submission.ghost == False, Submission.state_mod == StateMod.VISIBLE, Submission.state_user_deleted_utc == None, Vote.vote_type==-1, Submission.author_id==id).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all()
votes2 = g.db.query(CommentVote.user_id, func.count(CommentVote.user_id)).join(Comment, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.is_banned == False, Comment.state_user_deleted_utc == None, CommentVote.vote_type==-1, Comment.author_id==id).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all()
votes2 = g.db.query(CommentVote.user_id, func.count(CommentVote.user_id)).join(Comment, CommentVote.comment_id==Comment.id).filter(Comment.ghost == False, Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == None, CommentVote.vote_type==-1, Comment.author_id==id).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all()
votes = Counter(dict(votes)) + Counter(dict(votes2))
@ -250,9 +251,9 @@ def downvoters(v, username):
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(Submission.ghost == False, Submission.is_banned == False, Submission.state_user_deleted_utc == None, 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 == False, Submission.state_mod == StateMod.VISIBLE, Submission.state_user_deleted_utc == 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(Comment.ghost == False, Comment.is_banned == False, Comment.state_user_deleted_utc == None, 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 == False, Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == 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))
@ -274,9 +275,9 @@ def upvoting(v, username):
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(Submission.ghost == False, Submission.is_banned == False, Submission.state_user_deleted_utc == None, 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 == False, Submission.state_mod == StateMod.VISIBLE, Submission.state_user_deleted_utc == 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(Comment.ghost == False, Comment.is_banned == False, Comment.state_user_deleted_utc == None, 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 == False, Comment.state_mod == StateMod.VISIBLE, Comment.state_user_deleted_utc == 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))
@ -454,7 +455,8 @@ def message2(v, username):
parent_submission=None,
level=1,
sentto=user.id,
body_html=body_html
body_html=body_html,
state_mod=StateMod.VISIBLE,
)
g.db.add(c)
g.db.flush()
@ -512,6 +514,7 @@ def messagereply(v):
level=parent.level + 1,
sentto=user_id,
body_html=body_html,
state_mod=StateMod.VISIBLE,
)
g.db.add(c)
g.db.flush()
@ -755,9 +758,8 @@ def u_username_comments(username, v=None):
if not v or (v.id != u.id and v.admin_level < 2):
comments = comments.filter(
Comment.state_user_deleted_utc == None,
Comment.is_banned == False,
Comment.state_mod == StateMod.VISIBLE,
Comment.ghost == False,
(Comment.filter_state != 'filtered') & (Comment.filter_state != 'removed')
)
comments = apply_time_filter(comments, t, Comment)

View file

@ -4,6 +4,7 @@ from files.__main__ import app
from files.classes.comment import Comment
from files.classes.flags import CommentFlag
from files.classes.user import User
from files.classes.visstate import StateReport
from files.classes.volunteer_janitor import VolunteerJanitorRecord, VolunteerJanitorResult
from files.helpers.volunteer_janitor import update_comment_badness
from files.routes.volunteer_common import VolunteerDuty
@ -43,7 +44,7 @@ def get_duty(u: User) -> Optional[VolunteerDutyJanitor]:
# find reported not-deleted comments not made by the current user
reported_comments = g.db.query(Comment) \
.where(Comment.filter_state == 'reported') \
.where(Comment.state_report == StateReport.REPORTED) \
.where(Comment.state_user_deleted_utc == None) \
.where(Comment.author_id != u.id) \
.with_entities(Comment.id)