From 8eb3604cafebad5b640f26af4291e4fac288fe68 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 10 Jan 2024 00:48:15 +0000 Subject: [PATCH] Post to approval thread when package status changes --- app/blueprints/packages/packages.py | 3 ++- app/utils/models.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index f477efd8..7346a451 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -44,7 +44,7 @@ from app.models import Package, Tag, db, User, Tags, PackageState, Permission, P PackageScreenshot, NotificationType, AuditLogEntry, PackageAlias, PackageProvides, PackageGameSupport, \ PackageDailyStats, Collection from app.utils import is_user_bot, get_int_or_abort, is_package_page, abs_url_for, add_audit_log, get_package_by_info, \ - add_notification, get_system_user, rank_required, get_games_from_csv, get_daterange_options + add_notification, get_system_user, rank_required, get_games_from_csv, get_daterange_options, post_to_approval_thread @bp.route("/packages/") @@ -443,6 +443,7 @@ def move_to_state(package): add_notification(package.maintainers, current_user, NotificationType.PACKAGE_APPROVAL, msg, package.get_url("packages.view"), package) severity = AuditSeverity.NORMAL if current_user in package.maintainers else AuditSeverity.EDITOR add_audit_log(severity, current_user, msg, package.get_url("packages.view"), package) + post_to_approval_thread(package, current_user, msg, True) db.session.commit() diff --git a/app/utils/models.py b/app/utils/models.py index 0029726c..66626f64 100644 --- a/app/utils/models.py +++ b/app/utils/models.py @@ -139,6 +139,28 @@ def post_bot_message(package: Package, title: str, message: str): thread.replies.append(reply) +def post_to_approval_thread(package: Package, user: User, message: str, is_status_update=True): + thread = package.review_thread + if thread is None: + return + + reply = ThreadReply() + reply.thread = thread + reply.author = user + reply.is_status_update = is_status_update + reply.comment = message + db.session.add(reply) + + if is_status_update: + msg = f"{message} - {thread.title}" + else: + msg = f"New comment on '{thread.title}'" + + add_notification(thread.watchers, current_user, NotificationType.THREAD_REPLY, msg, thread.get_view_url(), package) + + thread.replies.append(reply) + + def get_games_from_csv(session: sqlalchemy.orm.Session, csv: str) -> List[Package]: return get_games_from_list(session, [name.strip() for name in csv.split(",")])