Hide shadowed user content in more contexts.

- Search: posts by shadowed user.
  - Search: shadowed users in search for users.
  - Direct links to shadowed user posts display as removed.
  - Other users' profile comments listings hide comments on shadowed
    posts. Users can still see their own comments on shadowed posts.
    Similar to ghosted comment logic.
master
Snakes 2022-08-08 18:21:59 -04:00
parent a10a177106
commit 6a7a3b1821
Signed by: Snakes
GPG Key ID: E745A82778055C7E
3 changed files with 40 additions and 16 deletions

View File

@ -225,11 +225,18 @@ def post_id(pid, anything=None, v=None, sub=None):
post.views += 1 post.views += 1
g.db.add(post) g.db.add(post)
if request.headers.get("Authorization"): return post.json
else: if request.headers.get("Authorization"):
if post.is_banned and not (v and (v.admin_level > 1 or post.author_id == v.id)): template = "submission_banned.html" return post.json
else: template = "submission.html"
return render_template(template, v=v, p=post, ids=list(ids), sort=sort, render_replies=True, offset=offset, sub=post.subr, fart=app.config['SETTINGS']['Fart mode']) template = "submission.html"
if (post.is_banned or post.author.shadowbanned) \
and not (v and (v.admin_level >= 2 or post.author_id == v.id)):
template = "submission_banned.html"
return render_template(template, v=v, p=post, ids=list(ids),
sort=sort, render_replies=True, offset=offset, sub=post.subr,
fart=app.config['SETTINGS']['Fart mode'])
@app.get("/viewmore/<pid>/<sort>/<offset>") @app.get("/viewmore/<pid>/<sort>/<offset>")
@limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day")

View File

@ -48,16 +48,19 @@ def searchposts(v):
criteria=searchparse(query) criteria=searchparse(query)
posts = g.db.query(Submission.id) \
.join(Submission.author) \
posts = g.db.query(Submission.id).filter(Submission.author_id.notin_(v.userblocks)) .filter(Submission.author_id.notin_(v.userblocks))
if not v.paid_dues: posts = posts.filter_by(club=False) if not v.paid_dues:
posts = posts.filter(Submission.club == False)
if v.admin_level < 2: if v.admin_level < 2:
posts = posts.filter(Submission.deleted_utc == 0, Submission.is_banned == False, Submission.private == False) posts = posts.filter(
Submission.deleted_utc == 0,
Submission.is_banned == False,
Submission.private == False,
User.shadowbanned == None)
if 'author' in criteria: if 'author' in criteria:
posts = posts.filter(Submission.ghost == False) posts = posts.filter(Submission.ghost == False)
@ -239,6 +242,9 @@ def searchusers(v):
) )
) )
if v.admin_level < 2:
users = users.filter(User.shadowbanned == None)
users=users.order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc()) users=users.order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc())
total=users.count() total=users.count()

View File

@ -11,6 +11,7 @@ from files.mail import *
from flask import * from flask import *
from files.__main__ import app, limiter, db_session from files.__main__ import app, limiter, db_session
import sqlalchemy import sqlalchemy
from sqlalchemy.orm import aliased
from sqlalchemy import text from sqlalchemy import text
from collections import Counter from collections import Counter
import gevent import gevent
@ -1055,14 +1056,24 @@ def u_username_comments(username, v=None):
sort=request.values.get("sort","new") sort=request.values.get("sort","new")
t=request.values.get("t","all") t=request.values.get("t","all")
comment_post_author = aliased(User)
comments = g.db.query(Comment.id).filter(Comment.author_id == u.id, Comment.parent_submission != None) comments = g.db.query(Comment.id) \
.join(Comment.post) \
.join(comment_post_author, Submission.author) \
.filter(
Comment.author_id == u.id,
Comment.parent_submission != None
)
if not v or (v.id != u.id and v.admin_level < 2): if not v or (v.id != u.id and v.admin_level < 2):
comments = comments.filter(Comment.is_banned == False, Comment.ghost == False) comments = comments.filter(
Comment.is_banned == False,
Comment.ghost == False,
comment_post_author.shadowbanned == None
)
if not (v and v.admin_level > 1): if not (v and v.admin_level > 1):
comments = comments.filter_by(deleted_utc=0) comments = comments.filter(Comment.deleted_utc == 0)
comments = apply_time_filter(t, comments, Comment) comments = apply_time_filter(t, comments, Comment)