From c428a59397299bd9190904c522df7cd83cbaa139 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Sat, 15 Oct 2022 04:18:07 -0700 Subject: [PATCH 1/5] v -> v and v.client --- files/routes/users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/users.py b/files/routes/users.py index d2e5ec54e..c3869bf1a 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -913,7 +913,7 @@ def u_username_comments(username, v=None): listing = get_comments(ids, v=v) - if v.client or request.path.endswith(".json"): + if (v and v.client) or request.path.endswith(".json"): return {"data": [c.json for c in listing]} return render_template("userpage_comments.html", u=user, v=v, listing=listing, page=page, sort=sort, t=t,next_exists=next_exists, is_following=is_following, standalone=True) From c95e33831ca810400323dfe8f0e934112e658517 Mon Sep 17 00:00:00 2001 From: TLSM Date: Sat, 15 Oct 2022 07:23:29 -0400 Subject: [PATCH 2/5] Check for globals in calc_users; fix error pages. --- files/helpers/wrappers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 6bd5672a8..3f2466108 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -9,6 +9,10 @@ import user_agents import time def calc_users(v): + # Some globals we expect aren't available when rendering error pages + if not g.agent or not ('session_id' in session): + return '' + loggedin = cache.get(f'{SITE}_loggedin') or {} loggedout = cache.get(f'{SITE}_loggedout') or {} timestamp = int(time.time()) From 35fd90c9ca205eafb3c20de11e6ba141199c416a Mon Sep 17 00:00:00 2001 From: TLSM Date: Sat, 15 Oct 2022 07:27:26 -0400 Subject: [PATCH 3/5] Amend c95e33831: even fewer globals than expected. --- files/helpers/wrappers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 3f2466108..1caf45d85 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -10,7 +10,7 @@ import time def calc_users(v): # Some globals we expect aren't available when rendering error pages - if not g.agent or not ('session_id' in session): + if not g or not g.agent or not session or not ('session_id' in session): return '' loggedin = cache.get(f'{SITE}_loggedin') or {} From ed2b6938ba291ac222cdb324f8a1826257842391 Mon Sep 17 00:00:00 2001 From: TLSM Date: Sat, 15 Oct 2022 07:33:25 -0400 Subject: [PATCH 4/5] Amend 35fd90c9c: calc_users gets g but not g.agent. --- files/helpers/wrappers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 1caf45d85..4930c5301 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -10,7 +10,8 @@ import time def calc_users(v): # Some globals we expect aren't available when rendering error pages - if not g or not g.agent or not session or not ('session_id' in session): + if (not g or not hasattr(g, 'agent') + or not session or not ('session_id' in session)): return '' loggedin = cache.get(f'{SITE}_loggedin') or {} From 616e15ebb95f745c26e543f9dfa3265a11809ed3 Mon Sep 17 00:00:00 2001 From: TLSM Date: Sat, 15 Oct 2022 10:11:14 -0400 Subject: [PATCH 5/5] Fix posting/commenting from API. The rework to v.client meant that `is_bot` on Submission and Comment would attempt to be populated with a ClientAuth object when submitted by a bot other than Snappy or bbbb. SQLAlchemy requires an actual boolean, not just a truthy value. --- files/routes/comments.py | 4 +++- files/routes/posts.py | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index 0efbd291f..4465b82ee 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -255,7 +255,9 @@ def comment(v): if parent.author.any_block_exists(v) and v.admin_level < PERMS['POST_COMMENT_MODERATION']: abort(403, "You can't reply to users who have blocked you or users that you have blocked.") - is_bot = v.id != BBBB_ID and v.client or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID) + is_bot = (v.client is not None + and v.id != BBBB_ID + or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID)) execute_antispam_comment_check(body, v) diff --git a/files/routes/posts.py b/files/routes/posts.py index 15db20131..2f3fdadf0 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -877,8 +877,6 @@ def submit_post(v, sub=None): if embed and len(embed) > 1500: embed = None - is_bot = v.id != BBBB_ID and v.client or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID) - if request.values.get("ghost") and v.coins >= 100: v.charge_account('coins', 100) ghost = True @@ -894,7 +892,7 @@ def submit_post(v, sub=None): over_18=bool(request.values.get("over_18","")), new=bool(request.values.get("new","")), app_id=v.client.application.id if v.client else None, - is_bot = is_bot, + is_bot=(v.client is not None), url=url, body=body, body_html=body_html,