From b7e40fb35cea56bab7164b3041258fcbe09ebb52 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:22:17 +1300 Subject: [PATCH] notify admin when new registration is waiting --- app/activitypub/util.py | 1 + app/auth/routes.py | 8 +++++++- app/post/routes.py | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 2a9be508..1ba0c9aa 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -484,6 +484,7 @@ def post_json_to_model(post_json, user, community) -> Post: if admin.id not in already_notified: notify = Notification(title='Suspicious content', url=post.ap_id, user_id=admin.id, author_id=user.id) db.session.add(notify) + admin.unread_notifications += 1 if domain.banned: post = None if not domain.banned: diff --git a/app/auth/routes.py b/app/auth/routes.py index 62591803..3e7bbf05 100644 --- a/app/auth/routes.py +++ b/app/auth/routes.py @@ -10,7 +10,7 @@ from app.auth import bp from app.auth.forms import LoginForm, RegistrationForm, ResetPasswordRequestForm, ResetPasswordForm from app.auth.util import random_token, normalize_utf from app.email import send_verification_email, send_password_reset_email -from app.models import User, utcnow, IpBan, UserRegistration +from app.models import User, utcnow, IpBan, UserRegistration, Notification, Site from app.utils import render_template, ip_address, user_ip_banned, user_cookie_banned, banned_ip_addresses, \ finalize_user_setup @@ -116,6 +116,12 @@ def register(): if g.site.registration_mode == 'RequireApplication': application = UserRegistration(user_id=user.id, answer=form.question.data) db.session.add(application) + for admin in Site.admins(): + notify = Notification(title='New registration', url='/admin/approve_registrations', user_id=admin.id, + author_id=user.id) + admin.unread_notifications += 1 + db.session.add(notify) + # todo: notify everyone with the "approve registrations" permission, instead of just all admins db.session.commit() return redirect(url_for('auth.please_wait')) else: diff --git a/app/post/routes.py b/app/post/routes.py index daf12fdb..a0ef2cb5 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -752,6 +752,7 @@ def post_report(post_id: int): if admin.id not in already_notified: notify = Notification(title='Suspicious content', url=post.ap_id, user_id=admin.id, author_id=current_user.id) db.session.add(notify) + admin.unread_notifications += 1 db.session.commit() # todo: federate report to originating instance @@ -853,6 +854,7 @@ def post_reply_report(post_id: int, comment_id: int): if admin.id not in already_notified: notify = Notification(title='Suspicious content', url=post.ap_id, user_id=admin.id, author_id=current_user.id) db.session.add(notify) + admin.unread_notifications += 1 db.session.commit() # todo: federate report to originating instance