diff --git a/app/blueprints/admin/admin.py b/app/blueprints/admin/admin.py index 5c63fb25..e4fc78ba 100644 --- a/app/blueprints/admin/admin.py +++ b/app/blueprints/admin/admin.py @@ -107,8 +107,8 @@ def admin_page(): makeVCSRelease.apply_async((rel.id, "master"), task_id=rel.task_id) - msg = "{}: Release {} created".format(package.title, rel.title) - addNotification(package.maintainers, current_user, msg, rel.getEditURL()) + msg = "Release {} created".format(rel.title) + addNotification(package.maintainers, current_user, msg, rel.getEditURL(), package) db.session.commit() elif action == "cleanuploads": diff --git a/app/blueprints/packages/editrequests.py b/app/blueprints/packages/editrequests.py index 3dd61596..cc17af5a 100644 --- a/app/blueprints/packages/editrequests.py +++ b/app/blueprints/packages/editrequests.py @@ -97,10 +97,10 @@ def create_edit_editrequest_page(package, id=None): wasChangeMade = True if wasChangeMade: - msg = "{}: Edit request #{} {}" \ - .format(package.title, erequest.id, "created" if id is None else "edited") - addNotification(package.maintainers, current_user, msg, erequest.getURL()) - addNotification(erequest.author, current_user, msg, erequest.getURL()) + msg = "Edit request #{} {}" \ + .format(erequest.id, "created" if id is None else "edited") + addNotification(package.maintainers, current_user, msg, erequest.getURL(), package) + addNotification(erequest.author, current_user, msg, erequest.getURL(), package) db.session.commit() return redirect(erequest.getURL()) else: @@ -140,9 +140,9 @@ def approve_editrequest_page(package, id): erequest.status = 1 erequest.applyAll(package) - msg = "{}: Edit request #{} merged".format(package.title, erequest.id) - addNotification(erequest.author, current_user, msg, erequest.getURL()) - addNotification(package.maintainers, current_user, msg, erequest.getURL()) + msg = "Edit request #{} merged".format(erequest.id) + addNotification(erequest.author, current_user, msg, erequest.getURL(), package) + addNotification(package.maintainers, current_user, msg, erequest.getURL(), package) db.session.commit() return redirect(package.getDetailsURL()) @@ -164,9 +164,9 @@ def reject_editrequest_page(package, id): else: erequest.status = 2 - msg = "{}: Edit request #{} rejected".format(package.title, erequest.id) - addNotification(erequest.author, current_user, msg, erequest.getURL()) - addNotification(package.maintainers, current_user, msg, erequest.getURL()) + msg = "Edit request #{} rejected".format(erequest.id) + addNotification(erequest.author, current_user, msg, erequest.getURL(), package) + addNotification(package.maintainers, current_user, msg, erequest.getURL(), package) db.session.commit() return redirect(package.getDetailsURL()) diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index b765eae1..3f264441 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -266,7 +266,7 @@ def create_edit(author=None, name=None): else: addNotification(package.maintainers, current_user, - "{} edited".format(package.title), package.getDetailsURL()) + "Edited {}".format(package.title), package.getDetailsURL(), package) form.populate_obj(package) # copy to row @@ -338,7 +338,7 @@ def approve(package): s.approved = True addNotification(package.maintainers, current_user, - "{} approved".format(package.title), package.getDetailsURL()) + "Approved {}".format(package.title), package.getDetailsURL(), package) db.session.commit() return redirect(package.getDetailsURL()) @@ -360,7 +360,7 @@ def remove(package): url = url_for("users.profile", username=package.author.username) addNotification(package.maintainers, current_user, - "{} deleted".format(package.title), url) + "Deleted {}".format(package.title), url, package) db.session.commit() flash("Deleted package", "success") @@ -374,7 +374,7 @@ def remove(package): package.approved = False addNotification(package.maintainers, current_user, - "{} unapproved".format(package.title), package.getDetailsURL()) + "Unapproved {}".format(package.title), package.getDetailsURL(), package) db.session.commit() flash("Unapproved package", "success") @@ -409,19 +409,19 @@ def edit_maintainers(package): for user in users: if not user in package.maintainers: 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(), package) for user in package.maintainers: if user != package.author and not user in users: 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) package.maintainers.clear() package.maintainers.extend(users) package.maintainers.append(package.author) addNotification(package.author, current_user, - "Edited {} maintainers".format(package.title), package.getDetailsURL()) + "Edited {} maintainers".format(package.title), package.getDetailsURL(), package) db.session.commit() @@ -447,7 +447,7 @@ def remove_self_maintainers(package): package.maintainers.remove(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(), package) db.session.commit() diff --git a/app/blueprints/packages/releases.py b/app/blueprints/packages/releases.py index 33e8a1f8..4c069f29 100644 --- a/app/blueprints/packages/releases.py +++ b/app/blueprints/packages/releases.py @@ -92,8 +92,8 @@ def create_release(package): makeVCSRelease.apply_async((rel.id, form["vcsLabel"].data), task_id=rel.task_id) - msg = "{}: Release {} created".format(package.title, rel.title) - addNotification(package.maintainers, current_user, msg, rel.getEditURL()) + msg = "Release {} created".format(rel.title) + addNotification(package.maintainers, current_user, msg, rel.getEditURL(), package) db.session.commit() return redirect(url_for("tasks.check", id=rel.task_id, r=rel.getEditURL())) @@ -112,8 +112,8 @@ def create_release(package): checkZipRelease.apply_async((rel.id, uploadedPath), task_id=rel.task_id) - msg = "{}: Release {} created".format(package.title, rel.title) - addNotification(package.maintainers, current_user, msg, rel.getEditURL()) + msg = "Release {} created".format(rel.title) + addNotification(package.maintainers, current_user, msg, rel.getEditURL(), package) db.session.commit() return redirect(url_for("tasks.check", id=rel.task_id, r=rel.getEditURL())) diff --git a/app/blueprints/packages/reviews.py b/app/blueprints/packages/reviews.py index a662f77e..ee6e3a55 100644 --- a/app/blueprints/packages/reviews.py +++ b/app/blueprints/packages/reviews.py @@ -97,11 +97,11 @@ def review(package): notif_msg = None if was_new: - notif_msg = "New review '{}' on package {}".format(form.title.data, package.title) + notif_msg = "New review '{}'".format(form.title.data) else: - notif_msg = "Updated review '{}' on package {}".format(form.title.data, package.title) + notif_msg = "Updated review '{}'".format(form.title.data) - addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id)) + addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id), package) db.session.commit() @@ -129,8 +129,8 @@ def delete_review(package): thread.review = None - notif_msg = "Deleted review '{}' on package {}, comments were kept as a thread".format(thread.title, package.title) - addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id)) + notif_msg = "Deleted review '{}', comments were kept as a thread".format(thread.title) + addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id), package) db.session.delete(review) db.session.commit() diff --git a/app/blueprints/packages/screenshots.py b/app/blueprints/packages/screenshots.py index 93644691..40cf4d25 100644 --- a/app/blueprints/packages/screenshots.py +++ b/app/blueprints/packages/screenshots.py @@ -60,9 +60,9 @@ def create_screenshot(package, id=None): ss.approved = package.checkPerm(current_user, Permission.APPROVE_SCREENSHOT) db.session.add(ss) - msg = "{}: Screenshot added {}" \ - .format(package.title, ss.title) - addNotification(package.maintainers, current_user, msg, package.getDetailsURL()) + msg = "Screenshot added {}" \ + .format(ss.title) + addNotification(package.maintainers, current_user, msg, package.getDetailsURL(), package) db.session.commit() return redirect(package.getDetailsURL()) diff --git a/app/blueprints/threads/__init__.py b/app/blueprints/threads/__init__.py index ad585458..a4728a03 100644 --- a/app/blueprints/threads/__init__.py +++ b/app/blueprints/threads/__init__.py @@ -106,14 +106,8 @@ def view(id): if not current_user in thread.watchers: thread.watchers.append(current_user) - msg = None - if thread.package is None: - msg = "New comment on '{}'".format(thread.title) - else: - msg = "New comment on '{}' on package {}".format(thread.title, thread.package.title) - - - addNotification(thread.watchers, current_user, msg, url_for("threads.view", id=thread.id)) + msg = "New comment on '{}'".format(thread.title) + addNotification(thread.watchers, current_user, msg, url_for("threads.view", id=thread.id), thread.package) db.session.commit() return redirect(url_for("threads.view", id=id)) @@ -200,15 +194,12 @@ def new(): if is_review_thread: package.review_thread = thread - notif_msg = None + notif_msg = "New thread '{}'".format(thread.title) if package is not None: - notif_msg = "New thread '{}' on package {}".format(thread.title, package.title) - addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id)) - else: - notif_msg = "New thread '{}'".format(thread.title) + addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id), package) editors = User.query.filter(User.rank >= UserRank.EDITOR).all() - addNotification(editors, current_user, notif_msg, url_for("threads.view", id=thread.id)) + addNotification(editors, current_user, notif_msg, url_for("threads.view", id=thread.id), package) db.session.commit() diff --git a/app/models.py b/app/models.py index 3a9ddf49..acd427a3 100644 --- a/app/models.py +++ b/app/models.py @@ -240,23 +240,31 @@ class UserEmailVerification(db.Model): user = db.relationship("User", foreign_keys=[user_id]) class Notification(db.Model): - id = db.Column(db.Integer, primary_key=True) - user_id = db.Column(db.Integer, db.ForeignKey("user.id")) - causer_id = db.Column(db.Integer, db.ForeignKey("user.id")) - user = db.relationship("User", foreign_keys=[user_id]) - causer = db.relationship("User", foreign_keys=[causer_id]) + id = db.Column(db.Integer, primary_key=True) - title = db.Column(db.String(100), nullable=False) - url = db.Column(db.String(200), nullable=True) + user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) + user = db.relationship("User", foreign_keys=[user_id]) - def __init__(self, us, cau, titl, ur): - if len(titl) > 100: + causer_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) + causer = db.relationship("User", foreign_keys=[causer_id]) + + title = db.Column(db.String(100), nullable=False) + url = db.Column(db.String(200), nullable=True) + + package_id = db.Column(db.Integer, db.ForeignKey("package.id"), nullable=True) + package = db.relationship("Package", foreign_keys=[package_id]) + + created_at = db.Column(db.DateTime, nullable=True, default=datetime.datetime.utcnow) + + def __init__(self, user, causer, title, url, package=None): + if len(title) > 100: title = title[:99] + "…" - self.user = us - self.causer = cau - self.title = titl - self.url = ur + self.user = user + self.causer = causer + self.title = title + self.url = url + self.package = package class License(db.Model): diff --git a/app/templates/notifications/list.html b/app/templates/notifications/list.html index 61f884a8..d2503124 100644 --- a/app/templates/notifications/list.html +++ b/app/templates/notifications/list.html @@ -18,12 +18,26 @@ Notifications {% for n in current_user.notifications %}
+ {% if n.package %} + +
+ + + + {{ n.package.title }} + +
+ {% endif %} +
{{ n.title}}
- {{ n.causer.display_name }} + {{ n.causer.display_name }}