remove .deleted column for alts

pull/124/head
Aevann 2023-02-18 17:19:14 +02:00
parent ef2bda6920
commit 57e9cb3428
4 changed files with 6 additions and 17 deletions

View File

@ -12,7 +12,6 @@ class Alt(Base):
user2 = Column(Integer, ForeignKey("users.id"), primary_key=True)
is_manual = Column(Boolean, default=False)
created_utc = Column(Integer)
deleted = Column(Boolean, default=False)
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())

View File

@ -610,15 +610,13 @@ def admin_add_alt(v:User, username):
user2 = get_user(request.values.get('other_username'))
if user1.id == user2.id: abort(400, "Can't add the same account as alts of each other")
deleted = request.values.get('deleted', False, bool) or False
ids = [user1.id, user2.id]
a = g.db.query(Alt).filter(Alt.user1.in_(ids), Alt.user2.in_(ids)).one_or_none()
if a: abort(409, f"@{user1.username} and @{user2.username} are already known {'linked' if not a.deleted else 'delinked'} alts")
if a: abort(409, f"@{user1.username} and @{user2.username} are already known alts!")
a = Alt(
user1=user1.id,
user2=user2.id,
is_manual=True,
deleted=deleted
)
g.db.add(a)
g.db.flush()
@ -629,17 +627,14 @@ def admin_add_alt(v:User, username):
check_for_alts(user1)
check_for_alts(user2)
word = 'Delinked' if deleted else 'Linked'
ma_word = 'delink' if deleted else 'link'
note = f'from @{user2.username}' if deleted else f'with @{user2.username}'
ma = ModAction(
kind=f"{ma_word}_accounts",
kind=f"link_accounts",
user_id=v.id,
target_user_id=user1.id,
_note=note
_note=f'with @{user2.username}'
)
g.db.add(ma)
return {"message": f"{word} @{user1.username} and @{user2.username} successfully!"}
return {"message": f"Linked @{user1.username} and @{user2.username} successfully!"}
@app.post('/@<username>/alts/<int:other>/deleted')
@limiter.limit(DEFAULT_RATELIMIT_SLOWER)

View File

@ -72,13 +72,6 @@ def check_for_alts(current:User, include_current_session=False):
add_alt(past_id, current_id)
other_alts = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).all()
for a in other_alts:
if a.deleted:
if include_current_session:
try: session["history"].remove(a.user1)
except: pass
try: session["history"].remove(a.user2)
except: pass
continue # don't propagate deleted alt links
if a.user1 != past_id: add_alt(a.user1, past_id)
if a.user1 != current_id: add_alt(a.user1, current_id)
if a.user2 != past_id: add_alt(a.user2, past_id)

View File

@ -0,0 +1,2 @@
delete from alts where deleted=true;
alter table alts drop column deleted;