Add ability to delete threads

This reverts commit 78630b3071.
This commit is contained in:
rubenwardy
2020-12-09 18:40:25 +00:00
parent b28732ee74
commit fd0b203f1e
4 changed files with 54 additions and 5 deletions

View File

@@ -94,6 +94,7 @@ class Permission(enum.Enum):
CREATE_THREAD = "CREATE_THREAD"
COMMENT_THREAD = "COMMENT_THREAD"
LOCK_THREAD = "LOCK_THREAD"
DELETE_THREAD = "DELETE_THREAD"
DELETE_REPLY = "DELETE_REPLY"
EDIT_REPLY = "EDIT_REPLY"
UNAPPROVE_PACKAGE = "UNAPPROVE_PACKAGE"
@@ -1352,7 +1353,7 @@ class Thread(db.Model):
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
replies = db.relationship("ThreadReply", back_populates="thread", lazy="dynamic",
order_by=db.asc("thread_reply_id"))
order_by=db.asc("thread_reply_id"), cascade="all, delete, delete-orphan")
watchers = db.relationship("User", secondary=watchers, lazy="subquery", backref="watching")
@@ -1386,7 +1387,7 @@ class Thread(db.Model):
elif perm == Permission.COMMENT_THREAD:
return canSee and (not self.locked or user.rank.atLeast(UserRank.MODERATOR))
elif perm == Permission.LOCK_THREAD:
elif perm == Permission.LOCK_THREAD or perm == Permission.DELETE_THREAD:
return user.rank.atLeast(UserRank.MODERATOR)
else: