diff --git a/drama/helpers/get.py b/drama/helpers/get.py index 7e816fe4b..160086a52 100644 --- a/drama/helpers/get.py +++ b/drama/helpers/get.py @@ -180,112 +180,6 @@ def get_posts(pids, v=None): return sorted(output, key=lambda x: pids.index(x.id)) - -def get_post_with_comments(pid, sort="top", v=None): - - post = get_post(pid, v=v) - - if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() - - blocking = v.blocking.subquery() - - blocked = v.blocked.subquery() - - comms = g.db.query( - Comment, - votes.c.vote_type, - blocking.c.id, - blocked.c.id, - ) - if v.admin_level >=4: - comms=comms.options(joinedload(Comment.oauth_app)) - - comms=comms.filter( - Comment.parent_submission == post.id - ).join( - votes, - votes.c.comment_id == Comment.id, - isouter=True - ).join( - blocking, - blocking.c.target_id == Comment.author_id, - isouter=True - ).join( - blocked, - blocked.c.user_id == Comment.author_id, - isouter=True - ) - - if sort == "top": - comments = comms.order_by(Comment.score.desc()).all() - elif sort == "bottom": - comments = comms.order_by(Comment.score.asc()).all() - elif sort == "new": - comments = comms.order_by(Comment.created_utc.desc()).all() - elif sort == "old": - comments = comms.order_by(Comment.created_utc.asc()).all() - elif sort == "controversial": - comments = sorted(comms.all(), key=lambda x: x[0].score_disputed, reverse=True) - elif sort == "random": - c = comms.all() - comments = random.sample(c, k=len(c)) - else: - abort(422) - - output = [] - for c in comments: - comment = c[0] - if comment.author and comment.author.shadowbanned and not (v and v.id == comment.author_id): continue - comment._voted = c[1] or 0 - comment._is_blocking = c[2] or 0 - comment._is_blocked = c[3] or 0 - output.append(comment) - - post._preloaded_comments = output - - else: - comms = g.db.query( - Comment - ).filter( - Comment.parent_submission == post.id - ) - - if sort == "top": - comments = comms.order_by(Comment.score.desc()).all() - elif sort == "bottom": - comments = comms.order_by(Comment.score.asc()).all() - elif sort == "new": - comments = comms.order_by(Comment.created_utc.desc()).all() - elif sort == "old": - comments = comms.order_by(Comment.created_utc.asc()).all() - elif sort == "controversial": - comments = sorted(comms.all(), key=lambda x: x.score_disputed, reverse=True) - elif sort == "random": - c = comms.all() - comments = random.sample(c, k=len(c)) - else: - abort(422) - - if random.random() < 0.1: - for comment in comments: - if comment.author and comment.author.shadowbanned: - rand = random.randint(500,1400) - vote = CommentVote(user_id=rand, - vote_type=random.choice([-1, 1]), - comment_id=comment.id) - g.db.add(vote) - try: g.db.flush() - except: g.db.rollback() - comment.upvotes = comment.ups - comment.downvotes = comment.downs - g.db.add(comment) - - post._preloaded_comments = [x for x in comments if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)] - - return post - - def get_comment(cid, v=None, graceful=False, **kwargs): if isinstance(cid, str): @@ -411,16 +305,6 @@ def get_comments(cids, v=None, load_parent=False, **kwargs): return output -def get_board(bid, graceful=False): - - return g.db.query(Board).first() - - -def get_guild(name, graceful=False): - - return g.db.query(Board).first() - - def get_domain(s): # parse domain into all possible subdomains @@ -445,43 +329,4 @@ def get_domain(s): # property doms = sorted(doms, key=lambda x: len(x.domain), reverse=True) - return doms[0] - - -def get_application(client_id, graceful=False): - - application = g.db.query(OauthApp).filter_by(client_id=client_id).first() - if not application and not graceful: - abort(404) - - return application - - -def get_from_permalink(link, v=None): - - if "@" in link: - - name = re.search("/@(\w+)", link) - if name: - name=name.match(1) - return get_user(name) - - if "+" in link: - - x = re.search("/\+(\w+)$", link) - if x: - name=x.match(1) - return get_guild(name) - - ids = re.search("://[^/]+\w+/post/(\w+)/[^/]+(/(\w+))?", link) - - try: - post_id = ids.group(1) - comment_id = ids.group(3) - except: abort(400) - - if comment_id: - return get_comment(int(comment_id), v=v) - - else: - return get_post(int(post_id), v=v) \ No newline at end of file + return doms[0] \ No newline at end of file diff --git a/drama/helpers/jinja2.py b/drama/helpers/jinja2.py index 969a97d7a..2c3a6abab 100644 --- a/drama/helpers/jinja2.py +++ b/drama/helpers/jinja2.py @@ -49,8 +49,4 @@ def js_str_escape(s): @app.template_filter("app_config") def app_config(x): - return app.config.get(x) - -# @app.template_filter("general_chat_count") -# def general_chat_count(x): -# return get_guild("general").chat_count \ No newline at end of file + return app.config.get(x) \ No newline at end of file diff --git a/drama/routes/admin.py b/drama/routes/admin.py index e87403dce..faac5765e 100644 --- a/drama/routes/admin.py +++ b/drama/routes/admin.py @@ -196,6 +196,8 @@ def badge_grant_post(v): if badge_id in [21,22,23,24]: user.patron = True user.animatedname = True + if badge_id == 23: user.banawards = 1 + elif badge_id == 24: user.banawards = 3 g.db.add(user) return redirect(user.permalink) @@ -265,10 +267,22 @@ def participation_stats(v): def admin_vote_info_get(v): if v and v.is_banned and not v.unban_utc: return render_template("seized.html") - if not request.args.get("link"): - return render_template("admin/votes.html", v=v) + link = request.args.get("link") + if not link: return render_template("admin/votes.html", v=v) + + ids = re.search("://[^/]+\w+/post/(\w+)/[^/]+(/(\w+))?", link) + + try: + post_id = ids.group(1) + comment_id = ids.group(3) + except: abort(400) + + if comment_id: + thing = get_comment(int(comment_id), v=v) + + else: + thing = get_post(int(post_id), v=v) - thing = get_from_permalink(request.args.get("link"), v=v) if isinstance(thing, Submission): diff --git a/drama/routes/boards.py b/drama/routes/boards.py index 8b95a714b..ea68f9314 100644 --- a/drama/routes/boards.py +++ b/drama/routes/boards.py @@ -128,7 +128,7 @@ def mod_rescind_bid_username(bid, username, board, v): @api("guildmaster") def mod_accept_board(bid, v): - board = get_board(bid) + board = g.db.query(Board).first() x = board.has_invite(v) if not x: @@ -222,7 +222,7 @@ def mod_remove_username(bid, username, board, v): @public("read") def board_about_mods(v): - board = get_guild("general") + g.db.query(Board).first() me = board.has_mod(v) diff --git a/drama/routes/comments.py b/drama/routes/comments.py index 199eb9a73..354306bbb 100644 --- a/drama/routes/comments.py +++ b/drama/routes/comments.py @@ -668,7 +668,7 @@ def api_comment(v): # print(f"Content Event: @{v.username} comment {c.base36id}") - board = get_board(1) + board = g.db.query(Board).first() cache.delete_memoized(comment_idlist) cache.delete_memoized(User.commentlisting, v) diff --git a/drama/routes/errors.py b/drama/routes/errors.py index b784ed453..5a178b92a 100644 --- a/drama/routes/errors.py +++ b/drama/routes/errors.py @@ -11,6 +11,14 @@ from drama.__main__ import app +@app.errorhandler(400) +@auth_desired +@api() +def error_400(e, v): + return{"html": lambda: (render_template('errors/400.html', v=v), 400), + "api": lambda: (jsonify({"error": "400 Bad Request"}), 400 ) + } + @app.errorhandler(401) def error_401(e): @@ -25,6 +33,7 @@ def error_401(e): else: return redirect(output) + @app.errorhandler(403) @auth_desired @api() @@ -61,12 +70,28 @@ def error_409(e, v): } +@app.errorhandler(410) +@auth_desired +@api() +def error_410(e, v): + return{"html": lambda: (render_template('errors/410.html', v=v), 410), + "api": lambda: (jsonify({"error": "410 Request Payload Too Large"}), 410) + } + @app.errorhandler(413) @auth_desired @api() def error_413(e, v): return{"html": lambda: (render_template('errors/413.html', v=v), 413), - "api": lambda: (jsonify({"error": "413 Request Payload Too Large"}), 413) + "api": lambda: (jsonify({"error": "413 Image Size Too Large"}), 413) + } + +@app.errorhandler(418) +@auth_desired +@api() +def error_418(e, v): + return{"html": lambda: (render_template('errors/418.html', v=v), 418), + "api": lambda: (jsonify({"error": "418 I'm A Teapot"}), 418) } @@ -111,6 +136,24 @@ def error_500(e, v): } +@app.errorhandler(502) +@auth_desired +@api() +def error_502(e, v): + return{"html": lambda: (render_template('errors/502.html', v=v), 502), + "api": lambda: (jsonify({"error": "502 Bad Gateway"}), 502) + } + + +@app.errorhandler(503) +@auth_desired +@api() +def error_503(e, v): + return{"html": lambda: (render_template('errors/503.html', v=v), 503), + "api": lambda: (jsonify({"error": "503 Service Unavailable"}), 503) + } + + @app.route("/allow_nsfw_logged_in/", methods=["POST"]) @auth_required @validate_formkey diff --git a/drama/routes/front.py b/drama/routes/front.py index 99afbdd14..20bd26007 100644 --- a/drama/routes/front.py +++ b/drama/routes/front.py @@ -427,7 +427,7 @@ def all_comments(v): idlist = idlist[0:25] - board = get_board(1) + board = g.db.query(Board).first() return {"html": lambda: render_template("home_comments.html", v=v, sort=sort, diff --git a/drama/routes/oauth.py b/drama/routes/oauth.py index e50cecb5b..62a47667e 100644 --- a/drama/routes/oauth.py +++ b/drama/routes/oauth.py @@ -29,7 +29,9 @@ def oauth_authorize_prompt(v): client_id = request.args.get("client_id") - application = get_application(client_id) + + application = g.db.query(OauthApp).filter_by(client_id=client_id).first() + if not application: return jsonify({"oauth_error": "Invalid `client_id`"}), 401 @@ -90,7 +92,7 @@ def oauth_authorize_post(v): state = request.form.get("state") redirect_uri = request.form.get("redirect_uri") - application = get_application(client_id) + application = g.db.query(OauthApp).filter_by(client_id=client_id).first() if not application: return jsonify({"oauth_error": "Invalid `client_id`"}), 401 if application.is_banned: diff --git a/drama/routes/posts.py b/drama/routes/posts.py index 5655b7ad6..38f6f3681 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -93,7 +93,7 @@ def publish(pid, v): def submit_get(v): if v and v.is_banned and not v.unban_utc: return render_template("seized.html") - b = get_guild("general") + b = g.db.query(Board).first() return render_template("submit.html", v=v, @@ -113,9 +113,149 @@ def post_base36id(pid, anything=None, v=None): if v: defaultsortingcomments = v.defaultsortingcomments else: defaultsortingcomments = "top" sort=request.args.get("sort", defaultsortingcomments) - - post = get_post_with_comments(pid, v=v, sort=sort) + + + + + + + + + + + + + + + post = get_post(pid, v=v) + + if v: + votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + + blocking = v.blocking.subquery() + + blocked = v.blocked.subquery() + + comms = g.db.query( + Comment, + votes.c.vote_type, + blocking.c.id, + blocked.c.id, + ) + if v.admin_level >=4: + comms=comms.options(joinedload(Comment.oauth_app)) + + comms=comms.filter( + Comment.parent_submission == post.id + ).join( + votes, + votes.c.comment_id == Comment.id, + isouter=True + ).join( + blocking, + blocking.c.target_id == Comment.author_id, + isouter=True + ).join( + blocked, + blocked.c.user_id == Comment.author_id, + isouter=True + ) + + if sort == "top": + comments = comms.order_by(Comment.score.desc()).all() + elif sort == "bottom": + comments = comms.order_by(Comment.score.asc()).all() + elif sort == "new": + comments = comms.order_by(Comment.created_utc.desc()).all() + elif sort == "old": + comments = comms.order_by(Comment.created_utc.asc()).all() + elif sort == "controversial": + comments = sorted(comms.all(), key=lambda x: x[0].score_disputed, reverse=True) + elif sort == "random": + c = comms.all() + comments = random.sample(c, k=len(c)) + else: + abort(422) + + output = [] + for c in comments: + comment = c[0] + if comment.author and comment.author.shadowbanned and not (v and v.id == comment.author_id): continue + comment._voted = c[1] or 0 + comment._is_blocking = c[2] or 0 + comment._is_blocked = c[3] or 0 + output.append(comment) + + post._preloaded_comments = output + + else: + comms = g.db.query( + Comment + ).filter( + Comment.parent_submission == post.id + ) + + if sort == "top": + comments = comms.order_by(Comment.score.desc()).all() + elif sort == "bottom": + comments = comms.order_by(Comment.score.asc()).all() + elif sort == "new": + comments = comms.order_by(Comment.created_utc.desc()).all() + elif sort == "old": + comments = comms.order_by(Comment.created_utc.asc()).all() + elif sort == "controversial": + comments = sorted(comms.all(), key=lambda x: x.score_disputed, reverse=True) + elif sort == "random": + c = comms.all() + comments = random.sample(c, k=len(c)) + else: + abort(422) + + if random.random() < 0.1: + for comment in comments: + if comment.author and comment.author.shadowbanned: + rand = random.randint(500,1400) + vote = CommentVote(user_id=rand, + vote_type=random.choice([-1, 1]), + comment_id=comment.id) + g.db.add(vote) + try: g.db.flush() + except: g.db.rollback() + comment.upvotes = comment.ups + comment.downvotes = comment.downs + g.db.add(comment) + + post._preloaded_comments = [x for x in comments if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + post.views += 1 g.db.add(post) g.db.commit() @@ -482,9 +622,7 @@ def submit_post(v): if repost: return redirect(repost.permalink) - board = get_guild(request.form.get('board', 'general'), graceful=True) - if not board: - board = get_guild('general') + board = g.db.query(Board).first() if not title: return {"html": lambda: (render_template("submit.html", @@ -616,7 +754,7 @@ def submit_post(v): board_name = board_name.lstrip("+") board_name = board_name.strip() - board = get_guild(board_name, graceful=True) + board = g.db.query(Board).first() if not board: diff --git a/drama/routes/users.py b/drama/routes/users.py index 491954f96..e747aaea2 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -413,7 +413,7 @@ def u_username_comments(username, v=None): is_following = (v and user.has_follower(v)) - board = get_board(1) + board = g.db.query(Board).first() return {"html": lambda: render_template("userpage_comments.html", u=user, v=v, diff --git a/drama/templates/errors/banaward.html b/drama/templates/errors/banaward.html index 1712f8b94..4c70e148d 100644 --- a/drama/templates/errors/banaward.html +++ b/drama/templates/errors/banaward.html @@ -1,17 +1,17 @@ {% extends "default.html" %} {% block title %} -403 Unauthorized +401 Not Authorized {% endblock %} -{% block pagetype %}error-405{% endblock %} +{% block pagetype %}error-401{% endblock %} {% block content %}
-

403 Unauthorized

+

401 Not Authorized

You have 0 ban awards (they're a patron perk):

https://rdrama.gumroad.com/l/tfcvri
diff --git a/drama/templates/errors/patron.html b/drama/templates/errors/patron.html index bdf323896..0d93876ca 100644 --- a/drama/templates/errors/patron.html +++ b/drama/templates/errors/patron.html @@ -1,17 +1,17 @@ {% extends "default.html" %} {% block title %} -403 Unauthorized +401 Not Authorized {% endblock %} -{% block pagetype %}error-403{% endblock %} +{% block pagetype %}error-401{% endblock %} {% block content %}
-

403 Unauthorized

+

401 Not Authorized

This page is only available to patrons:

https://rdrama.gumroad.com/l/tfcvri
diff --git a/snappy.txt b/snappy.txt index 1b964081e..082f10f69 100644 --- a/snappy.txt +++ b/snappy.txt @@ -2129,4 +2129,10 @@ Fuck it, I'm gonna take my meds and go out for my daily run Because I'm not fat, you see, but I am a schizo -:crazyeyes: \ No newline at end of file +:crazyeyes: +{[para]} +My plan is to buy a slumlord rental property in a shithole city, get a bunch of illegal women living there on section 8, knock them all up while keeping my name off the birth certificates, and then report them to health and human services once they can't make babies any more. My kids will end up in the foster care system, where the half-mexican boys will be turned gay by pedophiles (thereby preventing dilution of white women and ensuring that the gays are too busy with brown kids to molest white kids), and the girls will do as hapa/castillo girls do and exclusively date white guys. + +Without their kids the illegal women will invariably go insane or kill themselves, ensuring that tax dollars don't go towards their maintenance in old age. + +I also want to set up something that looks from the outside like a hippy commune, but is actually a fascist compound - American Juche with Crunchy Granola Characteristics, if you want to get technical. All the women will wear sundresses and sandals, all the men will be jacked, and the only thing vaccinated will be the livestock. As long as we say on paper that our kids are all gay or trans, and all the men and women are gay or trans, we should escape notice until it's too late. If the feds try to pull an ATF we'll put the men in sundresses and play music at them until they go away, or do oiled up Greco-Roman wrestling until they get uncomfortable and look away. \ No newline at end of file