mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 03:37:28 +01:00
Add thread watchers
This commit is contained in:
parent
e8cc685f89
commit
68b7a5e922
@ -92,7 +92,6 @@ class Permission(enum.Enum):
|
|||||||
else:
|
else:
|
||||||
raise Exception("Non-global permission checked globally. Use Package.checkPerm or User.checkPerm instead.")
|
raise Exception("Non-global permission checked globally. Use Package.checkPerm or User.checkPerm instead.")
|
||||||
|
|
||||||
|
|
||||||
class User(db.Model, UserMixin):
|
class User(db.Model, UserMixin):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
@ -665,6 +664,11 @@ class EditRequestChange(db.Model):
|
|||||||
setattr(package, self.key.name, self.newValue)
|
setattr(package, self.key.name, self.newValue)
|
||||||
|
|
||||||
|
|
||||||
|
watchers = db.Table("watchers",
|
||||||
|
db.Column("user_id", db.Integer, db.ForeignKey("user.id"), primary_key=True),
|
||||||
|
db.Column("thread_id", db.Integer, db.ForeignKey("thread.id"), primary_key=True)
|
||||||
|
)
|
||||||
|
|
||||||
class Thread(db.Model):
|
class Thread(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
@ -679,6 +683,9 @@ class Thread(db.Model):
|
|||||||
|
|
||||||
replies = db.relationship("ThreadReply", backref="thread", lazy="dynamic")
|
replies = db.relationship("ThreadReply", backref="thread", lazy="dynamic")
|
||||||
|
|
||||||
|
watchers = db.relationship("User", secondary=watchers, lazy="subquery", \
|
||||||
|
backref=db.backref("watching", lazy=True))
|
||||||
|
|
||||||
def checkPerm(self, user, perm):
|
def checkPerm(self, user, perm):
|
||||||
if not user.is_authenticated:
|
if not user.is_authenticated:
|
||||||
return not self.private
|
return not self.private
|
||||||
|
@ -48,6 +48,20 @@ def thread_page(id):
|
|||||||
db.session.add(reply)
|
db.session.add(reply)
|
||||||
|
|
||||||
thread.replies.append(reply)
|
thread.replies.append(reply)
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
for user in thread.watchers:
|
||||||
|
if user != current_user:
|
||||||
|
triggerNotif(user, current_user, msg, url_for("thread_page", id=thread.id))
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(url_for("thread_page", id=id))
|
return redirect(url_for("thread_page", id=id))
|
||||||
@ -111,6 +125,10 @@ def new_thread_page():
|
|||||||
thread.package = package
|
thread.package = package
|
||||||
db.session.add(thread)
|
db.session.add(thread)
|
||||||
|
|
||||||
|
thread.watchers.append(current_user)
|
||||||
|
if package is not None and package.author != current_user:
|
||||||
|
thread.watchers.append(package.author)
|
||||||
|
|
||||||
reply = ThreadReply()
|
reply = ThreadReply()
|
||||||
reply.thread = thread
|
reply.thread = thread
|
||||||
reply.author = current_user
|
reply.author = current_user
|
||||||
@ -127,7 +145,6 @@ def new_thread_page():
|
|||||||
if package is not None:
|
if package is not None:
|
||||||
triggerNotif(package.author, current_user,
|
triggerNotif(package.author, current_user,
|
||||||
"New thread '{}' on package {}".format(thread.title, package.title), url_for("thread_page", id=thread.id))
|
"New thread '{}' on package {}".format(thread.title, package.title), url_for("thread_page", id=thread.id))
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
34
migrations/versions/de004661c5e1_.py
Normal file
34
migrations/versions/de004661c5e1_.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: de004661c5e1
|
||||||
|
Revises: 605b3d74ada1
|
||||||
|
Create Date: 2018-06-11 23:38:38.611039
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'de004661c5e1'
|
||||||
|
down_revision = '605b3d74ada1'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('watchers',
|
||||||
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('thread_id', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['thread_id'], ['thread.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('user_id', 'thread_id')
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table('watchers')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user