diff --git a/files/classes/comment.py b/files/classes/comment.py index 90c9d5955..bc48306d8 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -53,6 +53,7 @@ class Comment(Base): parent_comment = relationship("Comment", remote_side=[id], viewonly=True) child_comments = relationship("Comment", remote_side=[parent_comment_id], viewonly=True) awards = relationship("AwardRelationship", viewonly=True) + reports = relationship("CommentFlag", viewonly=True) def __init__(self, *args, **kwargs): diff --git a/files/classes/submission.py b/files/classes/submission.py index bdc2a63d8..69cd36ce7 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -56,6 +56,7 @@ class Submission(Base): oauth_app = relationship("OauthApp", viewonly=True) approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True) awards = relationship("AwardRelationship", viewonly=True) + reports = relationship("Flag", viewonly=True) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/files/helpers/get.py b/files/helpers/get.py index 6a430506b..451b53448 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -216,7 +216,7 @@ def get_comment(i, v=None, graceful=False): return comment -def get_comments(cids, v=None, load_parent=False, shadowbanned=False): +def get_comments(cids, v=None, load_parent=False): if not cids: return [] @@ -235,8 +235,8 @@ def get_comments(cids, v=None, load_parent=False, shadowbanned=False): blocking.c.id, blocked.c.id, ).filter(Comment.id.in_(cids)) - - if not shadowbanned and not v.shadowbanned and v.admin_level < 2: + + if not (v and (v.shadowbanned or v.admin_level > 1)): comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None) comments = comments.join( diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 4bcf4dfaa..fe7c3073b 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -21,8 +21,10 @@ def get_logged_in_user(): if not uid: return None # if not uid or not logged_in or uid != logged_in: return None - if g.db: v = g.db.query(User).filter_by(id=uid).first() - else: return None + try: + if g.db: v = g.db.query(User).filter_by(id=uid).first() + else: return None + except: return None if not v or nonce < v.login_nonce: return None diff --git a/files/routes/admin.py b/files/routes/admin.py index 700ada0c6..5d222ad50 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -290,7 +290,7 @@ def reported_posts(v): posts = g.db.query(Submission).filter_by( is_approved=0, is_banned=False - ).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 posts] next_exists = (len(listing) > 25) @@ -312,7 +312,7 @@ def reported_comments(v): ).filter_by( is_approved=0, is_banned=False - ).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 = [p.id for p in posts] next_exists = (len(listing) > 25) @@ -559,7 +559,7 @@ def admin_link_accounts(v): return redirect(f"/admin/alt_votes?u1={g.db.query(User).get(u1).username}&u2={g.db.query(User).get(u2).username}") -@app.get("/admin/removed") +@app.get("/admin/removed/posts") @admin_level_required(2) def admin_removed(v): @@ -583,6 +583,29 @@ def admin_removed(v): ) +@app.get("/admin/removed/comments") +@admin_level_required(2) +def admin_removed_comments(v): + + page = int(request.values.get("page", 1)) + + ids = g.db.query(Comment.id).join(User, User.id == Comment.author_id).filter(or_(Comment.is_banned==True, User.shadowbanned != None)).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all() + + ids=[x[0] for x in ids] + + next_exists = len(ids) > 25 + + ids = ids[:25] + + comments = get_comments(ids, v=v) + + return render_template("admin/removed_comments.html", + v=v, + listing=comments, + page=page, + next_exists=next_exists + ) + @app.post("/agendaposter/") @admin_level_required(2) diff --git a/files/routes/front.py b/files/routes/front.py index b4c801206..b998936db 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -370,7 +370,7 @@ def random_post(v): return redirect(f"/post/{post.id}") @cache.memoize(timeout=86400) -def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", shadowbanned=False): +def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all"): posts = g.db.query(Submission) cc_idlist = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()] @@ -418,7 +418,6 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", shadowbanned elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - if shadowbanned: comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned != None) comments = comments.offset(25 * (page - 1)).limit(26).all() return [x[0] for x in comments] @@ -432,20 +431,17 @@ def all_comments(v): sort=request.values.get("sort", "new") t=request.values.get("t", defaulttimefilter) - if request.values.get("shadowbanned") and v and v.admin_level > 1: shadowbanned = True - else: shadowbanned = False - idlist = comment_idlist(v=v, page=page, sort=sort, t=t, - shadowbanned=shadowbanned - ) - comments = get_comments(idlist, v=v, shadowbanned=shadowbanned) + ) + + comments = get_comments(idlist, v=v) next_exists = len(idlist) > 25 idlist = idlist[:25] if request.headers.get("Authorization"): return {"data": [x.json for x in comments]} - else: return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists, shadowbanned=shadowbanned) + else: return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists) \ No newline at end of file diff --git a/files/routes/settings.py b/files/routes/settings.py index b35b047b9..e8a4caac7 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -1003,10 +1003,7 @@ def settings_song_change(v): id = song.split("v=")[1] elif song.startswith("https://youtu.be/"): id = song.split("https://youtu.be/")[1] - else: - return render_template("settings_profile.html", - v=v, - error=f"Not a youtube link.") + else: return render_template("settings_profile.html", v=v, error=f"Not a youtube link.") if "?" in id: id = id.split("?")[0] if "&" in id: id = id.split("&")[0] @@ -1020,17 +1017,16 @@ def settings_song_change(v): req = requests.get(f"https://www.googleapis.com/youtube/v3/videos?id={id}&key={YOUTUBE_KEY}&part=contentDetails", timeout=5).json() duration = req['items'][0]['contentDetails']['duration'] + if duration == 'P0D': + return render_template("settings_profile.html", v=v, error=f"Can't use a live youtube video!") + if "H" in duration: - return render_template("settings_profile.html", - v=v, - error=f"Duration of the video must not exceed 10 minutes.") + return render_template("settings_profile.html", v=v, error=f"Duration of the video must not exceed 10 minutes.") if "M" in duration: duration = int(duration.split("PT")[1].split("M")[0]) if duration > 10: - return render_template("settings_profile.html", - v=v, - error=f"Duration of the video must not exceed 10 minutes.") + return render_template("settings_profile.html", v=v, error=f"Duration of the video must not exceed 10 minutes.") if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1: diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index 60bd9fb2d..634ea1f4d 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -12,17 +12,19 @@

Content

Users

Safety

diff --git a/files/templates/admin/removed_comments.html b/files/templates/admin/removed_comments.html new file mode 100644 index 000000000..afe9ad9aa --- /dev/null +++ b/files/templates/admin/removed_comments.html @@ -0,0 +1,73 @@ +{% extends "admin/image_posts.html" %} + + +{% block title %} +Removed Content + +{% endblock %} + +{% block content %} + +
+
+
+
+
+

+				
Removed Posts
+ +
+ +
+ +
+
+
+ +
+ +
+ + {% block listing %} + + +
+ {% with comments=listing %} + {% include "comments.html" %} + {% endwith %} + {% if not listing %} +
+
+
+
There are no comments here (yet).
+
+
+
+ {% endif %} +
+ +{% endblock %} +
+
+{% endblock %} + +{% block pagenav %} + +{% endblock %}