From 9d822af154f2e0c2e8778a23f0a30ea36c168ab9 Mon Sep 17 00:00:00 2001 From: atrc445 Date: Tue, 3 Aug 2021 19:55:02 +0200 Subject: [PATCH 1/2] fix seed-db, make comments and private messages work without pusher by catching and printing pusher auth error exception --- drama/routes/comments.py | 34 +++++++++++++++++++++------------- drama/routes/users.py | 32 ++++++++++++++++++++------------ seed-db.sql | 28 +++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 26 deletions(-) diff --git a/drama/routes/comments.py b/drama/routes/comments.py index f70f00400..e6135546f 100644 --- a/drama/routes/comments.py +++ b/drama/routes/comments.py @@ -1,3 +1,6 @@ +import traceback +import sys + from drama.helpers.wrappers import * from drama.helpers.filters import * from drama.helpers.alerts import * @@ -5,7 +8,7 @@ from drama.helpers.images import * from drama.helpers.session import * from drama.classes import * from drama.routes.front import comment_idlist -from pusher_push_notifications import PushNotifications +from pusher_push_notifications import PushNotifications, PusherAuthError from flask import * from drama.__main__ import app, limiter @@ -522,18 +525,23 @@ def api_comment(v): except: g.db.rollback() if parent.author.id != v.id: - beams_client.publish_to_interests( - interests=[str(parent.author.id)], - publish_body={ - 'web': { - 'notification': { - 'title': f'New reply by @{v.username}', - 'body': c.body, - 'deep_link': f'https://{site}{c.permalink}?context=5#context', + try: + beams_client.publish_to_interests( + interests=[str(parent.author.id)], + publish_body={ + 'web': { + 'notification': { + 'title': f'New reply by @{v.username}', + 'body': c.body, + 'deep_link': f'https://{site}{c.permalink}?context=5#context', + }, + }, }, - }, - }, - ) + ) + except PusherAuthError as e: + traceback.print_tb(e.__traceback__) + sys.stderr.flush() + @@ -858,4 +866,4 @@ def unsave_comment(cid, v): g.db.delete(save) - return "", 204 \ No newline at end of file + return "", 204 diff --git a/drama/routes/users.py b/drama/routes/users.py index d2f1e18cd..8d39af87b 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -1,6 +1,8 @@ import qrcode import io import time +import traceback +import sys from drama.classes.user import ViewerRelationship from drama.helpers.alerts import * @@ -9,7 +11,7 @@ from drama.helpers.markdown import * from drama.mail import * from flask import * from drama.__main__ import app, limiter -from pusher_push_notifications import PushNotifications +from pusher_push_notifications import PushNotifications, PusherAuthError site = environ.get("domain").strip() @@ -142,18 +144,24 @@ def message2(v, username): if existing: return redirect('/notifications?all=true') send_pm(v.id, user, message) - beams_client.publish_to_interests( - interests=[str(user.id)], - publish_body={ - 'web': { - 'notification': { - 'title': f'New message from @{v.username}', - 'body': message, - 'deep_link': f'https://{site}/notifications', + + try: + beams_client.publish_to_interests( + interests=[str(user.id)], + publish_body={ + 'web': { + 'notification': { + 'title': f'New message from @{v.username}', + 'body': message, + 'deep_link': f'https://{site}/notifications', + }, }, }, - }, - ) + ) + except PusherAuthError as e: + traceback.print_tb(e.__traceback__) + sys.stderr.flush() + return redirect('/notifications?all=true') @app.get("/2faqr/") @@ -541,4 +549,4 @@ def saved_comments(v, username): listing=listing, page=page, next_exists=next_exists, - standalone=True) \ No newline at end of file + standalone=True) diff --git a/seed-db.sql b/seed-db.sql index 55f3eca56..1db135429 100644 --- a/seed-db.sql +++ b/seed-db.sql @@ -1 +1,27 @@ -INSERT INTO public.badge_defs VALUES (6, 'Beta User', 'Joined during open beta', 'beta.png', 4, 3, NULL); \ No newline at end of file +INSERT INTO public.users + (id, username, passhash, + created_utc, admin_level, over_18, is_activated, is_banned, + is_private, login_nonce, dramacoins, original_username, bio, + defaultsorting, defaultsortingcomments, namecolor, titlecolor, theme, themecolor) +VALUES +-- admin:admin + (1, 'admin', 'pbkdf2:sha256:150000$z6kifBOp$1ee4ab0b1d565d541715d128d4d00dee2800f157ac3865546efed28bbb726dac', + 0, 6, false, true, 0, + false, 0, 0, 'admin', '', + 'hot', 'top', 'ff66ac', 'ff66ac', 'dark', 'ff66ac'); + +INSERT INTO public.users + (id, username, passhash, + created_utc, admin_level, over_18, is_activated, is_banned, + is_private, login_nonce, dramacoins, original_username, bio, + defaultsorting, defaultsortingcomments, namecolor, titlecolor, theme, themecolor) +VALUES +-- user:user + (2, 'user', 'pbkdf2:sha256:150000$gB7i3Vsj$7e78baba3b3eb8030bef8850f7016369221152488b27b50f48432bd7713a7e31', + 0, 0, false, true, 0, + false, 0, 0, 'user', '', + 'hot', 'top', 'ff66ac', 'ff66ac', 'dark', 'ff66ac'); + +INSERT INTO public.badge_defs VALUES (6, 'Beta User', 'Joined Drama during open beta', 'beta.png', 4, 3, NULL); + +SELECT pg_catalog.setval('public.users_id_seq', 2, true); From f9a13429fbf98427d481255cd65c3708b03d498e Mon Sep 17 00:00:00 2001 From: atrc445 Date: Tue, 3 Aug 2021 23:23:59 +0200 Subject: [PATCH 2/2] unfix seed-ab --- seed-db.sql | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/seed-db.sql b/seed-db.sql index 1db135429..fc88b293a 100644 --- a/seed-db.sql +++ b/seed-db.sql @@ -1,27 +1 @@ -INSERT INTO public.users - (id, username, passhash, - created_utc, admin_level, over_18, is_activated, is_banned, - is_private, login_nonce, dramacoins, original_username, bio, - defaultsorting, defaultsortingcomments, namecolor, titlecolor, theme, themecolor) -VALUES --- admin:admin - (1, 'admin', 'pbkdf2:sha256:150000$z6kifBOp$1ee4ab0b1d565d541715d128d4d00dee2800f157ac3865546efed28bbb726dac', - 0, 6, false, true, 0, - false, 0, 0, 'admin', '', - 'hot', 'top', 'ff66ac', 'ff66ac', 'dark', 'ff66ac'); - -INSERT INTO public.users - (id, username, passhash, - created_utc, admin_level, over_18, is_activated, is_banned, - is_private, login_nonce, dramacoins, original_username, bio, - defaultsorting, defaultsortingcomments, namecolor, titlecolor, theme, themecolor) -VALUES --- user:user - (2, 'user', 'pbkdf2:sha256:150000$gB7i3Vsj$7e78baba3b3eb8030bef8850f7016369221152488b27b50f48432bd7713a7e31', - 0, 0, false, true, 0, - false, 0, 0, 'user', '', - 'hot', 'top', 'ff66ac', 'ff66ac', 'dark', 'ff66ac'); - -INSERT INTO public.badge_defs VALUES (6, 'Beta User', 'Joined Drama during open beta', 'beta.png', 4, 3, NULL); - -SELECT pg_catalog.setval('public.users_id_seq', 2, true); +INSERT INTO public.badge_defs VALUES (6, 'Beta User', 'Joined during open beta', 'beta.png', 4, 3, NULL);