Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
190b934a
Commit
190b934a
authored
Apr 17, 2024
by
Jun Siang Cheah
Browse files
feat: add ALLOW_ADMIN_EXPORT to disable exporting of chats and the db
parent
1e76dbc9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
25 deletions
+44
-25
backend/apps/web/routers/chats.py
backend/apps/web/routers/chats.py
+9
-1
backend/apps/web/routers/utils.py
backend/apps/web/routers/utils.py
+5
-1
backend/config.py
backend/config.py
+2
-0
backend/main.py
backend/main.py
+2
-0
src/lib/components/admin/Settings/Database.svelte
src/lib/components/admin/Settings/Database.svelte
+25
-22
src/lib/components/chat/Settings/Chats.svelte
src/lib/components/chat/Settings/Chats.svelte
+1
-1
No files found.
backend/apps/web/routers/chats.py
View file @
190b934a
...
@@ -28,7 +28,10 @@ from apps.web.models.tags import (
...
@@ -28,7 +28,10 @@ from apps.web.models.tags import (
from
constants
import
ERROR_MESSAGES
from
constants
import
ERROR_MESSAGES
from
config
import
SRC_LOG_LEVELS
from
config
import
(
SRC_LOG_LEVELS
,
ALLOW_ADMIN_EXPORT
)
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
log
.
setLevel
(
SRC_LOG_LEVELS
[
"MODELS"
])
log
.
setLevel
(
SRC_LOG_LEVELS
[
"MODELS"
])
...
@@ -79,6 +82,11 @@ async def get_all_user_chats(user=Depends(get_current_user)):
...
@@ -79,6 +82,11 @@ async def get_all_user_chats(user=Depends(get_current_user)):
@
router
.
get
(
"/all/db"
,
response_model
=
List
[
ChatResponse
])
@
router
.
get
(
"/all/db"
,
response_model
=
List
[
ChatResponse
])
async
def
get_all_user_chats_in_db
(
user
=
Depends
(
get_admin_user
)):
async
def
get_all_user_chats_in_db
(
user
=
Depends
(
get_admin_user
)):
if
not
ALLOW_ADMIN_EXPORT
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
,
)
return
[
return
[
ChatResponse
(
**
{
**
chat
.
model_dump
(),
"chat"
:
json
.
loads
(
chat
.
chat
)})
ChatResponse
(
**
{
**
chat
.
model_dump
(),
"chat"
:
json
.
loads
(
chat
.
chat
)})
for
chat
in
Chats
.
get_all_chats
()
for
chat
in
Chats
.
get_all_chats
()
...
...
backend/apps/web/routers/utils.py
View file @
190b934a
...
@@ -91,7 +91,11 @@ async def download_chat_as_pdf(
...
@@ -91,7 +91,11 @@ async def download_chat_as_pdf(
@
router
.
get
(
"/db/download"
)
@
router
.
get
(
"/db/download"
)
async
def
download_db
(
user
=
Depends
(
get_admin_user
)):
async
def
download_db
(
user
=
Depends
(
get_admin_user
)):
if
not
ALLOW_ADMIN_EXPORT
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
,
)
return
FileResponse
(
return
FileResponse
(
f
"
{
DATA_DIR
}
/webui.db"
,
f
"
{
DATA_DIR
}
/webui.db"
,
media_type
=
"application/octet-stream"
,
media_type
=
"application/octet-stream"
,
...
...
backend/config.py
View file @
190b934a
...
@@ -382,6 +382,8 @@ MODEL_FILTER_LIST = [model.strip() for model in MODEL_FILTER_LIST.split(";")]
...
@@ -382,6 +382,8 @@ MODEL_FILTER_LIST = [model.strip() for model in MODEL_FILTER_LIST.split(";")]
WEBHOOK_URL
=
os
.
environ
.
get
(
"WEBHOOK_URL"
,
""
)
WEBHOOK_URL
=
os
.
environ
.
get
(
"WEBHOOK_URL"
,
""
)
ALLOW_ADMIN_EXPORT
=
os
.
environ
.
get
(
"ALLOW_ADMIN_EXPORT"
,
"True"
).
lower
()
==
"true"
####################################
####################################
# WEBUI_VERSION
# WEBUI_VERSION
####################################
####################################
...
...
backend/main.py
View file @
190b934a
...
@@ -52,6 +52,7 @@ from config import (
...
@@ -52,6 +52,7 @@ from config import (
GLOBAL_LOG_LEVEL
,
GLOBAL_LOG_LEVEL
,
SRC_LOG_LEVELS
,
SRC_LOG_LEVELS
,
WEBHOOK_URL
,
WEBHOOK_URL
,
ALLOW_ADMIN_EXPORT
,
)
)
from
constants
import
ERROR_MESSAGES
from
constants
import
ERROR_MESSAGES
...
@@ -207,6 +208,7 @@ async def get_app_config():
...
@@ -207,6 +208,7 @@ async def get_app_config():
"default_models"
:
webui_app
.
state
.
DEFAULT_MODELS
,
"default_models"
:
webui_app
.
state
.
DEFAULT_MODELS
,
"default_prompt_suggestions"
:
webui_app
.
state
.
DEFAULT_PROMPT_SUGGESTIONS
,
"default_prompt_suggestions"
:
webui_app
.
state
.
DEFAULT_PROMPT_SUGGESTIONS
,
"trusted_header_auth"
:
bool
(
webui_app
.
state
.
AUTH_TRUSTED_EMAIL_HEADER
),
"trusted_header_auth"
:
bool
(
webui_app
.
state
.
AUTH_TRUSTED_EMAIL_HEADER
),
"allow_admin_export"
:
ALLOW_ADMIN_EXPORT
,
}
}
...
...
src/lib/components/admin/Settings/Database.svelte
View file @
190b934a
<script lang="ts">
<script lang="ts">
import { downloadDatabase } from '$lib/apis/utils';
import { downloadDatabase } from '$lib/apis/utils';
import { onMount, getContext } from 'svelte';
import { onMount, getContext } from 'svelte';
import { config } from '$lib/stores';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
...
@@ -24,32 +25,34 @@
...
@@ -24,32 +25,34 @@
<div class=" flex w-full justify-between">
<div class=" flex w-full justify-between">
<!-- <div class=" self-center text-xs font-medium">{$i18n.t('Allow Chat Deletion')}</div> -->
<!-- <div class=" self-center text-xs font-medium">{$i18n.t('Allow Chat Deletion')}</div> -->
<button
{#if $config?.allow_admin_export ?? true}
class=" flex rounded-md py-1.5 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
<button
type="button"
class=" flex rounded-md py-1.5 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
on:click={() => {
type="button"
on:click={() => {
// exportAllUserChats();
// exportAllUserChats();
downloadDatabase(localStorage.token);
downloadDatabase(localStorage.token);
}}
}}
>
>
<div class=" self-center mr-3">
<div class=" self-center mr-3">
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
viewBox="0 0 16 16"
fill="currentColor"
fill="currentColor"
class="w-4 h-4"
class="w-4 h-4"
>
>
<path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z" />
<path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z" />
<path
<path
fill-rule="evenodd"
fill-rule="evenodd"
d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM8.75 7.75a.75.75 0 0 0-1.5 0v2.69L6.03 9.22a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l2.5-2.5a.75.75 0 1 0-1.06-1.06l-1.22 1.22V7.75Z"
d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM8.75 7.75a.75.75 0 0 0-1.5 0v2.69L6.03 9.22a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l2.5-2.5a.75.75 0 1 0-1.06-1.06l-1.22 1.22V7.75Z"
clip-rule="evenodd"
clip-rule="evenodd"
/>
/>
</svg>
</svg>
</div>
</div>
<div class=" self-center text-sm font-medium">{$i18n.t('Download Database')}</div>
<div class=" self-center text-sm font-medium">{$i18n.t('Download Database')}</div>
</button>
</button>
{/if}
</div>
</div>
</div>
</div>
</div>
</div>
...
...
src/lib/components/chat/Settings/Chats.svelte
View file @
190b934a
...
@@ -301,7 +301,7 @@
...
@@ -301,7 +301,7 @@
</button>
</button>
{/if}
{/if}
{#if $user?.role === 'admin'}
{#if $user?.role === 'admin'
&& ($config?.allow_admin_export ?? true)
}
<hr class=" dark:border-gray-700" />
<hr class=" dark:border-gray-700" />
<button
<button
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment