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:
@@ -37,8 +37,8 @@ def is_banned(ip: str, board: Optional["Board"]) -> bool:
|
|||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
bans = [ban for ban in get_ip_bans(ip) if ban.board == board or not ban.board]
|
bans = [ban for ban in get_ip_bans(ip) if ban.board == board or not ban.board]
|
||||||
if bans:
|
if bans:
|
||||||
active = [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 <= now]
|
expired = [ban for ban in bans if ban.expires and ban.expires <= now]
|
||||||
# Delete expired bans
|
# Delete expired bans
|
||||||
for ban in expired:
|
for ban in expired:
|
||||||
ban.delete()
|
ban.delete()
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class BannedView(TemplateView):
|
|||||||
bans = get_ip_bans(ip)
|
bans = get_ip_bans(ip)
|
||||||
|
|
||||||
now = timezone.now()
|
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["bans"] = bans
|
||||||
context["active_bans"] = active_bans
|
context["active_bans"] = active_bans
|
||||||
context["ip"] = ip
|
context["ip"] = ip
|
||||||
@@ -215,10 +215,10 @@ class BanCreateView(PermissionRequiredMixin, edit.CreateView):
|
|||||||
if ban.board == self.board or ban.board is None
|
if ban.board == self.board or ban.board is None
|
||||||
]
|
]
|
||||||
context["previous_bans"] = [
|
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"] = [
|
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(
|
context["templates"] = BanTemplate.objects.filter(
|
||||||
Q(board=self.board) | Q(board=None)
|
Q(board=self.board) | Q(board=None)
|
||||||
|
|||||||
Reference in New Issue
Block a user