Post to approval thread when package status changes

This commit is contained in:
rubenwardy 2024-01-10 00:48:15 +00:00
parent 8367fd14a8
commit 8eb3604caf
2 changed files with 24 additions and 1 deletions

@ -44,7 +44,7 @@ from app.models import Package, Tag, db, User, Tags, PackageState, Permission, P
PackageScreenshot, NotificationType, AuditLogEntry, PackageAlias, PackageProvides, PackageGameSupport, \ PackageScreenshot, NotificationType, AuditLogEntry, PackageAlias, PackageProvides, PackageGameSupport, \
PackageDailyStats, Collection 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, \ 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/") @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) 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 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) 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() db.session.commit()

@ -139,6 +139,28 @@ def post_bot_message(package: Package, title: str, message: str):
thread.replies.append(reply) 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]: 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(",")]) return get_games_from_list(session, [name.strip() for name in csv.split(",")])