refac
This commit is contained in:
1 parent
2dbf7b6764
commit
3a21b334cc
1 file changed
+8
-14
@@ -1412,19 +1412,16 @@ async def update_shared_chat_access_by_id(
|
|||||||
user=Depends(get_verified_user),
|
user=Depends(get_verified_user),
|
||||||
db: AsyncSession = Depends(get_async_session),
|
db: AsyncSession = Depends(get_async_session),
|
||||||
):
|
):
|
||||||
chat = await Chats.get_chat_by_id_and_user_id(id, user.id, db=db)
|
if user.role == 'admin':
|
||||||
|
chat = await Chats.get_chat_by_id(id, db=db)
|
||||||
|
else:
|
||||||
|
chat = await Chats.get_chat_by_id_and_user_id(id, user.id, db=db)
|
||||||
if not chat:
|
if not chat:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
detail=ERROR_MESSAGES.NOT_FOUND,
|
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||||
)
|
)
|
||||||
|
|
||||||
if chat.user_id != user.id and user.role != 'admin':
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
||||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
|
||||||
)
|
|
||||||
|
|
||||||
form_data.access_grants = await filter_allowed_access_grants(
|
form_data.access_grants = await filter_allowed_access_grants(
|
||||||
request.app.state.config.USER_PERMISSIONS,
|
request.app.state.config.USER_PERMISSIONS,
|
||||||
user.id,
|
user.id,
|
||||||
@@ -1449,19 +1446,16 @@ async def get_shared_chat_access_by_id(
|
|||||||
user=Depends(get_verified_user),
|
user=Depends(get_verified_user),
|
||||||
db: AsyncSession = Depends(get_async_session),
|
db: AsyncSession = Depends(get_async_session),
|
||||||
):
|
):
|
||||||
chat = await Chats.get_chat_by_id_and_user_id(id, user.id, db=db)
|
if user.role == 'admin':
|
||||||
|
chat = await Chats.get_chat_by_id(id, db=db)
|
||||||
|
else:
|
||||||
|
chat = await Chats.get_chat_by_id_and_user_id(id, user.id, db=db)
|
||||||
if not chat:
|
if not chat:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
detail=ERROR_MESSAGES.NOT_FOUND,
|
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||||
)
|
)
|
||||||
|
|
||||||
if chat.user_id != user.id and user.role != 'admin':
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
||||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
|
||||||
)
|
|
||||||
|
|
||||||
grants = await AccessGrants.get_grants_by_resource('shared_chat', id, db=db)
|
grants = await AccessGrants.get_grants_by_resource('shared_chat', id, db=db)
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user