diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index d8d7b9032e..e3a90dbcf5 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -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, diff --git a/backend/open_webui/routers/chats.py b/backend/open_webui/routers/chats.py index 0ece8ec410..5017f821e2 100644 --- a/backend/open_webui/routers/chats.py +++ b/backend/open_webui/routers/chats.py @@ -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 diff --git a/backend/open_webui/routers/users.py b/backend/open_webui/routers/users.py index 158d6e8e15..ef1c989773 100644 --- a/backend/open_webui/routers/users.py +++ b/backend/open_webui/routers/users.py @@ -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 diff --git a/src/lib/components/admin/Users/Groups/Permissions.svelte b/src/lib/components/admin/Users/Groups/Permissions.svelte index d0845d398c..bb07931efd 100644 --- a/src/lib/components/admin/Users/Groups/Permissions.svelte +++ b/src/lib/components/admin/Users/Groups/Permissions.svelte @@ -700,6 +700,22 @@ {/if} +