Add Draft/ChangesNeeded notification admin action

This commit is contained in:
rubenwardy 2021-07-19 23:02:20 +01:00
parent f49c60d7f6
commit 4523849641
2 changed files with 27 additions and 1 deletions

@ -21,13 +21,14 @@ from celery import group
from flask import * from flask import *
from flask_login import current_user, login_user from flask_login import current_user, login_user
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from sqlalchemy import or_
from wtforms import * from wtforms import *
from wtforms.validators import InputRequired, Length from wtforms.validators import InputRequired, Length
from app.models import * from app.models import *
from app.tasks.forumtasks import importTopicList, checkAllForumAccounts from app.tasks.forumtasks import importTopicList, checkAllForumAccounts
from app.tasks.importtasks import importRepoScreenshot, checkZipRelease, check_for_updates from app.tasks.importtasks import importRepoScreenshot, checkZipRelease, check_for_updates
from app.utils import rank_required, addAuditLog, addNotification from app.utils import rank_required, addAuditLog, addNotification, get_system_user
from . import bp from . import bp
@ -184,6 +185,30 @@ def admin_page():
flash("Started update configs", "success") flash("Started update configs", "success")
return redirect(url_for("admin.admin_page")) return redirect(url_for("admin.admin_page"))
elif action == "remindwip":
users = User.query.filter(User.packages.any(or_(Package.state==PackageState.WIP, Package.state==PackageState.CHANGES_NEEDED)))
system_user = get_system_user()
for user in users:
packages = db.session.query(Package.title).filter(
Package.author_id==user.id,
or_(Package.state==PackageState.WIP, Package.state==PackageState.CHANGES_NEEDED)) \
.all()
# Who needs translations?
packages = [pkg[0] for pkg in packages]
if len(packages) >= 3:
packages[len(packages) - 1] = "and " + packages[len(packages) - 1]
packages_list = ", ".join(packages)
else:
packages_list = "and ".join(packages)
havent = "haven't" if len(packages) > 1 else "hasn't"
addNotification(user, system_user, NotificationType.PACKAGE_APPROVAL,
f"Did you forget? {packages_list} {havent} been submitted for review yet",
url_for('todo.view_user', username=user.username))
db.session.commit()
else: else:
flash("Unknown action: " + action, "danger") flash("Unknown action: " + action, "danger")

@ -39,6 +39,7 @@
<option value="importscreenshots">Import screenshots from VCS</option> <option value="importscreenshots">Import screenshots from VCS</option>
<option value="addupdateconfig">Add update configs</option> <option value="addupdateconfig">Add update configs</option>
<option value="runupdateconfig">Run update configs</option> <option value="runupdateconfig">Run update configs</option>
<option value="remindwip">Send WIP/Changes needed notifications</option>
</select> </select>
<input type="submit" value="Perform" class="col-sm-auto btn btn-primary ml-2" /> <input type="submit" value="Perform" class="col-sm-auto btn btn-primary ml-2" />
</div> </div>