remove unneccessary v checks

also add can_see_chat
pull/20/head
justcool393 2022-11-18 09:00:46 -06:00
parent 2bdb382ee5
commit 16c129e2b3
10 changed files with 45 additions and 48 deletions

View File

@ -141,7 +141,7 @@ class Comment(Base):
replies = db.query(Comment).filter_by(parent_comment_id=self.id).order_by(Comment.stickied) replies = db.query(Comment).filter_by(parent_comment_id=self.id).order_by(Comment.stickied)
if not self.parent_submission: sort='old' if not self.parent_submission: sort='old'
return sort_objects(sort, replies, Comment, return sort_objects(sort, replies, Comment,
include_shadowbanned=(v and v.can_see_shadowbanned)).all() include_shadowbanned=v.can_see_shadowbanned).all()
@property @property
@ -243,8 +243,8 @@ class Comment(Base):
def realbody(self, v): def realbody(self, v):
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id] or (self.parent_comment and v.id == self.parent_comment.author_id))): if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id] or (self.parent_comment and v.id == self.parent_comment.author_id))):
return f"<p>{CC} ONLY</p>" return f"<p>{CC} ONLY</p>"
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]" if self.deleted_utc != 0 and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (v and v.id == self.author.id): return "[Deleted by user]"
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return "" if self.is_banned and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and not (v and v.id == self.author.id): return ""
body = self.body_html or "" body = self.body_html or ""
@ -298,8 +298,8 @@ class Comment(Base):
def plainbody(self, v): def plainbody(self, v):
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id] or (self.parent_comment and v.id == self.parent_comment.author_id))): if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id] or (self.parent_comment and v.id == self.parent_comment.author_id))):
return f"{CC} ONLY" return f"{CC} ONLY"
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]" if self.deleted_utc != 0 and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (v and v.id == self.author.id): return "[Deleted by user]"
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return "" if self.is_banned and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and not (v and v.id == self.author.id): return ""
body = self.body body = self.body
@ -312,21 +312,13 @@ class Comment(Base):
@lazy @lazy
def collapse_for_user(self, v, path): def collapse_for_user(self, v, path):
if v and self.author_id == v.id: return False if v and self.author_id == v.id: return False
if path == '/admin/removed/comments': return False if path == '/admin/removed/comments': return False
if self.author.shadowbanned and not v.shadowbanned: return True
if '?context' in path or f'/{self.id}' in path: return False if '?context' in path or f'/{self.id}' in path: return False
if self.over_18 and not v.over_18 and not (self.post and self.post.over_18): return True
if self.over_18 and not (v and v.over_18) and not (self.post and self.post.over_18): return True
if self.is_banned: return True if self.is_banned: return True
if self.author.shadowbanned and not (v and v.shadowbanned): return True
if (self.wordle_result) and (not self.body or len(self.body_html) <= 100) and 9 > self.level > 1: return True if (self.wordle_result) and (not self.body or len(self.body_html) <= 100) and 9 > self.level > 1: return True
if v.filter_words and self.body and any(x in self.body for x in v.filter_words): return True
if v and v.filter_words and self.body and any(x in self.body for x in v.filter_words): return True
return False return False
@property @property
@ -335,7 +327,7 @@ class Comment(Base):
@lazy @lazy
def filtered_flags(self, v): 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 v.shadowbanned or not f.user.shadowbanned]
@lazy @lazy
def active_flags(self, v): def active_flags(self, v):

View File

@ -271,8 +271,8 @@ class Submission(Base):
@lazy @lazy
def realbody(self, v, listing=False): def realbody(self, v, listing=False):
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>" if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]" if self.deleted_utc != 0 and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (v and v.id == self.author.id): return "[Deleted by user]"
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return "" if self.is_banned and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and not (v and v.id == self.author.id): return ""
body = self.body_html or "" body = self.body_html or ""
@ -328,8 +328,8 @@ class Submission(Base):
@lazy @lazy
def plainbody(self, v): def plainbody(self, v):
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]" if self.deleted_utc != 0 and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (v and v.id == self.author.id): return "[Deleted by user]"
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return "" if self.is_banned and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and not (v and v.id == self.author.id): return ""
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>" if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
body = self.body body = self.body
@ -380,7 +380,7 @@ class Submission(Base):
@lazy @lazy
def filtered_flags(self, v): 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 v.shadowbanned or not f.user.shadowbanned]
@lazy @lazy
def active_flags(self, v): def active_flags(self, v):

View File

@ -419,8 +419,8 @@ class LoggedOutUser():
'bannerurl': self.banner_url, 'bannerurl': self.banner_url,
'bio_html': self.bio_html_eager, 'bio_html': self.bio_html_eager,
'coins': self.coins, 'coins': self.coins,
'post_count': 0 if self.shadowbanned and not (v and v.can_see_shadowbanned) else self.post_count, 'post_count': 0 if self.shadowbanned and not v.can_see_shadowbanned else self.post_count,
'comment_count': 0 if self.shadowbanned and not (v and v.can_see_shadowbanned) else self.comment_count, 'comment_count': 0 if self.shadowbanned and not v.can_see_shadowbanned else self.comment_count,
'badges': [x.path for x in self.badges], 'badges': [x.path for x in self.badges],
'created_date': self.created_date, 'created_date': self.created_date,
} }
@ -521,15 +521,9 @@ class LoggedOutUser():
@lazy @lazy
def show_sig(self, v): def show_sig(self, v):
if not self.sig_html: if not self.sig_html: return False
return False if not self.patron and SITE_NAME != 'WPD': return False
if v and (v.sigs_disabled or v.poor): return False
if not self.patron and SITE_NAME != 'WPD':
return False
if v and (v.sigs_disabled or v.poor):
return False
return True return True
@property @property
@ -587,7 +581,7 @@ class LoggedOutUser():
if other.parent_submission and other.post.sub and not self.can_see(other.post.subr): return False if other.parent_submission and other.post.sub and not self.can_see(other.post.subr): return False
# if other.parent_submission and not self.can_see(other.post): return False # if other.parent_submission and not self.can_see(other.post): return False
elif isinstance(other, Sub): elif isinstance(other, Sub):
return other.name != 'chudrama' or self.can_see_chudrama return other.name != 'chudrama' or self.can_see_chudrama # type: ignore
elif isinstance(other, User): elif isinstance(other, User):
return bool(self and self.id == other.id) or self.can_see_shadowbanned or not other.shadowbanned return bool(self and self.id == other.id) or self.can_see_shadowbanned or not other.shadowbanned
return True return True
@ -612,6 +606,17 @@ class LoggedOutUser():
if self.truescore >= TRUESCORE_GHOST_LIMIT: return True if self.truescore >= TRUESCORE_GHOST_LIMIT: return True
if self.patron: return True if self.patron: return True
return False return False
@property
@lazy
def can_see_chat(self):
if not self: return False
if self.is_suspended_permanently: return False
if not TRUESCORE_CHAT_LIMIT: return True
if self.club_allowed: return True
if self.truescore >= TRUESCORE_CHAT_LIMIT: return True
if self.patron: return True
return False
@property @property
@lazy @lazy

View File

@ -51,7 +51,7 @@ def get_user(username:Optional[str], v:Optional[LoggedOutUser]=None, graceful=Fa
user = user.one_or_none() user = user.one_or_none()
if not user or (user.shadowbanned and not (include_shadowbanned or (v and v.can_see_shadowbanned))): if not user or (user.shadowbanned and not (include_shadowbanned or v.can_see_shadowbanned)):
if graceful: return None if graceful: return None
abort(404) abort(404)
@ -86,7 +86,7 @@ def get_account(id:Union[str, int], v:Optional[LoggedOutUser]=None, graceful=Fal
user = g.db.get(User, id) user = g.db.get(User, id)
if not user or (user.shadowbanned and not (include_shadowbanned or (v and v.can_see_shadowbanned))): if not user or (user.shadowbanned and not (include_shadowbanned or v.can_see_shadowbanned)):
if not graceful: abort(404) if not graceful: abort(404)
else: return None else: return None

View File

@ -39,7 +39,7 @@ user_ids_to_socket_ids = {}
@app.get("/chat") @app.get("/chat")
@is_not_permabanned @is_not_permabanned
def chat(v): def chat(v):
if TRUESCORE_CHAT_LIMIT and v.truescore < TRUESCORE_CHAT_LIMIT and not v.club_allowed: if not v.can_see_chat:
abort(403, f"Need at least {TRUESCORE_CHAT_LIMIT} truescore for access to chat.") abort(403, f"Need at least {TRUESCORE_CHAT_LIMIT} truescore for access to chat.")
return render_template("chat.html", v=v, messages=messages) return render_template("chat.html", v=v, messages=messages)
@ -50,7 +50,7 @@ def chat(v):
@ratelimit_user("3/second;10/minute") @ratelimit_user("3/second;10/minute")
def speak(data, v): def speak(data, v):
if v.is_banned: return '', 403 if v.is_banned: return '', 403
if TRUESCORE_CHAT_LIMIT and v.truescore < TRUESCORE_CHAT_LIMIT and not v.club_allowed: return '', 403 if not v.can_see_chat: return '', 403
vname = v.username.lower() vname = v.username.lower()
if vname in muted and not v.admin_level >= PERMS['CHAT_BYPASS_MUTE']: if vname in muted and not v.admin_level >= PERMS['CHAT_BYPASS_MUTE']:

View File

@ -47,7 +47,7 @@ def post_pid_comment_cid(v, cid, pid=None, anything=None, sub=None):
post = get_post(pid, v=v) post = get_post(pid, v=v)
if post.over_18 and not (v and v.over_18) and not session.get('over_18', 0) >= int(time.time()): if post.over_18 and not v.over_18 and not session.get('over_18', 0) >= int(time.time()):
if v and v.client: abort(403, "This content is not suitable for some users and situations.") if v and v.client: abort(403, "This content is not suitable for some users and situations.")
else: return render_template("errors/nsfw.html", v=v), 403 else: return render_template("errors/nsfw.html", v=v), 403

View File

@ -101,7 +101,7 @@ def front_all(v, sub=None, subdomain=None):
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', gt=0, lt=0, sub=None, site=None, pins=True, holes=True): def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', gt=0, lt=0, sub=None, site=None, pins=True, holes=True):
posts = g.db.query(Submission) posts = g.db.query(Submission)
if v and v.hidevotedon: if v.hidevotedon:
posts = posts.outerjoin(Vote, posts = posts.outerjoin(Vote,
and_(Vote.submission_id == Submission.id, Vote.user_id == v.id) and_(Vote.submission_id == Submission.id, Vote.user_id == v.id)
).filter(Vote.submission_id == None) ).filter(Vote.submission_id == None)
@ -137,7 +137,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
posts=posts.filter(not_(Submission.title.ilike(f'%{word}%'))) posts=posts.filter(not_(Submission.title.ilike(f'%{word}%')))
posts = sort_objects(sort, posts, Submission, posts = sort_objects(sort, posts, Submission,
include_shadowbanned=(v and v.can_see_shadowbanned)) include_shadowbanned=v.can_see_shadowbanned)
if v: size = v.frontsize or 0 if v: size = v.frontsize or 0
else: size = PAGE_SIZE else: size = PAGE_SIZE
@ -255,7 +255,7 @@ def comment_idlist(v=None, page=1, sort="new", t="all", gt=0, lt=0, site=None):
comments = apply_time_filter(t, comments, Comment) comments = apply_time_filter(t, comments, Comment)
comments = sort_objects(sort, comments, Comment, comments = sort_objects(sort, comments, Comment,
include_shadowbanned=(v and v.can_see_shadowbanned)) include_shadowbanned=v.can_see_shadowbanned)
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all() comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all()
return [x[0] for x in comments] return [x[0] for x in comments]

View File

@ -157,7 +157,7 @@ def post_id(v, pid, anything=None, sub=None):
pinned = [c[0] for c in comments.filter(Comment.stickied != None).all()] pinned = [c[0] for c in comments.filter(Comment.stickied != None).all()]
comments = comments.filter(Comment.level == 1, Comment.stickied == None) comments = comments.filter(Comment.level == 1, Comment.stickied == None)
comments = sort_objects(sort, comments, Comment, comments = sort_objects(sort, comments, Comment,
include_shadowbanned=(v and v.can_see_shadowbanned)) include_shadowbanned=v.can_see_shadowbanned)
comments = [c[0] for c in comments.all()] comments = [c[0] for c in comments.all()]
else: else:
pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.stickied != None).all() pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.stickied != None).all()
@ -247,7 +247,7 @@ def viewmore(v, pid, sort, offset):
comments, output = get_comments_v_properties(v, True, None, Comment.parent_submission == pid, Comment.stickied == None, Comment.id.notin_(ids), Comment.level < 10) comments, output = get_comments_v_properties(v, True, None, Comment.parent_submission == pid, Comment.stickied == None, Comment.id.notin_(ids), Comment.level < 10)
comments = comments.filter(Comment.level == 1) comments = comments.filter(Comment.level == 1)
comments = sort_objects(sort, comments, Comment, comments = sort_objects(sort, comments, Comment,
include_shadowbanned=(v and v.can_see_shadowbanned)) include_shadowbanned=v.can_see_shadowbanned)
comments = [c[0] for c in comments.all()] comments = [c[0] for c in comments.all()]
else: else:

View File

@ -153,7 +153,7 @@ def searchposts(v):
posts = apply_time_filter(t, posts, Submission) posts = apply_time_filter(t, posts, Submission)
posts = sort_objects(sort, posts, Submission, posts = sort_objects(sort, posts, Submission,
include_shadowbanned=(v and v.can_see_shadowbanned)) include_shadowbanned=v.can_see_shadowbanned)
total = posts.count() total = posts.count()
@ -255,7 +255,7 @@ def searchcomments(v):
comments = comments.filter(Comment.created_utc < before) comments = comments.filter(Comment.created_utc < before)
comments = sort_objects(sort, comments, Comment, comments = sort_objects(sort, comments, Comment,
include_shadowbanned=(v and v.can_see_shadowbanned)) include_shadowbanned=v.can_see_shadowbanned)
total = comments.count() total = comments.count()

View File

@ -670,7 +670,7 @@ def visitors(v):
@cache.memoize(timeout=86400) @cache.memoize(timeout=86400)
def userpagelisting(user:User, site=None, v=None, page:int=1, sort="new", t="all"): def userpagelisting(user:User, site=None, v=None, page:int=1, sort="new", t="all"):
if user.shadowbanned and not (v and v.can_see_shadowbanned): return [] if user.shadowbanned and not v.can_see_shadowbanned: return []
posts = g.db.query(Submission.id).filter_by(author_id=user.id, is_pinned=False) posts = g.db.query(Submission.id).filter_by(author_id=user.id, is_pinned=False)
if not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == user.id)): if not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == user.id)):
posts = posts.filter_by(is_banned=False, private=False, ghost=False, deleted_utc=0) posts = posts.filter_by(is_banned=False, private=False, ghost=False, deleted_utc=0)
@ -803,7 +803,7 @@ def u_username_comments(username, v=None):
comments = apply_time_filter(t, comments, Comment) comments = apply_time_filter(t, comments, Comment)
comments = sort_objects(sort, comments, Comment, comments = sort_objects(sort, comments, Comment,
include_shadowbanned=(v and v.can_see_shadowbanned)) include_shadowbanned=v.can_see_shadowbanned)
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE+1).all() comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE+1).all()
ids = [x.id for x in comments] ids = [x.id for x in comments]