mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-08 16:43:47 +01:00
Add package and created_at to Notifications
This commit is contained in:
parent
9bf20df941
commit
5f7be4b433
@ -107,8 +107,8 @@ 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(rel.title)
|
||||||
addNotification(package.maintainers, current_user, msg, rel.getEditURL())
|
addNotification(package.maintainers, current_user, msg, rel.getEditURL(), package)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
elif action == "cleanuploads":
|
elif action == "cleanuploads":
|
||||||
|
@ -97,10 +97,10 @@ def create_edit_editrequest_page(package, id=None):
|
|||||||
wasChangeMade = True
|
wasChangeMade = True
|
||||||
|
|
||||||
if wasChangeMade:
|
if wasChangeMade:
|
||||||
msg = "{}: Edit request #{} {}" \
|
msg = "Edit request #{} {}" \
|
||||||
.format(package.title, erequest.id, "created" if id is None else "edited")
|
.format(erequest.id, "created" if id is None else "edited")
|
||||||
addNotification(package.maintainers, current_user, msg, erequest.getURL())
|
addNotification(package.maintainers, current_user, msg, erequest.getURL(), package)
|
||||||
addNotification(erequest.author, current_user, msg, erequest.getURL())
|
addNotification(erequest.author, current_user, msg, erequest.getURL(), package)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(erequest.getURL())
|
return redirect(erequest.getURL())
|
||||||
else:
|
else:
|
||||||
@ -140,9 +140,9 @@ def approve_editrequest_page(package, id):
|
|||||||
erequest.status = 1
|
erequest.status = 1
|
||||||
erequest.applyAll(package)
|
erequest.applyAll(package)
|
||||||
|
|
||||||
msg = "{}: Edit request #{} merged".format(package.title, erequest.id)
|
msg = "Edit request #{} merged".format(erequest.id)
|
||||||
addNotification(erequest.author, current_user, msg, erequest.getURL())
|
addNotification(erequest.author, current_user, msg, erequest.getURL(), package)
|
||||||
addNotification(package.maintainers, current_user, msg, erequest.getURL())
|
addNotification(package.maintainers, current_user, msg, erequest.getURL(), package)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
@ -164,9 +164,9 @@ def reject_editrequest_page(package, id):
|
|||||||
else:
|
else:
|
||||||
erequest.status = 2
|
erequest.status = 2
|
||||||
|
|
||||||
msg = "{}: Edit request #{} rejected".format(package.title, erequest.id)
|
msg = "Edit request #{} rejected".format(erequest.id)
|
||||||
addNotification(erequest.author, current_user, msg, erequest.getURL())
|
addNotification(erequest.author, current_user, msg, erequest.getURL(), package)
|
||||||
addNotification(package.maintainers, current_user, msg, erequest.getURL())
|
addNotification(package.maintainers, current_user, msg, erequest.getURL(), package)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
|
@ -266,7 +266,7 @@ def create_edit(author=None, name=None):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
addNotification(package.maintainers, current_user,
|
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
|
form.populate_obj(package) # copy to row
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ def approve(package):
|
|||||||
s.approved = True
|
s.approved = True
|
||||||
|
|
||||||
addNotification(package.maintainers, current_user,
|
addNotification(package.maintainers, current_user,
|
||||||
"{} approved".format(package.title), package.getDetailsURL())
|
"Approved {}".format(package.title), package.getDetailsURL(), package)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
@ -360,7 +360,7 @@ def remove(package):
|
|||||||
|
|
||||||
url = url_for("users.profile", username=package.author.username)
|
url = url_for("users.profile", username=package.author.username)
|
||||||
addNotification(package.maintainers, current_user,
|
addNotification(package.maintainers, current_user,
|
||||||
"{} deleted".format(package.title), url)
|
"Deleted {}".format(package.title), url, package)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
flash("Deleted package", "success")
|
flash("Deleted package", "success")
|
||||||
@ -374,7 +374,7 @@ def remove(package):
|
|||||||
package.approved = False
|
package.approved = False
|
||||||
|
|
||||||
addNotification(package.maintainers, current_user,
|
addNotification(package.maintainers, current_user,
|
||||||
"{} unapproved".format(package.title), package.getDetailsURL())
|
"Unapproved {}".format(package.title), package.getDetailsURL(), package)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
flash("Unapproved package", "success")
|
flash("Unapproved package", "success")
|
||||||
@ -409,19 +409,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:
|
||||||
addNotification(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(), package)
|
||||||
|
|
||||||
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:
|
||||||
addNotification(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)
|
||||||
|
|
||||||
package.maintainers.clear()
|
package.maintainers.clear()
|
||||||
package.maintainers.extend(users)
|
package.maintainers.extend(users)
|
||||||
package.maintainers.append(package.author)
|
package.maintainers.append(package.author)
|
||||||
|
|
||||||
addNotification(package.author, current_user,
|
addNotification(package.author, current_user,
|
||||||
"Edited {} maintainers".format(package.title), package.getDetailsURL())
|
"Edited {} maintainers".format(package.title), package.getDetailsURL(), package)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@ -447,7 +447,7 @@ def remove_self_maintainers(package):
|
|||||||
package.maintainers.remove(current_user)
|
package.maintainers.remove(current_user)
|
||||||
|
|
||||||
addNotification(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(), package)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -92,8 +92,8 @@ 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(rel.title)
|
||||||
addNotification(package.maintainers, current_user, msg, rel.getEditURL())
|
addNotification(package.maintainers, current_user, msg, rel.getEditURL(), package)
|
||||||
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()))
|
||||||
@ -112,8 +112,8 @@ 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(rel.title)
|
||||||
addNotification(package.maintainers, current_user, msg, rel.getEditURL())
|
addNotification(package.maintainers, current_user, msg, rel.getEditURL(), package)
|
||||||
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()))
|
||||||
|
@ -97,11 +97,11 @@ def review(package):
|
|||||||
|
|
||||||
notif_msg = None
|
notif_msg = None
|
||||||
if was_new:
|
if was_new:
|
||||||
notif_msg = "New review '{}' on package {}".format(form.title.data, package.title)
|
notif_msg = "New review '{}'".format(form.title.data)
|
||||||
else:
|
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()
|
db.session.commit()
|
||||||
|
|
||||||
@ -129,8 +129,8 @@ def delete_review(package):
|
|||||||
|
|
||||||
thread.review = None
|
thread.review = None
|
||||||
|
|
||||||
notif_msg = "Deleted review '{}' on package {}, comments were kept as a thread".format(thread.title, package.title)
|
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))
|
addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id), package)
|
||||||
|
|
||||||
db.session.delete(review)
|
db.session.delete(review)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -60,9 +60,9 @@ def create_screenshot(package, id=None):
|
|||||||
ss.approved = package.checkPerm(current_user, Permission.APPROVE_SCREENSHOT)
|
ss.approved = package.checkPerm(current_user, Permission.APPROVE_SCREENSHOT)
|
||||||
db.session.add(ss)
|
db.session.add(ss)
|
||||||
|
|
||||||
msg = "{}: Screenshot added {}" \
|
msg = "Screenshot added {}" \
|
||||||
.format(package.title, ss.title)
|
.format(ss.title)
|
||||||
addNotification(package.maintainers, current_user, msg, package.getDetailsURL())
|
addNotification(package.maintainers, current_user, msg, package.getDetailsURL(), package)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
@ -106,14 +106,8 @@ def view(id):
|
|||||||
if not current_user in thread.watchers:
|
if not current_user in thread.watchers:
|
||||||
thread.watchers.append(current_user)
|
thread.watchers.append(current_user)
|
||||||
|
|
||||||
msg = None
|
|
||||||
if thread.package is None:
|
|
||||||
msg = "New comment on '{}'".format(thread.title)
|
msg = "New comment on '{}'".format(thread.title)
|
||||||
else:
|
addNotification(thread.watchers, current_user, msg, url_for("threads.view", id=thread.id), thread.package)
|
||||||
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))
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(url_for("threads.view", id=id))
|
return redirect(url_for("threads.view", id=id))
|
||||||
@ -200,15 +194,12 @@ def new():
|
|||||||
if is_review_thread:
|
if is_review_thread:
|
||||||
package.review_thread = thread
|
package.review_thread = thread
|
||||||
|
|
||||||
notif_msg = None
|
|
||||||
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)
|
notif_msg = "New thread '{}'".format(thread.title)
|
||||||
|
if package is not None:
|
||||||
|
addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id), package)
|
||||||
|
|
||||||
editors = User.query.filter(User.rank >= UserRank.EDITOR).all()
|
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()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -241,22 +241,30 @@ class UserEmailVerification(db.Model):
|
|||||||
|
|
||||||
class Notification(db.Model):
|
class Notification(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
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_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
|
||||||
user = db.relationship("User", foreign_keys=[user_id])
|
user = db.relationship("User", foreign_keys=[user_id])
|
||||||
|
|
||||||
|
causer_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
|
||||||
causer = db.relationship("User", foreign_keys=[causer_id])
|
causer = db.relationship("User", foreign_keys=[causer_id])
|
||||||
|
|
||||||
title = db.Column(db.String(100), nullable=False)
|
title = db.Column(db.String(100), nullable=False)
|
||||||
url = db.Column(db.String(200), nullable=True)
|
url = db.Column(db.String(200), nullable=True)
|
||||||
|
|
||||||
def __init__(self, us, cau, titl, ur):
|
package_id = db.Column(db.Integer, db.ForeignKey("package.id"), nullable=True)
|
||||||
if len(titl) > 100:
|
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] + "…"
|
title = title[:99] + "…"
|
||||||
|
|
||||||
self.user = us
|
self.user = user
|
||||||
self.causer = cau
|
self.causer = causer
|
||||||
self.title = titl
|
self.title = title
|
||||||
self.url = ur
|
self.url = url
|
||||||
|
self.package = package
|
||||||
|
|
||||||
|
|
||||||
class License(db.Model):
|
class License(db.Model):
|
||||||
|
@ -18,12 +18,26 @@ Notifications
|
|||||||
{% for n in current_user.notifications %}
|
{% for n in current_user.notifications %}
|
||||||
<a class="list-group-item list-group-item-action" href="{{ n.url }}">
|
<a class="list-group-item list-group-item-action" href="{{ n.url }}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
{% if n.package %}
|
||||||
|
|
||||||
|
<div class="col-sm-auto text-muted">
|
||||||
|
<img
|
||||||
|
class="img-responsive"
|
||||||
|
style="max-height: 22px; max-width: 22px;"
|
||||||
|
src="{{ n.package.getThumbnailURL(1) }}" />
|
||||||
|
|
||||||
|
<span class="pl-2">
|
||||||
|
{{ n.package.title }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
{{ n.title}}
|
{{ n.title}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-auto text-muted text-right">
|
<div class="col-sm-auto text-muted text-right">
|
||||||
<span class="pr-1">{{ n.causer.display_name }}</span>
|
<span class="pr-2">{{ n.causer.display_name }}</span>
|
||||||
<img
|
<img
|
||||||
class="img-responsive user-photo img-thumbnail img-thumbnail-1"
|
class="img-responsive user-photo img-thumbnail img-thumbnail-1"
|
||||||
style="max-height: 22px;"
|
style="max-height: 22px;"
|
||||||
|
@ -189,18 +189,18 @@ def is_package_page(f):
|
|||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
||||||
|
|
||||||
def addNotification(target, causer, title, url):
|
def addNotification(target, causer, title, url, package=None):
|
||||||
try:
|
try:
|
||||||
iter(target)
|
iter(target)
|
||||||
for x in target:
|
for x in target:
|
||||||
addNotification(x, causer, title, url)
|
addNotification(x, causer, title, url, package)
|
||||||
return
|
return
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if target.rank.atLeast(UserRank.NEW_MEMBER) and target != causer:
|
if target.rank.atLeast(UserRank.NEW_MEMBER) and target != causer:
|
||||||
Notification.query.filter_by(user=target, causer=causer, title=title, url=url).delete()
|
Notification.query.filter_by(user=target, causer=causer, title=title, url=url, package=package).delete()
|
||||||
notif = Notification(target, causer, title, url)
|
notif = Notification(target, causer, title, url, package)
|
||||||
db.session.add(notif)
|
db.session.add(notif)
|
||||||
|
|
||||||
|
|
||||||
|
43
migrations/versions/f612e293070a_.py
Normal file
43
migrations/versions/f612e293070a_.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: f612e293070a
|
||||||
|
Revises: 019da77ba02d
|
||||||
|
Create Date: 2020-07-10 23:32:02.465374
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'f612e293070a'
|
||||||
|
down_revision = '019da77ba02d'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('notification', sa.Column('created_at', sa.DateTime(), nullable=True, server_default=datetime.datetime.utcnow().isoformat()))
|
||||||
|
op.add_column('notification', sa.Column('package_id', sa.Integer(), nullable=True))
|
||||||
|
op.alter_column('notification', 'causer_id',
|
||||||
|
existing_type=sa.INTEGER(),
|
||||||
|
nullable=False)
|
||||||
|
op.alter_column('notification', 'user_id',
|
||||||
|
existing_type=sa.INTEGER(),
|
||||||
|
nullable=False)
|
||||||
|
op.create_foreign_key(None, 'notification', 'package', ['package_id'], ['id'])
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_constraint(None, 'notification', type_='foreignkey')
|
||||||
|
op.alter_column('notification', 'user_id',
|
||||||
|
existing_type=sa.INTEGER(),
|
||||||
|
nullable=True)
|
||||||
|
op.alter_column('notification', 'causer_id',
|
||||||
|
existing_type=sa.INTEGER(),
|
||||||
|
nullable=True)
|
||||||
|
op.drop_column('notification', 'package_id')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user