mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-08 08:33:45 +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)
|
||||
|
||||
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":
|
||||
|
@ -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())
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()))
|
||||
|
@ -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()
|
||||
|
@ -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())
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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):
|
||||
|
@ -18,12 +18,26 @@ Notifications
|
||||
{% for n in current_user.notifications %}
|
||||
<a class="list-group-item list-group-item-action" href="{{ n.url }}">
|
||||
<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">
|
||||
{{ n.title}}
|
||||
</div>
|
||||
|
||||
<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
|
||||
class="img-responsive user-photo img-thumbnail img-thumbnail-1"
|
||||
style="max-height: 22px;"
|
||||
|
@ -189,18 +189,18 @@ def is_package_page(f):
|
||||
return decorated_function
|
||||
|
||||
|
||||
def addNotification(target, causer, title, url):
|
||||
def addNotification(target, causer, title, url, package=None):
|
||||
try:
|
||||
iter(target)
|
||||
for x in target:
|
||||
addNotification(x, causer, title, url)
|
||||
addNotification(x, causer, title, url, package)
|
||||
return
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
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)
|
||||
Notification.query.filter_by(user=target, causer=causer, title=title, url=url, package=package).delete()
|
||||
notif = Notification(target, causer, title, url, package)
|
||||
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