feat(privacy): user blocklist with private chat enforcement
Some checks failed
CI / test (push) Failing after 21s
Some checks failed
CI / test (push) Failing after 21s
- add blocked_users table and migration - add users API: block, unblock, list blocked users - prevent private chat creation and private messaging when block relation exists - add block/unblock action in private chat info panel
This commit is contained in:
@@ -22,7 +22,7 @@ from app.messages.repository import (
|
||||
list_chat_message_ids,
|
||||
)
|
||||
from app.realtime.presence import get_users_online_map
|
||||
from app.users.repository import get_user_by_id
|
||||
from app.users.repository import get_user_by_id, has_block_relation_between_users
|
||||
|
||||
|
||||
async def serialize_chat_for_user(db: AsyncSession, *, user_id: int, chat: Chat) -> ChatRead:
|
||||
@@ -103,6 +103,11 @@ async def create_chat_for_user(db: AsyncSession, *, creator_id: int, payload: Ch
|
||||
detail="Private chat requires exactly one target user.",
|
||||
)
|
||||
if payload.type == ChatType.PRIVATE:
|
||||
if await has_block_relation_between_users(db, user_a_id=creator_id, user_b_id=member_ids[0]):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Cannot create private chat due to block settings",
|
||||
)
|
||||
existing_chat = await repository.find_private_chat_between_users(
|
||||
db,
|
||||
user_a_id=creator_id,
|
||||
|
||||
Reference in New Issue
Block a user