make is_banned fkey on user id

pull/65/head
Aevann1 2022-12-14 00:02:53 +02:00
parent 8075c5e81f
commit c10c00473a
8 changed files with 14 additions and 11 deletions

View File

@ -107,7 +107,7 @@ class User(Base):
friends_html = deferred(Column(String))
enemies = deferred(Column(String))
enemies_html = deferred(Column(String))
is_banned = Column(Integer, default=0)
is_banned = Column(Integer, ForeignKey("users.id"))
unban_utc = Column(Integer, default=0)
ban_reason = deferred(Column(String))
is_muted = Column(Boolean, default=False, nullable=False)

View File

@ -18,7 +18,7 @@ def award_timers(v, bot=False):
v.patron_utc = 0
notify_if_not_bot(f"Your {patron} status has expired!")
if v.unban_utc and v.unban_utc < now:
v.is_banned = 0
v.is_banned = None
v.unban_utc = 0
v.ban_reason = None
notify_if_not_bot("You have been unbanned!")

View File

@ -104,7 +104,7 @@ def stats(site=None):
"marseys": "{:,}".format(g.db.query(Marsey).filter(Marsey.submitter_id==None).count()),
"users": "{:,}".format(g.db.query(User).count()),
"private users": "{:,}".format(g.db.query(User).filter_by(is_private=True).count()),
"banned users": "{:,}".format(g.db.query(User).filter(User.is_banned > 0).count()),
"banned users": "{:,}".format(g.db.query(User).filter(User.is_banned != None).count()),
"verified email users": "{:,}".format(g.db.query(User).filter_by(is_activated=True).count()),
"coins in circulation": "{:,}".format(g.db.query(func.sum(User.coins)).scalar()),
"total shop sales": "{:,}".format(g.db.query(func.sum(User.coins_spent)).scalar()),

View File

@ -319,7 +319,7 @@ def revert_actions(v:User, username):
user.unban_utc = 0
user.ban_reason = None
if user.is_banned:
user.is_banned = 0
user.is_banned = None
send_repeatable_notification(user.id, f"@{v.username} (a site admin) has unbanned you!")
g.db.add(user)
@ -328,7 +328,7 @@ def revert_actions(v:User, username):
u.unban_utc = 0
u.ban_reason = None
if u.is_banned:
u.is_banned = 0
u.is_banned = None
send_repeatable_notification(u.id, f"@{v.username} (a site admin) has unbanned you!")
g.db.add(u)
@ -1135,7 +1135,7 @@ def unban_user(user_id, v):
if FEATURES['AWARDS'] and user.ban_reason and user.ban_reason.startswith('1-Day ban award'):
abort(403, "You can't undo a ban award!")
user.is_banned = 0
user.is_banned = None
user.unban_utc = 0
user.ban_reason = None
send_repeatable_notification(user.id, f"@{v.username} (a site admin) has unbanned you!")
@ -1143,7 +1143,7 @@ def unban_user(user_id, v):
for x in user.alts:
if x.is_banned: send_repeatable_notification(x.id, f"@{v.username} (a site admin) has unbanned you!")
x.is_banned = 0
x.is_banned = None
x.unban_utc = 0
x.ban_reason = None
g.db.add(x)

View File

@ -228,7 +228,7 @@ def award_thing(v, thing_type, id):
send_repeatable_notification(author.id, "Your ban duration has been reduced by 1 day!")
else:
author.unban_utc = 0
author.is_banned = 0
author.is_banned = None
author.ban_reason = None
send_repeatable_notification(author.id, "You have been unbanned!")
elif kind == "grass":

View File

@ -172,7 +172,7 @@ def user_voted_comments(v:User, username):
@auth_required
def banned(v:User):
users = g.db.query(User).filter(
User.is_banned > 0,
User.is_banned != None,
User.truescore > 0,
or_(User.unban_utc == 0, User.unban_utc > time.time()),
not_(and_(

View File

@ -0,0 +1,4 @@
alter table users alter column is_banned drop default;
alter table users alter column is_banned drop not null;
update users set is_banned=null where is_banned=0;
create index fki_user_is_banned_fkey on public.users using btree (is_banned);

View File

@ -944,7 +944,7 @@ CREATE TABLE public.users (
bio character varying(1500),
bio_html character varying(10000),
referred_by integer,
is_banned integer DEFAULT 0 NOT NULL,
is_banned integer,
ban_reason character varying(256),
login_nonce integer DEFAULT 0 NOT NULL,
reserved character varying(256),
@ -2752,4 +2752,3 @@ ALTER TABLE ONLY public.comments
--
-- PostgreSQL database dump complete
--