Add notifications for editing maintainers

This commit is contained in:
rubenwardy 2020-07-08 23:20:29 +01:00
parent b2809ed12e
commit 0e2ea27f54
2 changed files with 18 additions and 2 deletions

@ -374,7 +374,7 @@ def remove(package):
package.approved = False package.approved = False
triggerNotif(package.author, current_user, triggerNotif(package.author, current_user,
"{} deleted".format(package.title), package.getDetailsURL()) "{} unapproved".format(package.title), package.getDetailsURL())
db.session.commit() db.session.commit()
flash("Unapproved package", "success") flash("Unapproved package", "success")
@ -405,9 +405,25 @@ def edit_maintainers(package):
if request.method == "POST" and form.validate(): if request.method == "POST" and form.validate():
usernames = [x.strip().lower() for x in form.maintainers_str.data.split(",")] usernames = [x.strip().lower() for x in form.maintainers_str.data.split(",")]
users = User.query.filter(func.lower(User.username).in_(usernames)).all() users = User.query.filter(func.lower(User.username).in_(usernames)).all()
for user in users:
if not user in package.maintainers:
triggerNotif(user, current_user,
"Added you as a maintainer to {}".format(package.title), package.getDetailsURL())
for user in package.maintainers:
if not user in users:
triggerNotif(user, current_user,
"Removed you as a maintainer to {}".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)
if package.author != current_user:
triggerNotif(package.author, current_user,
"Edited {} maintainers".format(package.title), package.getDetailsURL())
db.session.commit() db.session.commit()
return redirect(package.getDetailsURL()) return redirect(package.getDetailsURL())

@ -190,7 +190,7 @@ def is_package_page(f):
def triggerNotif(owner, causer, title, url): def triggerNotif(owner, causer, title, url):
if owner.rank.atLeast(UserRank.NEW_MEMBER) and owner != causer: if owner.rank.atLeast(UserRank.NEW_MEMBER) and owner != causer:
Notification.query.filter_by(user=owner, url=url).delete() Notification.query.filter_by(user=owner, causer=causer, title=title, url=url).delete()
notif = Notification(owner, causer, title, url) notif = Notification(owner, causer, title, url)
db.session.add(notif) db.session.add(notif)