enh: chat file upload permission

This commit is contained in:
Timothy Jaeryang Baek 2024-11-16 02:31:04 -08:00
parent f9412f72f1
commit 646d926f70
4 changed files with 20 additions and 5 deletions

View File

@ -52,7 +52,7 @@ async def get_session_user_chat_list(
async def delete_all_user_chats(request: Request, user=Depends(get_verified_user)):
if user.role == "user" and not request.app.state.config.USER_PERMISSIONS.get(
"chat", {}
).get("deletion", {}):
).get("delete", {}):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
@ -386,7 +386,7 @@ async def delete_chat_by_id(request: Request, id: str, user=Depends(get_verified
return result
else:
if not request.app.state.config.USER_PERMISSIONS.get("chat", {}).get(
"deletion", {}
"delete", {}
):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,

View File

@ -62,6 +62,7 @@ class WorkspacePermissions(BaseModel):
class ChatPermissions(BaseModel):
file_upload: bool
delete: bool
edit: bool
temporary: bool

View File

@ -759,6 +759,10 @@ USER_PERMISSIONS_WORKSPACE_TOOLS_ACCESS = (
os.environ.get("USER_PERMISSIONS_WORKSPACE_TOOLS_ACCESS", "False").lower() == "true"
)
USER_PERMISSIONS_CHAT_FILE_UPLOAD = (
os.environ.get("USER_PERMISSIONS_CHAT_FILE_UPLOAD", "True").lower() == "true"
)
USER_PERMISSIONS_CHAT_DELETE = (
os.environ.get("USER_PERMISSIONS_CHAT_DELETE", "True").lower() == "true"
)
@ -782,8 +786,9 @@ USER_PERMISSIONS = PersistentConfig(
"tools": USER_PERMISSIONS_WORKSPACE_TOOLS_ACCESS,
},
"chat": {
"deletion": USER_PERMISSIONS_CHAT_DELETE,
"editing": USER_PERMISSIONS_CHAT_EDIT,
"file_upload": USER_PERMISSIONS_CHAT_FILE_UPLOAD,
"delete": USER_PERMISSIONS_CHAT_DELETE,
"edit": USER_PERMISSIONS_CHAT_EDIT,
"temporary": USER_PERMISSIONS_CHAT_TEMPORARY,
},
},

View File

@ -15,7 +15,8 @@
chat: {
delete: true,
edit: true,
temporary: true
temporary: true,
file_upload: true
}
};
</script>
@ -168,6 +169,14 @@
<div>
<div class=" mb-2 text-sm font-medium">{$i18n.t('Chat Permissions')}</div>
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Allow File Upload')}
</div>
<Switch bind:state={permissions.chat.file_upload} />
</div>
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Allow Chat Delete')}