fix(channel): enforce read-only for members and polish chat info
Some checks failed
CI / test (push) Failing after 26s
Some checks failed
CI / test (push) Failing after 26s
- block send/forward in channels for member role on backend - expose my_role in chat payload for client-side permissions - hide message composer for channel members and show read-only notice - hide members management sections for private/saved chats in info panel - return enriched chat detail via serialize_chat_for_user
This commit is contained in:
@@ -96,13 +96,12 @@ async def get_chat(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> ChatDetailRead:
|
||||
chat, members = await get_chat_for_user(db, chat_id=chat_id, user_id=current_user.id)
|
||||
return ChatDetailRead(
|
||||
id=chat.id,
|
||||
type=chat.type,
|
||||
title=chat.title,
|
||||
pinned_message_id=chat.pinned_message_id,
|
||||
created_at=chat.created_at,
|
||||
members=members,
|
||||
base = await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)
|
||||
return ChatDetailRead.model_validate(
|
||||
{
|
||||
**base.model_dump(),
|
||||
"members": members,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ class ChatRead(BaseModel):
|
||||
counterpart_username: str | None = None
|
||||
counterpart_is_online: bool | None = None
|
||||
counterpart_last_seen_at: datetime | None = None
|
||||
my_role: ChatMemberRole | None = None
|
||||
created_at: datetime
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ from app.users.repository import get_user_by_id
|
||||
|
||||
async def serialize_chat_for_user(db: AsyncSession, *, user_id: int, chat: Chat) -> ChatRead:
|
||||
display_title = chat.title
|
||||
my_role = None
|
||||
membership = await repository.get_chat_member(db, chat_id=chat.id, user_id=user_id)
|
||||
if membership:
|
||||
my_role = membership.role
|
||||
members_count: int | None = None
|
||||
online_count: int | None = None
|
||||
subscribers_count: int | None = None
|
||||
@@ -70,6 +74,7 @@ async def serialize_chat_for_user(db: AsyncSession, *, user_id: int, chat: Chat)
|
||||
"counterpart_username": counterpart_username,
|
||||
"counterpart_is_online": counterpart_is_online,
|
||||
"counterpart_last_seen_at": counterpart_last_seen_at,
|
||||
"my_role": my_role,
|
||||
"created_at": chat.created_at,
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user