Volunteer Janitor: Record accepted tasks.

This commit is contained in:
Ben Rog-Wilhelm 2022-11-19 05:02:12 -06:00 committed by Ben Rog-Wilhelm
parent 03b323c7a1
commit 0a8bbae290
6 changed files with 113 additions and 22 deletions

View file

@ -1,24 +1,35 @@
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.volunteer_janitor import VolunteerJanitorRecord, VolunteerJanitorResult
from files.routes.volunteer_common import VolunteerDuty
from flask import g
import pprint
import random
import sqlalchemy
class VolunteerDutyJanitor(VolunteerDuty):
def __init__(self, choices):
self.choices = choices
def accept(self) -> None:
pprint.pprint(self.choices)
pass
def accept(self, v) -> None:
for item in self.choices:
record = VolunteerJanitorRecord()
record.user_id = v.id
record.comment_id = item
record.edited_utc = sqlalchemy.func.now()
record.result = VolunteerJanitorResult.Pending
g.db.add(record)
g.db.commit()
def embed_template(self) -> str:
return "volunteer_janitor.html"
def get_duty(u: User) -> VolunteerDutyJanitor:
# these could probably be combined into one query somehow
@ -31,26 +42,34 @@ def get_duty(u: User) -> VolunteerDutyJanitor:
reported_ids = [reported.id for reported in reported_comments]
# find distinguished children of those reported comments
distinguished_children = g.db.query(Comment) \
.where(Comment.parent_comment_id.in_(reported_ids)) \
.where(Comment.distinguish_level > 0) \
.with_entities(Comment.parent_comment_id)
if not app.config['DBG_VOLUNTEER_PERMISSIVE']:
# find distinguished children of those reported comments
distinguished_children = g.db.query(Comment) \
.where(Comment.parent_comment_id.in_(reported_ids)) \
.where(Comment.distinguish_level > 0) \
.with_entities(Comment.parent_comment_id)
distinguished_children_ids = [child.parent_comment_id for child in distinguished_children]
distinguished_children_ids = [child.parent_comment_id for child in distinguished_children]
# filter
# we're doing this because we don't want to give people hints as to the "right" result
# once a modhat hits, that's it, doesn't show up in the volunteer system anymore
clean_reported = set(reported_ids) - set(distinguished_children_ids)
# filter
# we're doing this because we don't want to give people hints as to the "right" result
# once a modhat hits, that's it, doesn't show up in the volunteer system anymore
clean_reported = set(reported_ids) - set(distinguished_children_ids)
# also, let's make sure it has a report that isn't made by this user
nonuser_reports = g.db.query(CommentFlag) \
.where(CommentFlag.comment_id.in_(clean_reported)) \
.where(CommentFlag.user_id != u.id) \
.with_entities(CommentFlag.comment_id)
# also, let's make sure it has a report that isn't made by this user
nonuser_reports = g.db.query(CommentFlag) \
.where(CommentFlag.comment_id.in_(clean_reported)) \
.where(CommentFlag.user_id != u.id) \
.with_entities(CommentFlag.comment_id)
final_reported = [report.comment_id for report in nonuser_reports]
# also, let's make sure it hasn't already been looked at by this user
seen_records = g.db.query(VolunteerJanitorRecord) \
.where(VolunteerJanitorRecord.user_id == u.id) \
.with_entities(CommentFlag.comment_id)
final_reported = list({report.comment_id for report in nonuser_reports} - {record.comment_id for record in seen_records})
else:
final_reported = reported_ids
if len(final_reported) <= 0:
return None