Increase thread/comment ratelimiting based on rank

This commit is contained in:
rubenwardy 2020-08-18 18:10:42 +01:00
parent 1c4fe1b80c
commit e85d1755f0
2 changed files with 28 additions and 13 deletions

View File

@ -222,22 +222,34 @@ class User(db.Model, UserMixin):
raise Exception("Permission {} is not related to users".format(perm.name))
def canCommentRL(self):
factor = 1
if self.rank.atLeast(UserRank.ADMIN):
return True
elif self.rank.atLeast(UserRank.TRUSTED_MEMBER):
factor *= 2
one_min_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=1)
if ThreadReply.query.filter_by(author=self) \
.filter(ThreadReply.created_at > one_min_ago).count() >= 3:
.filter(ThreadReply.created_at > one_min_ago).count() >= 3 * factor:
return False
hour_ago = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
if ThreadReply.query.filter_by(author=self) \
.filter(ThreadReply.created_at > hour_ago).count() >= 20:
.filter(ThreadReply.created_at > hour_ago).count() >= 20 * factor:
return False
return True
def canOpenThreadRL(self):
factor = 1
if self.rank.atLeast(UserRank.ADMIN):
return True
elif self.rank.atLeast(UserRank.TRUSTED_MEMBER):
factor *= 5
hour_ago = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
return Thread.query.filter_by(author=self) \
.filter(Thread.created_at > hour_ago).count() < 2
.filter(Thread.created_at > hour_ago).count() < 2 * factor
def __eq__(self, other):
if other is None:

View File

@ -128,17 +128,20 @@ class PackageTreeNode:
result["optional_depends"] = []
def checkDependencies(deps):
for dep in result["depends"]:
if not basenamePattern.match(dep):
if " " in dep:
raise MinetestCheckError(("Invalid dependency name '{}' for mod at {}, did you forget a comma?") \
.format(dep, self.relative))
else:
raise MinetestCheckError(("Invalid dependency name '{}' for mod at {}, names must only contain a-z0-9_.") \
.format(dep, self.relative))
# Check dependencies
for dep in result["depends"]:
if not basenamePattern.match(dep):
raise MinetestCheckError(("Invalid dependency name '{}' for mod at {}, names must only contain a-z0-9_.") \
.format(dep, self.relative))
for dep in result["optional_depends"]:
if not basenamePattern.match(dep):
raise MinetestCheckError(("Invalid dependency name '{}' for mod at {}, names must only contain a-z0-9_.") \
.format(dep, self.relative))
checkDependencies(result["depends"])
checkDependencies(result["optional_depends"])
# Fix games using "name" as "title"
if self.type == ContentType.GAME: