diff --git a/files/routes/posts.py b/files/routes/posts.py index 938935964..11f0fc757 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -225,11 +225,18 @@ def post_id(pid, anything=None, v=None, sub=None): post.views += 1 g.db.add(post) - if request.headers.get("Authorization"): return post.json - else: - if post.is_banned and not (v and (v.admin_level > 1 or post.author_id == v.id)): template = "submission_banned.html" - 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']) + + if request.headers.get("Authorization"): + return post.json + + 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///") @limiter.limit("1/second;30/minute;200/hour;1000/day") diff --git a/files/routes/search.py b/files/routes/search.py index f33caa8a1..3711f3e56 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -48,16 +48,19 @@ def searchposts(v): criteria=searchparse(query) - - - posts = g.db.query(Submission.id).filter(Submission.author_id.notin_(v.userblocks)) + posts = g.db.query(Submission.id) \ + .join(Submission.author) \ + .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: - 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: 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()) total=users.count() diff --git a/files/routes/users.py b/files/routes/users.py index 001262bff..6436dcef5 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -11,6 +11,7 @@ from files.mail import * from flask import * from files.__main__ import app, limiter, db_session import sqlalchemy +from sqlalchemy.orm import aliased from sqlalchemy import text from collections import Counter import gevent @@ -1055,14 +1056,24 @@ def u_username_comments(username, v=None): sort=request.values.get("sort","new") t=request.values.get("t","all") - - comments = g.db.query(Comment.id).filter(Comment.author_id == u.id, Comment.parent_submission != None) + comment_post_author = aliased(User) + 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): - 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): - comments = comments.filter_by(deleted_utc=0) + comments = comments.filter(Comment.deleted_utc == 0) comments = apply_time_filter(t, comments, Comment)