Allow auto-approval for all users that aren't banned

This commit is contained in:
rubenwardy 2023-12-29 11:36:25 +00:00
parent 0488b129fc
commit 41477980df
3 changed files with 7 additions and 5 deletions

@ -118,7 +118,7 @@ def check_for_ban():
if current_user.rank == models.UserRank.BANNED: if current_user.rank == models.UserRank.BANNED:
current_user.rank = models.UserRank.MEMBER current_user.rank = models.UserRank.MEMBER
models.db.session.commit() models.db.session.commit()
elif current_user.ban or current_user.rank == models.UserRank.BANNED: elif current_user.is_banned:
if current_user.ban: if current_user.ban:
flash(gettext("Banned:") + " " + current_user.ban.message, "danger") flash(gettext("Banned:") + " " + current_user.ban.message, "danger")
else: else:

@ -1066,7 +1066,7 @@ class PackageRelease(db.Model):
return True return True
def check_perm(self, user, perm): def check_perm(self, user, perm):
if not user.is_authenticated: if not user.is_authenticated or user.is_banned:
return False return False
if type(perm) == str: if type(perm) == str:
@ -1092,9 +1092,7 @@ class PackageRelease(db.Model):
return count > 0 return count > 0
elif perm == Permission.APPROVE_RELEASE: elif perm == Permission.APPROVE_RELEASE:
return user.rank.at_least(UserRank.APPROVER) or \ return is_maintainer or user.rank.at_least(UserRank.APPROVER)
(is_maintainer and user.rank.at_least(
UserRank.MEMBER if self.approved else UserRank.NEW_MEMBER))
else: else:
raise Exception("Permission {} is not related to releases".format(perm.name)) raise Exception("Permission {} is not related to releases".format(perm.name))

@ -192,6 +192,10 @@ class User(db.Model, UserMixin):
ban = db.relationship("UserBan", foreign_keys="UserBan.user_id", back_populates="user", uselist=False) ban = db.relationship("UserBan", foreign_keys="UserBan.user_id", back_populates="user", uselist=False)
@property
def is_banned(self):
return (self.ban and not self.ban.has_expired) or self.rank == UserRank.BANNED
def get_dict(self): def get_dict(self):
from app.utils.flask import abs_url_for from app.utils.flask import abs_url_for
return { return {