order unban_utc properly

pull/222/head
Aevann 2024-02-03 00:39:02 +02:00
parent 4a9efafbb0
commit 091e449284
6 changed files with 17 additions and 14 deletions

View File

@ -118,7 +118,7 @@ class User(Base):
enemies = deferred(Column(String))
enemies_html = deferred(Column(String))
is_banned = Column(Integer, ForeignKey("users.id"))
unban_utc = Column(Integer, default=0)
unban_utc = Column(Integer)
ban_reason = deferred(Column(String))
is_muted = Column(Boolean, default=False, nullable=False)
login_nonce = Column(Integer, default=0)
@ -654,7 +654,7 @@ class User(Base):
@property
@lazy
def unban_string(self):
if self.unban_utc == 0:
if not self.unban_utc:
return "permanently banned"
wait = self.unban_utc - int(time.time())
@ -1035,7 +1035,7 @@ class User(Base):
else:
self.unban_utc = int(time.time()) + (days * 86400)
else:
self.unban_utc = 0
self.unban_utc = None
self.is_banned = admin.id if admin else AUTOJANNY_ID
if reason and len(reason) <= 256:
@ -1046,12 +1046,12 @@ class User(Base):
@property
@lazy
def is_suspended(self):
return (self.is_banned and (self.unban_utc == 0 or self.unban_utc > time.time()))
return (self.is_banned and (not self.unban_utc or self.unban_utc > time.time()))
@property
@lazy
def is_permabanned(self):
return (self.is_banned and self.unban_utc == 0)
return (self.is_banned and not self.unban_utc)
@property
@lazy

View File

@ -254,7 +254,7 @@ def revert_actions(v, username):
for user in users:
user.shadowbanned = None
user.unban_utc = 0
user.unban_utc = None
user.ban_reason = None
if user.is_banned:
user.is_banned = None
@ -263,7 +263,7 @@ def revert_actions(v, username):
for u in get_alt_graph(user.id):
u.shadowbanned = None
u.unban_utc = 0
u.unban_utc = None
u.ban_reason = None
if u.is_banned:
u.is_banned = None
@ -1193,7 +1193,7 @@ def unban_user(fullname, v):
abort(403, "You can't undo a ban award!")
user.is_banned = None
user.unban_utc = 0
user.unban_utc = None
if not user.shadowbanned:
user.ban_reason = None
send_repeatable_notification(user.id, f"@{v.username} (a site admin) has unbanned you!")
@ -1202,7 +1202,7 @@ def unban_user(fullname, v):
for x in get_alt_graph(user.id):
if x.is_banned: send_repeatable_notification(x.id, f"@{v.username} (a site admin) has unbanned you!")
x.is_banned = None
x.unban_utc = 0
x.unban_utc = None
if not x.shadowbanned:
x.ban_reason = None
g.db.add(x)

View File

@ -290,7 +290,7 @@ def award_thing(v, thing_type, id):
author.unban_utc -= 86400
send_repeatable_notification(author.id, "Your ban duration has been reduced by 1 day!")
else:
author.unban_utc = 0
author.unban_utc = None
author.is_banned = None
if not author.shadowbanned:
author.ban_reason = None

View File

@ -112,12 +112,12 @@ def check_for_alts(current, include_current_session=False):
elif u.is_permabanned and not current.is_permabanned:
current.is_banned = u.is_banned
current.ban_reason = u.ban_reason
current.unban_utc = 0
current.unban_utc = None
g.db.add(current)
elif current.is_permabanned and not u.is_permabanned:
u.is_banned = current.is_banned
u.ban_reason = current.ban_reason
u.unban_utc = 0
u.unban_utc = None
g.db.add(u)
if current.ban_reason == "Under Siege" and u.ban_reason and u.ban_reason != "Under Siege":

View File

@ -8,6 +8,7 @@ import gevent
import qrcode
from sqlalchemy.orm import aliased, load_only
from sqlalchemy.exc import IntegrityError
from sqlalchemy import nullslast
from files.classes import *
from files.classes.transactions import *
@ -334,7 +335,7 @@ def banned(v):
users = g.db.query(User).filter(
User.is_banned != None,
or_(User.unban_utc == 0, User.unban_utc > time.time()),
or_(User.unban_utc == None, User.unban_utc > time.time()),
)
total = users.count()
@ -349,7 +350,7 @@ def banned(v):
key = User.is_banned
else:
sort = "unban_utc"
key = User.unban_utc.desc()
key = nullslast(User.unban_utc)
users = users.order_by(key).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE)

View File

@ -0,0 +1,2 @@
alter table users alter column unban_utc drop not null;
update users set unban_utc=null where unban_utc=0;