mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-24 06:51:29 +01:00
Rename triggerNotif to addNotification, add array support
This commit is contained in:
parent
307b8f8dde
commit
d0aecd0ee5
@ -25,7 +25,7 @@ from app.tasks.importtasks import importRepoScreenshot, makeVCSRelease, checkZip
|
|||||||
from app.tasks.forumtasks import importTopicList, checkAllForumAccounts
|
from app.tasks.forumtasks import importTopicList, checkAllForumAccounts
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import *
|
from wtforms import *
|
||||||
from app.utils import loginUser, rank_required, triggerNotif
|
from app.utils import loginUser, rank_required, addNotification
|
||||||
import datetime, os
|
import datetime, os
|
||||||
|
|
||||||
@bp.route("/admin/", methods=["GET", "POST"])
|
@bp.route("/admin/", methods=["GET", "POST"])
|
||||||
@ -108,7 +108,7 @@ def admin_page():
|
|||||||
makeVCSRelease.apply_async((rel.id, "master"), task_id=rel.task_id)
|
makeVCSRelease.apply_async((rel.id, "master"), task_id=rel.task_id)
|
||||||
|
|
||||||
msg = "{}: Release {} created".format(package.title, rel.title)
|
msg = "{}: Release {} created".format(package.title, rel.title)
|
||||||
triggerNotif(package.author, current_user, msg, rel.getEditURL())
|
addNotification(package.maintainers, current_user, msg, rel.getEditURL())
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
elif action == "cleanuploads":
|
elif action == "cleanuploads":
|
||||||
|
@ -99,8 +99,8 @@ def create_edit_editrequest_page(package, id=None):
|
|||||||
if wasChangeMade:
|
if wasChangeMade:
|
||||||
msg = "{}: Edit request #{} {}" \
|
msg = "{}: Edit request #{} {}" \
|
||||||
.format(package.title, erequest.id, "created" if id is None else "edited")
|
.format(package.title, erequest.id, "created" if id is None else "edited")
|
||||||
triggerNotif(package.author, current_user, msg, erequest.getURL())
|
addNotification(package.maintainers, current_user, msg, erequest.getURL())
|
||||||
triggerNotif(erequest.author, current_user, msg, erequest.getURL())
|
addNotification(erequest.author, current_user, msg, erequest.getURL())
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(erequest.getURL())
|
return redirect(erequest.getURL())
|
||||||
else:
|
else:
|
||||||
@ -142,8 +142,8 @@ def approve_editrequest_page(package, id):
|
|||||||
erequest.applyAll(package)
|
erequest.applyAll(package)
|
||||||
|
|
||||||
msg = "{}: Edit request #{} merged".format(package.title, erequest.id)
|
msg = "{}: Edit request #{} merged".format(package.title, erequest.id)
|
||||||
triggerNotif(erequest.author, current_user, msg, erequest.getURL())
|
addNotification(erequest.author, current_user, msg, erequest.getURL())
|
||||||
triggerNotif(package.author, current_user, msg, erequest.getURL())
|
addNotification(package.maintainers, current_user, msg, erequest.getURL())
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
@ -166,8 +166,8 @@ def reject_editrequest_page(package, id):
|
|||||||
erequest.status = 2
|
erequest.status = 2
|
||||||
|
|
||||||
msg = "{}: Edit request #{} rejected".format(package.title, erequest.id)
|
msg = "{}: Edit request #{} rejected".format(package.title, erequest.id)
|
||||||
triggerNotif(erequest.author, current_user, msg, erequest.getURL())
|
addNotification(erequest.author, current_user, msg, erequest.getURL())
|
||||||
triggerNotif(package.author, current_user, msg, erequest.getURL())
|
addNotification(package.maintainers, current_user, msg, erequest.getURL())
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
|
@ -265,7 +265,7 @@ def create_edit(author=None, name=None):
|
|||||||
return redirect(url_for("packages.create_edit", author=author, name=name))
|
return redirect(url_for("packages.create_edit", author=author, name=name))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
triggerNotif(package.author, current_user,
|
addNotification(package.maintainers, current_user,
|
||||||
"{} edited".format(package.title), package.getDetailsURL())
|
"{} edited".format(package.title), package.getDetailsURL())
|
||||||
|
|
||||||
form.populate_obj(package) # copy to row
|
form.populate_obj(package) # copy to row
|
||||||
@ -337,7 +337,7 @@ def approve(package):
|
|||||||
for s in screenshots:
|
for s in screenshots:
|
||||||
s.approved = True
|
s.approved = True
|
||||||
|
|
||||||
triggerNotif(package.author, current_user,
|
addNotification(package.maintainers, current_user,
|
||||||
"{} approved".format(package.title), package.getDetailsURL())
|
"{} approved".format(package.title), package.getDetailsURL())
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ def remove(package):
|
|||||||
package.soft_deleted = True
|
package.soft_deleted = True
|
||||||
|
|
||||||
url = url_for("users.profile", username=package.author.username)
|
url = url_for("users.profile", username=package.author.username)
|
||||||
triggerNotif(package.author, current_user,
|
addNotification(package.maintainers, current_user,
|
||||||
"{} deleted".format(package.title), url)
|
"{} deleted".format(package.title), url)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@ -373,7 +373,7 @@ def remove(package):
|
|||||||
|
|
||||||
package.approved = False
|
package.approved = False
|
||||||
|
|
||||||
triggerNotif(package.author, current_user,
|
addNotification(package.maintainers, current_user,
|
||||||
"{} unapproved".format(package.title), package.getDetailsURL())
|
"{} unapproved".format(package.title), package.getDetailsURL())
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@ -408,19 +408,19 @@ def edit_maintainers(package):
|
|||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
if not user in package.maintainers:
|
if not user in package.maintainers:
|
||||||
triggerNotif(user, current_user,
|
addNotification(user, current_user,
|
||||||
"Added you as a maintainer of {}".format(package.title), package.getDetailsURL())
|
"Added you as a maintainer of {}".format(package.title), package.getDetailsURL())
|
||||||
|
|
||||||
for user in package.maintainers:
|
for user in package.maintainers:
|
||||||
if user != package.author and not user in users:
|
if user != package.author and not user in users:
|
||||||
triggerNotif(user, current_user,
|
addNotification(user, current_user,
|
||||||
"Removed you as a maintainer of {}".format(package.title), package.getDetailsURL())
|
"Removed you as a maintainer of {}".format(package.title), package.getDetailsURL())
|
||||||
|
|
||||||
package.maintainers.clear()
|
package.maintainers.clear()
|
||||||
package.maintainers.extend(users)
|
package.maintainers.extend(users)
|
||||||
package.maintainers.append(package.author)
|
package.maintainers.append(package.author)
|
||||||
|
|
||||||
triggerNotif(package.author, current_user,
|
addNotification(package.author, current_user,
|
||||||
"Edited {} maintainers".format(package.title), package.getDetailsURL())
|
"Edited {} maintainers".format(package.title), package.getDetailsURL())
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@ -446,7 +446,7 @@ def remove_self_maintainers(package):
|
|||||||
else:
|
else:
|
||||||
package.maintainers.remove(current_user)
|
package.maintainers.remove(current_user)
|
||||||
|
|
||||||
triggerNotif(package.author, current_user,
|
addNotification(package.author, current_user,
|
||||||
"Removed themself as a maintainer of {}".format(package.title), package.getDetailsURL())
|
"Removed themself as a maintainer of {}".format(package.title), package.getDetailsURL())
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -93,7 +93,7 @@ def create_release(package):
|
|||||||
makeVCSRelease.apply_async((rel.id, form["vcsLabel"].data), task_id=rel.task_id)
|
makeVCSRelease.apply_async((rel.id, form["vcsLabel"].data), task_id=rel.task_id)
|
||||||
|
|
||||||
msg = "{}: Release {} created".format(package.title, rel.title)
|
msg = "{}: Release {} created".format(package.title, rel.title)
|
||||||
triggerNotif(package.author, current_user, msg, rel.getEditURL())
|
addNotification(package.maintainers, current_user, msg, rel.getEditURL())
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(url_for("tasks.check", id=rel.task_id, r=rel.getEditURL()))
|
return redirect(url_for("tasks.check", id=rel.task_id, r=rel.getEditURL()))
|
||||||
@ -113,7 +113,7 @@ def create_release(package):
|
|||||||
checkZipRelease.apply_async((rel.id, uploadedPath), task_id=rel.task_id)
|
checkZipRelease.apply_async((rel.id, uploadedPath), task_id=rel.task_id)
|
||||||
|
|
||||||
msg = "{}: Release {} created".format(package.title, rel.title)
|
msg = "{}: Release {} created".format(package.title, rel.title)
|
||||||
triggerNotif(package.author, current_user, msg, rel.getEditURL())
|
addNotification(package.maintainers, current_user, msg, rel.getEditURL())
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(url_for("tasks.check", id=rel.task_id, r=rel.getEditURL()))
|
return redirect(url_for("tasks.check", id=rel.task_id, r=rel.getEditURL()))
|
||||||
|
@ -22,7 +22,7 @@ from flask_wtf import FlaskForm
|
|||||||
from wtforms import *
|
from wtforms import *
|
||||||
from wtforms.validators import *
|
from wtforms.validators import *
|
||||||
from app.models import db, PackageReview, Thread, ThreadReply
|
from app.models import db, PackageReview, Thread, ThreadReply
|
||||||
from app.utils import is_package_page, triggerNotif
|
from app.utils import is_package_page, addNotification
|
||||||
|
|
||||||
class ReviewForm(FlaskForm):
|
class ReviewForm(FlaskForm):
|
||||||
title = StringField("Title", [InputRequired(), Length(3,100)])
|
title = StringField("Title", [InputRequired(), Length(3,100)])
|
||||||
@ -88,8 +88,7 @@ def review(package):
|
|||||||
else:
|
else:
|
||||||
notif_msg = "Updated review '{}' on package {}".format(form.title.data, package.title)
|
notif_msg = "Updated review '{}' on package {}".format(form.title.data, package.title)
|
||||||
|
|
||||||
for maintainer in package.maintainers:
|
addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id))
|
||||||
triggerNotif(maintainer, current_user, notif_msg, url_for("threads.view", id=thread.id))
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ def create_screenshot(package, id=None):
|
|||||||
|
|
||||||
msg = "{}: Screenshot added {}" \
|
msg = "{}: Screenshot added {}" \
|
||||||
.format(package.title, ss.title)
|
.format(package.title, ss.title)
|
||||||
triggerNotif(package.author, current_user, msg, package.getDetailsURL())
|
addNotification(package.maintainers, current_user, msg, package.getDetailsURL())
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ bp = Blueprint("threads", __name__)
|
|||||||
|
|
||||||
from flask_user import *
|
from flask_user import *
|
||||||
from app.models import *
|
from app.models import *
|
||||||
from app.utils import triggerNotif, clearNotifications
|
from app.utils import addNotification, clearNotifications
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
@ -113,10 +113,7 @@ def view(id):
|
|||||||
msg = "New comment on '{}' on package {}".format(thread.title, thread.package.title)
|
msg = "New comment on '{}' on package {}".format(thread.title, thread.package.title)
|
||||||
|
|
||||||
|
|
||||||
for user in thread.watchers:
|
addNotification(thread.watchers, current_user, msg, url_for("threads.view", id=thread.id))
|
||||||
if user != current_user:
|
|
||||||
triggerNotif(user, current_user, msg, url_for("threads.view", id=thread.id))
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(url_for("threads.view", id=id))
|
return redirect(url_for("threads.view", id=id))
|
||||||
@ -206,13 +203,12 @@ def new():
|
|||||||
notif_msg = None
|
notif_msg = None
|
||||||
if package is not None:
|
if package is not None:
|
||||||
notif_msg = "New thread '{}' on package {}".format(thread.title, package.title)
|
notif_msg = "New thread '{}' on package {}".format(thread.title, package.title)
|
||||||
for maintainer in package.maintainers:
|
addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id))
|
||||||
triggerNotif(maintainer, current_user, notif_msg, url_for("threads.view", id=thread.id))
|
|
||||||
else:
|
else:
|
||||||
notif_msg = "New thread '{}'".format(thread.title)
|
notif_msg = "New thread '{}'".format(thread.title)
|
||||||
|
|
||||||
for user in User.query.filter(User.rank >= UserRank.EDITOR).all():
|
editors = User.query.filter(User.rank >= UserRank.EDITOR).all()
|
||||||
triggerNotif(user, current_user, notif_msg, url_for("threads.view", id=thread.id))
|
addNotification(editors, current_user, notif_msg, url_for("threads.view", id=thread.id))
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
15
app/utils.py
15
app/utils.py
@ -188,12 +188,19 @@ def is_package_page(f):
|
|||||||
|
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
||||||
def triggerNotif(owner, causer, title, url):
|
|
||||||
if owner.rank.atLeast(UserRank.NEW_MEMBER) and owner != causer:
|
def addNotification(target, causer, title, url):
|
||||||
Notification.query.filter_by(user=owner, causer=causer, title=title, url=url).delete()
|
if not isinstance(target, User):
|
||||||
notif = Notification(owner, causer, title, url)
|
for x in target:
|
||||||
|
addNotification(x, causer, title, url)
|
||||||
|
return
|
||||||
|
|
||||||
|
if target.rank.atLeast(UserRank.NEW_MEMBER) and target != causer:
|
||||||
|
Notification.query.filter_by(user=target, causer=causer, title=title, url=url).delete()
|
||||||
|
notif = Notification(target, causer, title, url)
|
||||||
db.session.add(notif)
|
db.session.add(notif)
|
||||||
|
|
||||||
|
|
||||||
def clearNotifications(url):
|
def clearNotifications(url):
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
Notification.query.filter_by(user=current_user, url=url).delete()
|
Notification.query.filter_by(user=current_user, url=url).delete()
|
||||||
|
Loading…
Reference in New Issue
Block a user