forked from MarseyWorld/MarseyWorld
order unban_utc properly
parent
4a9efafbb0
commit
091e449284
|
@ -118,7 +118,7 @@ class User(Base):
|
||||||
enemies = deferred(Column(String))
|
enemies = deferred(Column(String))
|
||||||
enemies_html = deferred(Column(String))
|
enemies_html = deferred(Column(String))
|
||||||
is_banned = Column(Integer, ForeignKey("users.id"))
|
is_banned = Column(Integer, ForeignKey("users.id"))
|
||||||
unban_utc = Column(Integer, default=0)
|
unban_utc = Column(Integer)
|
||||||
ban_reason = deferred(Column(String))
|
ban_reason = deferred(Column(String))
|
||||||
is_muted = Column(Boolean, default=False, nullable=False)
|
is_muted = Column(Boolean, default=False, nullable=False)
|
||||||
login_nonce = Column(Integer, default=0)
|
login_nonce = Column(Integer, default=0)
|
||||||
|
@ -654,7 +654,7 @@ class User(Base):
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def unban_string(self):
|
def unban_string(self):
|
||||||
if self.unban_utc == 0:
|
if not self.unban_utc:
|
||||||
return "permanently banned"
|
return "permanently banned"
|
||||||
|
|
||||||
wait = self.unban_utc - int(time.time())
|
wait = self.unban_utc - int(time.time())
|
||||||
|
@ -1035,7 +1035,7 @@ class User(Base):
|
||||||
else:
|
else:
|
||||||
self.unban_utc = int(time.time()) + (days * 86400)
|
self.unban_utc = int(time.time()) + (days * 86400)
|
||||||
else:
|
else:
|
||||||
self.unban_utc = 0
|
self.unban_utc = None
|
||||||
|
|
||||||
self.is_banned = admin.id if admin else AUTOJANNY_ID
|
self.is_banned = admin.id if admin else AUTOJANNY_ID
|
||||||
if reason and len(reason) <= 256:
|
if reason and len(reason) <= 256:
|
||||||
|
@ -1046,12 +1046,12 @@ class User(Base):
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def is_suspended(self):
|
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
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def is_permabanned(self):
|
def is_permabanned(self):
|
||||||
return (self.is_banned and self.unban_utc == 0)
|
return (self.is_banned and not self.unban_utc)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
|
|
|
@ -254,7 +254,7 @@ def revert_actions(v, username):
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
user.shadowbanned = None
|
user.shadowbanned = None
|
||||||
user.unban_utc = 0
|
user.unban_utc = None
|
||||||
user.ban_reason = None
|
user.ban_reason = None
|
||||||
if user.is_banned:
|
if user.is_banned:
|
||||||
user.is_banned = None
|
user.is_banned = None
|
||||||
|
@ -263,7 +263,7 @@ def revert_actions(v, username):
|
||||||
|
|
||||||
for u in get_alt_graph(user.id):
|
for u in get_alt_graph(user.id):
|
||||||
u.shadowbanned = None
|
u.shadowbanned = None
|
||||||
u.unban_utc = 0
|
u.unban_utc = None
|
||||||
u.ban_reason = None
|
u.ban_reason = None
|
||||||
if u.is_banned:
|
if u.is_banned:
|
||||||
u.is_banned = None
|
u.is_banned = None
|
||||||
|
@ -1193,7 +1193,7 @@ def unban_user(fullname, v):
|
||||||
abort(403, "You can't undo a ban award!")
|
abort(403, "You can't undo a ban award!")
|
||||||
|
|
||||||
user.is_banned = None
|
user.is_banned = None
|
||||||
user.unban_utc = 0
|
user.unban_utc = None
|
||||||
if not user.shadowbanned:
|
if not user.shadowbanned:
|
||||||
user.ban_reason = None
|
user.ban_reason = None
|
||||||
send_repeatable_notification(user.id, f"@{v.username} (a site admin) has unbanned you!")
|
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):
|
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!")
|
if x.is_banned: send_repeatable_notification(x.id, f"@{v.username} (a site admin) has unbanned you!")
|
||||||
x.is_banned = None
|
x.is_banned = None
|
||||||
x.unban_utc = 0
|
x.unban_utc = None
|
||||||
if not x.shadowbanned:
|
if not x.shadowbanned:
|
||||||
x.ban_reason = None
|
x.ban_reason = None
|
||||||
g.db.add(x)
|
g.db.add(x)
|
||||||
|
|
|
@ -290,7 +290,7 @@ def award_thing(v, thing_type, id):
|
||||||
author.unban_utc -= 86400
|
author.unban_utc -= 86400
|
||||||
send_repeatable_notification(author.id, "Your ban duration has been reduced by 1 day!")
|
send_repeatable_notification(author.id, "Your ban duration has been reduced by 1 day!")
|
||||||
else:
|
else:
|
||||||
author.unban_utc = 0
|
author.unban_utc = None
|
||||||
author.is_banned = None
|
author.is_banned = None
|
||||||
if not author.shadowbanned:
|
if not author.shadowbanned:
|
||||||
author.ban_reason = None
|
author.ban_reason = None
|
||||||
|
|
|
@ -112,12 +112,12 @@ def check_for_alts(current, include_current_session=False):
|
||||||
elif u.is_permabanned and not current.is_permabanned:
|
elif u.is_permabanned and not current.is_permabanned:
|
||||||
current.is_banned = u.is_banned
|
current.is_banned = u.is_banned
|
||||||
current.ban_reason = u.ban_reason
|
current.ban_reason = u.ban_reason
|
||||||
current.unban_utc = 0
|
current.unban_utc = None
|
||||||
g.db.add(current)
|
g.db.add(current)
|
||||||
elif current.is_permabanned and not u.is_permabanned:
|
elif current.is_permabanned and not u.is_permabanned:
|
||||||
u.is_banned = current.is_banned
|
u.is_banned = current.is_banned
|
||||||
u.ban_reason = current.ban_reason
|
u.ban_reason = current.ban_reason
|
||||||
u.unban_utc = 0
|
u.unban_utc = None
|
||||||
g.db.add(u)
|
g.db.add(u)
|
||||||
|
|
||||||
if current.ban_reason == "Under Siege" and u.ban_reason and u.ban_reason != "Under Siege":
|
if current.ban_reason == "Under Siege" and u.ban_reason and u.ban_reason != "Under Siege":
|
||||||
|
|
|
@ -8,6 +8,7 @@ import gevent
|
||||||
import qrcode
|
import qrcode
|
||||||
from sqlalchemy.orm import aliased, load_only
|
from sqlalchemy.orm import aliased, load_only
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
from sqlalchemy import nullslast
|
||||||
|
|
||||||
from files.classes import *
|
from files.classes import *
|
||||||
from files.classes.transactions import *
|
from files.classes.transactions import *
|
||||||
|
@ -334,7 +335,7 @@ def banned(v):
|
||||||
|
|
||||||
users = g.db.query(User).filter(
|
users = g.db.query(User).filter(
|
||||||
User.is_banned != None,
|
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()
|
total = users.count()
|
||||||
|
@ -349,7 +350,7 @@ def banned(v):
|
||||||
key = User.is_banned
|
key = User.is_banned
|
||||||
else:
|
else:
|
||||||
sort = "unban_utc"
|
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)
|
users = users.order_by(key).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table users alter column unban_utc drop not null;
|
||||||
|
update users set unban_utc=null where unban_utc=0;
|
Loading…
Reference in New Issue