diff --git a/files/classes/submission.py b/files/classes/submission.py index da41e425b6..a33aad78db 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -70,11 +70,11 @@ class Submission(Base): embed_url = Column(String) new = Column(Boolean) - author = relationship("User", primaryjoin="Submission.author_id==User.id", lazy="joined") + author = relationship("User", primaryjoin="Submission.author_id==User.id") oauth_app = relationship("OauthApp", viewonly=True) approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True) - awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", lazy="joined", viewonly=True) - flags = relationship("Flag", order_by="Flag.created_utc", lazy="joined", viewonly=True) + awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", viewonly=True) + reports = relationship("Flag", viewonly=True) comments = relationship("Comment", primaryjoin="Comment.parent_submission==Submission.id") subr = relationship("Sub", primaryjoin="foreign(Submission.sub)==remote(Sub.name)", viewonly=True) @@ -93,6 +93,15 @@ class Submission(Base): if self.downvotes > 5 and 0.25 < self.upvotes / self.downvotes < 4: return True return False + @lazy + def flags(self, v): + flags = g.db.query(Flag).filter_by(post_id=self.id).order_by(Flag.created_utc).all() + if not (v and (v.shadowbanned or v.admin_level >= 2)): + for flag in flags: + if flag.user.shadowbanned: + flags.remove(flag) + return flags + @property @lazy def options(self): @@ -278,7 +287,7 @@ class Submission(Base): @lazy def json_raw(self): flags = {} - for f in self.flags: flags[f.user.username] = f.reason + for f in self.flags(None): flags[f.user.username] = f.reason data = {'author_name': self.author_name if self.author else '', 'permalink': self.permalink, @@ -497,4 +506,4 @@ class Submission(Base): @lazy def active_flags(self, v): - return len(self.flags) \ No newline at end of file + return len(self.flags(v)) \ No newline at end of file diff --git a/files/classes/user.py b/files/classes/user.py index 739168fdc9..f1626aab51 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -135,7 +135,7 @@ class User(Base): total_held_lottery_tickets = Column(Integer, default=0) total_lottery_winnings = Column(Integer, default=0) - badges = relationship("Badge", order_by="Badge.created_utc", lazy="joined", viewonly=True) + badges = relationship("Badge", order_by="Badge.created_utc", viewonly=True) subscriptions = relationship("Subscription", viewonly=True) following = relationship("Follow", primaryjoin="Follow.user_id==User.id", viewonly=True) followers = relationship("Follow", primaryjoin="Follow.target_id==User.id", viewonly=True) diff --git a/files/routes/admin.py b/files/routes/admin.py index 5536c30cb7..71d6267b04 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -430,7 +430,7 @@ def reported_posts(v): listing = g.db.query(Submission).filter_by( is_approved=None, is_banned=False - ).join(Submission.flags).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26) + ).join(Submission.reports).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26) listing = [p.id for p in listing] next_exists = len(listing) > 25 @@ -452,7 +452,7 @@ def reported_comments(v): ).filter_by( is_approved=None, is_banned=False - ).join(Comment.flags).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all() + ).join(Comment.reports).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all() listing = [c.id for c in listing] next_exists = len(listing) > 25 diff --git a/files/templates/submission.html b/files/templates/submission.html index e781680ddb..3574ce0f65 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -770,7 +770,7 @@ Reported by: