Fix improper calls to Comment.replies.

In four contexts, Comment.replies(.) was not updated to reflect the
interface changes with comment filtering. This directly caused #170
and #172 (which was a stack trace from the former).
  - Updating notifications for DMs (routes/users.py L690)
  - Updating notifications for modmail (routes/users.py L729)
  - morecomments for logged out users (routes/posts.py L421)
  - JSON for API access (classes/comment.py L347)

All four contexts seem to behave correctly after the change. However,
strictly speaking the JSON generation will not include a user's own
filtered or removed comments, though this is hard to remedy without
passing the user object `v` to json_core. Propagating that through the
codebase seems a worse option than leaving it as is.
This commit is contained in:
TLSM 2022-08-17 02:49:19 -04:00 committed by Ben Rog-Wilhelm
parent d4dd495b31
commit 965a4dc157
3 changed files with 4 additions and 5 deletions

View file

@ -344,8 +344,7 @@ class Comment(Base):
if self.level>=2: data['parent_comment_id']= self.parent_comment_id if self.level>=2: data['parent_comment_id']= self.parent_comment_id
if "replies" in self.__dict__: data['replies']=[x.json_core for x in self.replies(None)]
data['replies']=[x.json_core for x in self.replies]
return data return data

View file

@ -418,7 +418,7 @@ def morecomments(v, cid):
comments = output comments = output
else: else:
c = g.db.query(Comment).filter_by(id=cid).one_or_none() c = g.db.query(Comment).filter_by(id=cid).one_or_none()
comments = c.replies comments = c.replies(None)
if comments: p = comments[0].post if comments: p = comments[0].post
else: p = None else: p = None

View file

@ -687,7 +687,7 @@ def messagereply(v):
if not notif: if not notif:
notif = Notification(comment_id=c.id, user_id=user_id) notif = Notification(comment_id=c.id, user_id=user_id)
g.db.add(notif) g.db.add(notif)
ids = [c.top_comment.id] + [x.id for x in c.top_comment.replies] ids = [c.top_comment.id] + [x.id for x in c.top_comment.replies_ignoring_shadowbans]
notifications = g.db.query(Notification).filter(Notification.comment_id.in_(ids), Notification.user_id == user_id) notifications = g.db.query(Notification).filter(Notification.comment_id.in_(ids), Notification.user_id == user_id)
for n in notifications: for n in notifications:
g.db.delete(n) g.db.delete(n)
@ -726,7 +726,7 @@ def messagereply(v):
notif = Notification(comment_id=c.id, user_id=admin.id) notif = Notification(comment_id=c.id, user_id=admin.id)
g.db.add(notif) g.db.add(notif)
ids = [c.top_comment.id] + [x.id for x in c.top_comment.replies] ids = [c.top_comment.id] + [x.id for x in c.top_comment.replies_ignoring_shadowbans]
notifications = g.db.query(Notification).filter(Notification.comment_id.in_(ids)) notifications = g.db.query(Notification).filter(Notification.comment_id.in_(ids))
for n in notifications: for n in notifications:
g.db.delete(n) g.db.delete(n)