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

@ -222,22 +222,34 @@ class User(db.Model, UserMixin):
raise Exception("Permission {} is not related to users".format(perm.name)) raise Exception("Permission {} is not related to users".format(perm.name))
def canCommentRL(self): 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) one_min_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=1)
if ThreadReply.query.filter_by(author=self) \ 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 return False
hour_ago = datetime.datetime.utcnow() - datetime.timedelta(hours=1) hour_ago = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
if ThreadReply.query.filter_by(author=self) \ 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 False
return True return True
def canOpenThreadRL(self): 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) hour_ago = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
return Thread.query.filter_by(author=self) \ 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): def __eq__(self, other):
if other is None: if other is None:

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