refac
This commit is contained in:
1 parent
0726db7217
commit
edf3ae9209
6 files changed
+49
-15
No files matched your search
@@ -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_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_STT = os.getenv('USER_PERMISSIONS_CHAT_STT', 'True').lower() == 'true'
|
||||||
|
|
||||||
USER_PERMISSIONS_CHAT_TTS = os.getenv('USER_PERMISSIONS_CHAT_TTS', '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,
|
'edit': USER_PERMISSIONS_CHAT_EDIT,
|
||||||
'share': USER_PERMISSIONS_CHAT_SHARE,
|
'share': USER_PERMISSIONS_CHAT_SHARE,
|
||||||
'export': USER_PERMISSIONS_CHAT_EXPORT,
|
'export': USER_PERMISSIONS_CHAT_EXPORT,
|
||||||
|
'import': USER_PERMISSIONS_CHAT_IMPORT,
|
||||||
'stt': USER_PERMISSIONS_CHAT_STT,
|
'stt': USER_PERMISSIONS_CHAT_STT,
|
||||||
'tts': USER_PERMISSIONS_CHAT_TTS,
|
'tts': USER_PERMISSIONS_CHAT_TTS,
|
||||||
'call': USER_PERMISSIONS_CHAT_CALL,
|
'call': USER_PERMISSIONS_CHAT_CALL,
|
||||||
|
|||||||
@@ -585,10 +585,19 @@ async def create_new_chat(
|
|||||||
|
|
||||||
@router.post('/import', response_model=list[ChatResponse])
|
@router.post('/import', response_model=list[ChatResponse])
|
||||||
async def import_chats(
|
async def import_chats(
|
||||||
|
request: Request,
|
||||||
form_data: ChatsImportForm,
|
form_data: ChatsImportForm,
|
||||||
user=Depends(get_verified_user),
|
user=Depends(get_verified_user),
|
||||||
db: AsyncSession = Depends(get_async_session),
|
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:
|
try:
|
||||||
chats = await Chats.import_chats(user.id, form_data.chats, db=db)
|
chats = await Chats.import_chats(user.id, form_data.chats, db=db)
|
||||||
return chats
|
return chats
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ from open_webui.utils.auth import (
|
|||||||
get_verified_user,
|
get_verified_user,
|
||||||
validate_password,
|
validate_password,
|
||||||
)
|
)
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@@ -201,6 +201,8 @@ class AccessGrantsPermissions(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class ChatPermissions(BaseModel):
|
class ChatPermissions(BaseModel):
|
||||||
|
model_config = ConfigDict(populate_by_name=True)
|
||||||
|
|
||||||
controls: bool = True
|
controls: bool = True
|
||||||
valves: bool = True
|
valves: bool = True
|
||||||
system_prompt: bool = True
|
system_prompt: bool = True
|
||||||
@@ -215,6 +217,7 @@ class ChatPermissions(BaseModel):
|
|||||||
edit: bool = True
|
edit: bool = True
|
||||||
share: bool = True
|
share: bool = True
|
||||||
export: bool = True
|
export: bool = True
|
||||||
|
import_: bool = Field(default=True, alias='import')
|
||||||
stt: bool = True
|
stt: bool = True
|
||||||
tts: bool = True
|
tts: bool = True
|
||||||
call: 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')
|
@router.post('/default/permissions')
|
||||||
async def update_default_user_permissions(request: Request, form_data: UserPermissions, user=Depends(get_admin_user)):
|
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
|
return request.app.state.config.USER_PERMISSIONS
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -700,6 +700,22 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</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 flex-col w-full">
|
||||||
<div class="flex w-full justify-between my-1">
|
<div class="flex w-full justify-between my-1">
|
||||||
<div class=" self-center text-xs font-medium">
|
<div class=" self-center text-xs font-medium">
|
||||||
|
|||||||
@@ -187,20 +187,22 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="mb-1 text-sm font-medium">{$i18n.t('Chats')}</div>
|
<div class="mb-1 text-sm font-medium">{$i18n.t('Chats')}</div>
|
||||||
|
|
||||||
<div>
|
{#if $user?.role === 'admin' || ($user.permissions?.chat?.import ?? true)}
|
||||||
<div class="py-0.5 flex w-full justify-between">
|
<div>
|
||||||
<div class="self-center text-xs">{$i18n.t('Import Chats')}</div>
|
<div class="py-0.5 flex w-full justify-between">
|
||||||
<button
|
<div class="self-center text-xs">{$i18n.t('Import Chats')}</div>
|
||||||
class="p-1 px-3 text-xs flex rounded-sm transition"
|
<button
|
||||||
on:click={() => {
|
class="p-1 px-3 text-xs flex rounded-sm transition"
|
||||||
chatImportInputElement.click();
|
on:click={() => {
|
||||||
}}
|
chatImportInputElement.click();
|
||||||
type="button"
|
}}
|
||||||
>
|
type="button"
|
||||||
<span class="self-center">{$i18n.t('Import')}</span>
|
>
|
||||||
</button>
|
<span class="self-center">{$i18n.t('Import')}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/if}
|
||||||
|
|
||||||
{#if $user?.role === 'admin' || ($user.permissions?.chat?.export ?? true)}
|
{#if $user?.role === 'admin' || ($user.permissions?.chat?.export ?? true)}
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export const DEFAULT_PERMISSIONS = {
|
|||||||
edit: true,
|
edit: true,
|
||||||
share: true,
|
share: true,
|
||||||
export: true,
|
export: true,
|
||||||
|
import: true,
|
||||||
stt: true,
|
stt: true,
|
||||||
tts: true,
|
tts: true,
|
||||||
call: true,
|
call: true,
|
||||||
|
|||||||
Reference in new issue
Block a user