diff --git a/app/blueprints/admin/admin.py b/app/blueprints/admin/admin.py index acfc7711..91a9f494 100644 --- a/app/blueprints/admin/admin.py +++ b/app/blueprints/admin/admin.py @@ -22,11 +22,12 @@ from flask import * from flask_login import current_user from flask_wtf import FlaskForm from wtforms import * +from wtforms.validators import InputRequired, Length from app.models import * from app.tasks.forumtasks import importTopicList, checkAllForumAccounts from app.tasks.importtasks import importRepoScreenshot, checkZipRelease, updateMetaFromRelease, importForeignDownloads -from app.utils import loginUser, rank_required +from app.utils import loginUser, rank_required, addAuditLog, addNotification from . import bp @@ -189,3 +190,26 @@ def switch_user(): # Process GET or invalid POST return render_template("admin/switch_user.html", form=form) + + +class SendNotificationForm(FlaskForm): + title = StringField("Title", [InputRequired(), Length(1, 300)]) + url = StringField("URL", [InputRequired(), Length(1, 100)], default="/") + submit = SubmitField("Send") + + +@bp.route("/admin/send-notification/", methods=["GET", "POST"]) +@rank_required(UserRank.ADMIN) +def send_bulk_notification(): + form = SendNotificationForm(request.form) + if form.validate_on_submit(): + addAuditLog(AuditSeverity.MODERATION, current_user, + "Sent bulk notification", None, None, form.title.data) + + users = User.query.filter(User.rank >= UserRank.NEW_MEMBER).all() + addNotification(users, current_user, NotificationType.OTHER, form.title.data, form.url.data, None) + db.session.commit() + + return redirect(url_for("admin.admin_page")) + + return render_template("admin/send_bulk_notification.html", form=form) diff --git a/app/templates/admin/list.html b/app/templates/admin/list.html index 1dc75e33..65f36cfa 100644 --- a/app/templates/admin/list.html +++ b/app/templates/admin/list.html @@ -14,6 +14,7 @@ Version Editor Warning Editor Send bulk email + Send bulk notification Sign in as another user diff --git a/app/templates/admin/send_bulk_notification.html b/app/templates/admin/send_bulk_notification.html new file mode 100644 index 00000000..e10020bb --- /dev/null +++ b/app/templates/admin/send_bulk_notification.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% block title %} + {{ _("Send bulk notification") }} +{% endblock %} + +{% block content %} +

{{ self.title() }}

+ +

+ BE VERY CAREFUL. + This will send a notification to all active users. +

+ +{% from "macros/forms.html" import render_field, render_submit_field %} +
+ {{ form.hidden_tag() }} + {{ render_field(form.title) }} + {{ render_field(form.url) }} + {{ render_submit_field(form.submit) }} +
+ +{% endblock %}