refac: align the channel completion gate with the message update route (#28631)
The gate now applies the same authorship condition the channel message update route already uses, so both paths agree on which messages a caller may modify.
This commit is contained in:
1 parent
1756c9d5d2
commit
7d392bedc9
1 file changed
+7
-3
@@ -1257,8 +1257,8 @@ async def chat_completion(
|
|||||||
if metadata.get('chat_id') and user:
|
if metadata.get('chat_id') and user:
|
||||||
chat_id = metadata['chat_id']
|
chat_id = metadata['chat_id']
|
||||||
|
|
||||||
# Gate channel: branch — caller needs write access on the channel
|
# Gate channel: branch — caller needs write access on the channel, and the
|
||||||
# and the supplied message_id must belong to that channel.
|
# supplied message_id must belong to that channel and be the caller's own.
|
||||||
if chat_id.startswith('channel:'):
|
if chat_id.startswith('channel:'):
|
||||||
channel_id = chat_id.removeprefix('channel:')
|
channel_id = chat_id.removeprefix('channel:')
|
||||||
channel = await Channels.get_channel_by_id(channel_id)
|
channel = await Channels.get_channel_by_id(channel_id)
|
||||||
@@ -1290,7 +1290,11 @@ async def chat_completion(
|
|||||||
if not target_message_id:
|
if not target_message_id:
|
||||||
continue
|
continue
|
||||||
target_message = await Messages.get_message_by_id(target_message_id)
|
target_message = await Messages.get_message_by_id(target_message_id)
|
||||||
if target_message and target_message.channel_id != channel.id:
|
if target_message and (
|
||||||
|
target_message.channel_id != channel.id
|
||||||
|
# Write access is not authorship — block cross-member edits.
|
||||||
|
or (user.role != 'admin' and target_message.user_id != user.id)
|
||||||
|
):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
detail=ERROR_MESSAGES.DEFAULT(),
|
detail=ERROR_MESSAGES.DEFAULT(),
|
||||||
|
|||||||
Reference in new issue
Block a user