Fix small bug with ban calculation

If a user had a permaban, there would be a comparison error between the
current time and the expiration time (none).

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-06-26 20:27:42 -07:00
parent fb61239147
commit 356196db26
2 changed files with 5 additions and 5 deletions

View File

@@ -37,8 +37,8 @@ def is_banned(ip: str, board: Optional["Board"]) -> bool:
now = timezone.now()
bans = [ban for ban in get_ip_bans(ip) if ban.board == board or not ban.board]
if bans:
active = [ban for ban in bans if ban.expires > now]
expired = [ban for ban in bans if ban.expires <= now]
active = [ban for ban in bans if not ban.expires or ban.expires > now]
expired = [ban for ban in bans if ban.expires and ban.expires <= now]
# Delete expired bans
for ban in expired:
ban.delete()

View File

@@ -35,7 +35,7 @@ class BannedView(TemplateView):
bans = get_ip_bans(ip)
now = timezone.now()
active_bans = [ban for ban in bans if ban.expires > now]
active_bans = [ban for ban in bans if not ban.expires or ban.expires > now]
context["bans"] = bans
context["active_bans"] = active_bans
context["ip"] = ip
@@ -215,10 +215,10 @@ class BanCreateView(PermissionRequiredMixin, edit.CreateView):
if ban.board == self.board or ban.board is None
]
context["previous_bans"] = [
ban for ban in bans if ban.expires is not None and ban.expires < now
ban for ban in bans if ban.expires and ban.expires < now
]
context["current_bans"] = [
ban for ban in bans if ban.expires is None or ban.expires > now
ban for ban in bans if not ban.expires or ban.expires > now
]
context["templates"] = BanTemplate.objects.filter(
Q(board=self.board) | Q(board=None)