refac
This commit is contained in:
@@ -2768,6 +2768,8 @@ USER_PERMISSIONS_CHAT_ALLOW_PUBLIC_SHARING = (
|
||||
|
||||
USER_PERMISSIONS_CHAT_EXPORT = os.getenv('USER_PERMISSIONS_CHAT_EXPORT', 'True').lower() == 'true'
|
||||
|
||||
USER_PERMISSIONS_CHAT_IMPORT = os.getenv('USER_PERMISSIONS_CHAT_IMPORT', 'True').lower() == 'true'
|
||||
|
||||
USER_PERMISSIONS_CHAT_STT = os.getenv('USER_PERMISSIONS_CHAT_STT', 'True').lower() == 'true'
|
||||
|
||||
USER_PERMISSIONS_CHAT_TTS = os.getenv('USER_PERMISSIONS_CHAT_TTS', 'True').lower() == 'true'
|
||||
@@ -2864,6 +2866,7 @@ DEFAULT_USER_PERMISSIONS = {
|
||||
'edit': USER_PERMISSIONS_CHAT_EDIT,
|
||||
'share': USER_PERMISSIONS_CHAT_SHARE,
|
||||
'export': USER_PERMISSIONS_CHAT_EXPORT,
|
||||
'import': USER_PERMISSIONS_CHAT_IMPORT,
|
||||
'stt': USER_PERMISSIONS_CHAT_STT,
|
||||
'tts': USER_PERMISSIONS_CHAT_TTS,
|
||||
'call': USER_PERMISSIONS_CHAT_CALL,
|
||||
|
||||
@@ -585,10 +585,19 @@ async def create_new_chat(
|
||||
|
||||
@router.post('/import', response_model=list[ChatResponse])
|
||||
async def import_chats(
|
||||
request: Request,
|
||||
form_data: ChatsImportForm,
|
||||
user=Depends(get_verified_user),
|
||||
db: AsyncSession = Depends(get_async_session),
|
||||
):
|
||||
if user.role != 'admin' and not await has_permission(
|
||||
user.id, 'chat.import', request.app.state.config.USER_PERMISSIONS, db=db
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||
)
|
||||
|
||||
try:
|
||||
chats = await Chats.import_chats(user.id, form_data.chats, db=db)
|
||||
return chats
|
||||
|
||||
@@ -38,7 +38,7 @@ from open_webui.utils.auth import (
|
||||
get_verified_user,
|
||||
validate_password,
|
||||
)
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -201,6 +201,8 @@ class AccessGrantsPermissions(BaseModel):
|
||||
|
||||
|
||||
class ChatPermissions(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
controls: bool = True
|
||||
valves: bool = True
|
||||
system_prompt: bool = True
|
||||
@@ -215,6 +217,7 @@ class ChatPermissions(BaseModel):
|
||||
edit: bool = True
|
||||
share: bool = True
|
||||
export: bool = True
|
||||
import_: bool = Field(default=True, alias='import')
|
||||
stt: bool = True
|
||||
tts: bool = True
|
||||
call: bool = True
|
||||
@@ -265,7 +268,7 @@ async def get_default_user_permissions(request: Request, user=Depends(get_admin_
|
||||
|
||||
@router.post('/default/permissions')
|
||||
async def update_default_user_permissions(request: Request, form_data: UserPermissions, user=Depends(get_admin_user)):
|
||||
request.app.state.config.USER_PERMISSIONS = form_data.model_dump()
|
||||
request.app.state.config.USER_PERMISSIONS = form_data.model_dump(by_alias=True)
|
||||
return request.app.state.config.USER_PERMISSIONS
|
||||
|
||||
|
||||
|
||||
@@ -700,6 +700,22 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Allow Chat Import')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.chat['import']} />
|
||||
</div>
|
||||
{#if defaultPermissions?.chat?.import && !permissions.chat['import']}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
|
||||
@@ -187,20 +187,22 @@
|
||||
<div>
|
||||
<div class="mb-1 text-sm font-medium">{$i18n.t('Chats')}</div>
|
||||
|
||||
<div>
|
||||
<div class="py-0.5 flex w-full justify-between">
|
||||
<div class="self-center text-xs">{$i18n.t('Import Chats')}</div>
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded-sm transition"
|
||||
on:click={() => {
|
||||
chatImportInputElement.click();
|
||||
}}
|
||||
type="button"
|
||||
>
|
||||
<span class="self-center">{$i18n.t('Import')}</span>
|
||||
</button>
|
||||
{#if $user?.role === 'admin' || ($user.permissions?.chat?.import ?? true)}
|
||||
<div>
|
||||
<div class="py-0.5 flex w-full justify-between">
|
||||
<div class="self-center text-xs">{$i18n.t('Import Chats')}</div>
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded-sm transition"
|
||||
on:click={() => {
|
||||
chatImportInputElement.click();
|
||||
}}
|
||||
type="button"
|
||||
>
|
||||
<span class="self-center">{$i18n.t('Import')}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if $user?.role === 'admin' || ($user.permissions?.chat?.export ?? true)}
|
||||
<div>
|
||||
|
||||
@@ -47,6 +47,7 @@ export const DEFAULT_PERMISSIONS = {
|
||||
edit: true,
|
||||
share: true,
|
||||
export: true,
|
||||
import: true,
|
||||
stt: true,
|
||||
tts: true,
|
||||
call: true,
|
||||
|
||||
Reference in New Issue
Block a user