Skip to content

Commit

Permalink
feat: add ALLOW_EXPORT_ALL_CHATS to disable admin chat export
Browse files Browse the repository at this point in the history
  • Loading branch information
cheahjs committed Mar 27, 2024
1 parent 043fabb commit 49dcf68
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion backend/apps/web/routers/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@

from constants import ERROR_MESSAGES

from config import SRC_LOG_LEVELS
from config import (
SRC_LOG_LEVELS,
ALLOW_EXPORT_ALL_CHATS
)
log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["MODELS"])

Expand Down Expand Up @@ -66,6 +69,11 @@ async def get_all_user_chats(user=Depends(get_current_user)):

@router.get("/all/db", response_model=List[ChatResponse])
async def get_all_user_chats_in_db(user=Depends(get_admin_user)):
if not ALLOW_EXPORT_ALL_CHATS:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
)
return [
ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
for chat in Chats.get_all_chats()
Expand Down
2 changes: 2 additions & 0 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ def create_config_file(file_path):

WEBHOOK_URL = os.environ.get("WEBHOOK_URL", "")

ALLOW_EXPORT_ALL_CHATS = os.environ.get("ALLOW_EXPORT_ALL_CHATS", "True").lower() == "true"

####################################
# WEBUI_VERSION
####################################
Expand Down
2 changes: 2 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
SRC_LOG_LEVELS,
WEBHOOK_URL,
IS_LOCAL,
ALLOW_EXPORT_ALL_CHATS,
)
from constants import ERROR_MESSAGES

Expand Down Expand Up @@ -174,6 +175,7 @@ async def get_app_config():
"default_prompt_suggestions": webui_app.state.DEFAULT_PROMPT_SUGGESTIONS,
"trusted_header_auth": bool(webui_app.state.AUTH_TRUSTED_EMAIL_HEADER),
"is_local": IS_LOCAL,
"all_chat_export_allowed": ALLOW_EXPORT_ALL_CHATS,
}


Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/chat/Settings/Chats.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fileSaver from 'file-saver';
const { saveAs } = fileSaver;
import { chats, user } from '$lib/stores';
import { chats, user, config } from '$lib/stores';
import {
createNewChat,
Expand Down Expand Up @@ -301,7 +301,7 @@
</button>
{/if}

{#if $user?.role === 'admin'}
{#if $user?.role === 'admin' && ($config?.all_chat_export_allowed ?? true)}
<hr class=" dark:border-gray-700" />

<button
Expand Down

0 comments on commit 49dcf68

Please sign in to comment.