refac
This commit is contained in:
1 parent
86df8bf27e
commit
cde21b9f6d
1 file changed
+10
-7
@@ -829,15 +829,17 @@ async def get_shared_chat_by_id(
|
|||||||
if user.role == 'pending':
|
if user.role == 'pending':
|
||||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.NOT_FOUND)
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.NOT_FOUND)
|
||||||
|
|
||||||
if user.role == 'admin' and ENABLE_ADMIN_CHAT_ACCESS:
|
|
||||||
chat = await Chats.get_chat_by_id(share_id, db=db)
|
|
||||||
else:
|
|
||||||
chat = await Chats.get_chat_by_share_id(share_id, db=db)
|
chat = await Chats.get_chat_by_share_id(share_id, db=db)
|
||||||
|
|
||||||
|
# Fallback: admins can also access any chat directly by chat ID
|
||||||
|
if not chat and user.role == 'admin' and ENABLE_ADMIN_CHAT_ACCESS:
|
||||||
|
chat = await Chats.get_chat_by_id(share_id, db=db)
|
||||||
|
|
||||||
if not chat:
|
if not chat:
|
||||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.NOT_FOUND)
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.NOT_FOUND)
|
||||||
|
|
||||||
# Look up the original chat_id to check access grants
|
# Look up the original chat_id to check access grants (admins bypass)
|
||||||
|
if user.role != 'admin' or not ENABLE_ADMIN_CHAT_ACCESS:
|
||||||
shared = await SharedChats.get_by_id(share_id, db=db)
|
shared = await SharedChats.get_by_id(share_id, db=db)
|
||||||
if shared:
|
if shared:
|
||||||
has_grant = await AccessGrants.has_access(
|
has_grant = await AccessGrants.has_access(
|
||||||
@@ -1183,11 +1185,12 @@ async def clone_chat_by_id(
|
|||||||
async def clone_shared_chat_by_id(
|
async def clone_shared_chat_by_id(
|
||||||
id: str, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)
|
id: str, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)
|
||||||
):
|
):
|
||||||
if user.role == 'admin':
|
|
||||||
chat = await Chats.get_chat_by_id(id, db=db)
|
|
||||||
else:
|
|
||||||
chat = await Chats.get_chat_by_share_id(id, db=db)
|
chat = await Chats.get_chat_by_share_id(id, db=db)
|
||||||
|
|
||||||
|
# Fallback: admins can also access any chat directly by chat ID
|
||||||
|
if not chat and user.role == 'admin' and ENABLE_ADMIN_CHAT_ACCESS:
|
||||||
|
chat = await Chats.get_chat_by_id(id, db=db)
|
||||||
|
|
||||||
if not chat:
|
if not chat:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
|||||||
Reference in new issue
Block a user