From 356196db26ca67b94910a6b92f446d9e1f46d944 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sun, 26 Jun 2022 20:27:42 -0700 Subject: [PATCH] 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 --- board/utils.py | 4 ++-- board/views.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/board/utils.py b/board/utils.py index 4a1fe79..268be2b 100644 --- a/board/utils.py +++ b/board/utils.py @@ -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() diff --git a/board/views.py b/board/views.py index 5b203b3..e1a1498 100644 --- a/board/views.py +++ b/board/views.py @@ -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)