MCPcopy
hub / github.com/learnhouse/learnhouse / is_user_superadmin

Function is_user_superadmin

apps/api/src/security/superadmin.py:11–22  ·  view source on GitHub ↗

Check if a user is a superadmin by querying the database directly.

(user_id: int, db_session: AsyncSession)

Source from the content-addressed store, hash-verified

9
10
11async def is_user_superadmin(user_id: int, db_session: AsyncSession) -> bool:
12 """Check if a user is a superadmin by querying the database directly."""
13 _cache = getattr(db_session, '_superadmin_cache', None)
14 if _cache is None:
15 db_session._superadmin_cache = {}
16 _cache = db_session._superadmin_cache
17 if user_id in _cache:
18 return _cache[user_id]
19 result = (await db_session.execute(select(User.is_superadmin).where(User.id == user_id))).scalars().first()
20 value = bool(result)
21 _cache[user_id] = value
22 return value
23
24
25async def _get_current_user_lazy(request: Request, db_session: AsyncSession = Depends(get_db_session)):

Calls 3

firstMethod · 0.45
scalarsMethod · 0.45
executeMethod · 0.45