Auth sync is_admin on TG login

This commit is contained in:
Vladless
2026-04-14 18:58:02 +00:00
parent 083e3a59dd
commit 1e1275f3c7
2 changed files with 6 additions and 1 deletions
+6 -1
View File
@@ -688,10 +688,15 @@ async def detach_telegram(session: AsyncSession, identity_id: str) -> Identity |
async def get_or_create_identity_for_tg(session: AsyncSession, tg_id: int) -> Identity:
"""Для tg_id возвращает существующую идентичность или создаёт новую и привязывает User."""
is_admin = (await session.execute(select(Admin).where(Admin.tg_id == tg_id))).scalar_one_or_none() is not None
identity = await get_identity_by_tg_id(session, tg_id)
if identity:
if is_admin and not identity.is_admin:
identity.is_admin = True
await session.flush()
await session.refresh(identity)
return identity
identity = Identity(tg_id=tg_id)
identity = Identity(tg_id=tg_id, is_admin=is_admin)
session.add(identity)
await session.flush()
await session.execute(User.__table__.update().where(User.tg_id == tg_id).values(identity_id=identity.id))
Regular → Executable
View File