feat(moderation): add chat bans list endpoint with admin access checks
Some checks are pending
CI / test (push) Has started running

This commit is contained in:
2026-03-08 21:21:43 +03:00
parent 5909503012
commit 90320ffd5d
7 changed files with 114 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.chats import repository
from app.chats.models import Chat, ChatMember, ChatMemberRole, ChatType
from app.chats.schemas import (
ChatBanRead,
ChatCreateRequest,
ChatDeleteRequest,
ChatDiscoverRead,
@@ -471,6 +472,28 @@ async def unban_chat_member_for_user(
await db.commit()
async def list_chat_bans_for_user(
db: AsyncSession,
*,
chat_id: int,
actor_user_id: int,
) -> list[ChatBanRead]:
chat, actor_membership = await _get_chat_and_membership(db, chat_id=chat_id, user_id=actor_user_id)
_ensure_group_or_channel(chat.type)
if actor_membership.role not in {ChatMemberRole.OWNER, ChatMemberRole.ADMIN}:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Insufficient permissions")
bans = await repository.list_chat_bans(db, chat_id=chat_id)
return [
ChatBanRead(
chat_id=ban.chat_id,
user_id=ban.user_id,
banned_by_user_id=ban.banned_by_user_id,
created_at=ban.created_at,
)
for ban in bans
]
async def leave_chat_for_user(db: AsyncSession, *, chat_id: int, user_id: int) -> None:
chat, membership = await _get_chat_and_membership(db, chat_id=chat_id, user_id=user_id)
_ensure_group_or_channel(chat.type)