diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-12-25 17:51:29 +0000 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-12-25 17:51:29 +0000 |
commit | 09150a4dbb74e9fb0d9fe4bdc5ced3ac246cd0e9 (patch) | |
tree | 6a79e990698c72053a396456f04ed8b7af0d4981 /app/models.py | |
parent | c726f56b3edbc2b97b82b777bada83a2097acb80 (diff) | |
download | cheatdb-09150a4dbb74e9fb0d9fe4bdc5ced3ac246cd0e9.tar.xz |
Allow users to discard their own topics
Diffstat (limited to 'app/models.py')
-rw-r--r-- | app/models.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models.py b/app/models.py index 545a7f1..3a41c83 100644 --- a/app/models.py +++ b/app/models.py @@ -79,6 +79,7 @@ class Permission(enum.Enum): SEE_THREAD = "SEE_THREAD" CREATE_THREAD = "CREATE_THREAD" UNAPPROVE_PACKAGE = "UNAPPROVE_PACKAGE" + TOPIC_DISCARD = "TOPIC_DISCARD" # Only return true if the permission is valid for *all* contexts # See Package.checkPerm for package-specific contexts @@ -843,6 +844,21 @@ class ForumTopic(db.Model): "created_at": self.created_at.isoformat(), } + def checkPerm(self, user, perm): + if not user.is_authenticated: + return False + + if type(perm) == str: + perm = Permission[perm] + elif type(perm) != Permission: + raise Exception("Unknown permission given to ForumTopic.checkPerm()") + + if perm == Permission.TOPIC_DISCARD: + return self.author == user or user.rank.atLeast(UserRank.EDITOR) + + else: + raise Exception("Permission {} is not related to topics".format(perm.name)) + # Setup Flask-User db_adapter = SQLAlchemyAdapter(db, User) # Register the User model |