From bdc60e7850e041460944e6065df2ea6695a80d15 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 19 Jan 2025 11:59:07 -0800 Subject: [PATCH] chore: format backend --- backend/open_webui/config.py | 16 ++++++++++------ .../open_webui/retrieval/vector/dbs/milvus.py | 3 ++- backend/open_webui/routers/knowledge.py | 6 +++++- backend/open_webui/routers/prompts.py | 8 ++++++-- backend/open_webui/routers/tools.py | 6 +++++- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 02c06487a..a6ec2e0d3 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -492,17 +492,17 @@ OAUTH_ALLOWED_DOMAINS = PersistentConfig( def load_oauth_providers(): OAUTH_PROVIDERS.clear() if GOOGLE_CLIENT_ID.value and GOOGLE_CLIENT_SECRET.value: + def google_oauth_register(client): client.register( name="google", client_id=GOOGLE_CLIENT_ID.value, client_secret=GOOGLE_CLIENT_SECRET.value, server_metadata_url="https://accounts.google.com/.well-known/openid-configuration", - client_kwargs={ - "scope": GOOGLE_OAUTH_SCOPE.value - }, + client_kwargs={"scope": GOOGLE_OAUTH_SCOPE.value}, redirect_uri=GOOGLE_REDIRECT_URI.value, ) + OAUTH_PROVIDERS["google"] = { "redirect_uri": GOOGLE_REDIRECT_URI.value, "register": google_oauth_register, @@ -513,6 +513,7 @@ def load_oauth_providers(): and MICROSOFT_CLIENT_SECRET.value and MICROSOFT_CLIENT_TENANT_ID.value ): + def microsoft_oauth_register(client): client.register( name="microsoft", @@ -524,6 +525,7 @@ def load_oauth_providers(): }, redirect_uri=MICROSOFT_REDIRECT_URI.value, ) + OAUTH_PROVIDERS["microsoft"] = { "redirect_uri": MICROSOFT_REDIRECT_URI.value, "picture_url": "https://graph.microsoft.com/v1.0/me/photo/$value", @@ -531,6 +533,7 @@ def load_oauth_providers(): } if GITHUB_CLIENT_ID.value and GITHUB_CLIENT_SECRET.value: + def github_oauth_register(client): client.register( name="github", @@ -540,11 +543,10 @@ def load_oauth_providers(): authorize_url="https://github.com/login/oauth/authorize", api_base_url="https://api.github.com", userinfo_endpoint="https://api.github.com/user", - client_kwargs={ - "scope": GITHUB_CLIENT_SCOPE.value - }, + client_kwargs={"scope": GITHUB_CLIENT_SCOPE.value}, redirect_uri=GITHUB_CLIENT_REDIRECT_URI.value, ) + OAUTH_PROVIDERS["github"] = { "redirect_uri": GITHUB_CLIENT_REDIRECT_URI.value, "register": github_oauth_register, @@ -556,6 +558,7 @@ def load_oauth_providers(): and OAUTH_CLIENT_SECRET.value and OPENID_PROVIDER_URL.value ): + def oidc_oauth_register(client): client.register( name="oidc", @@ -567,6 +570,7 @@ def load_oauth_providers(): }, redirect_uri=OPENID_REDIRECT_URI.value, ) + OAUTH_PROVIDERS["oidc"] = { "name": OAUTH_PROVIDER_NAME.value, "redirect_uri": OPENID_REDIRECT_URI.value, diff --git a/backend/open_webui/retrieval/vector/dbs/milvus.py b/backend/open_webui/retrieval/vector/dbs/milvus.py index 22bb87f3a..bdfa16eb6 100644 --- a/backend/open_webui/retrieval/vector/dbs/milvus.py +++ b/backend/open_webui/retrieval/vector/dbs/milvus.py @@ -6,7 +6,8 @@ from typing import Optional from open_webui.retrieval.vector.main import VectorItem, SearchResult, GetResult from open_webui.config import ( - MILVUS_URI, MILVUS_DB, + MILVUS_URI, + MILVUS_DB, ) diff --git a/backend/open_webui/routers/knowledge.py b/backend/open_webui/routers/knowledge.py index e918e78ce..cce3d6311 100644 --- a/backend/open_webui/routers/knowledge.py +++ b/backend/open_webui/routers/knowledge.py @@ -214,7 +214,11 @@ async def update_knowledge_by_id( detail=ERROR_MESSAGES.NOT_FOUND, ) # Is the user the original creator, in a group with write access, or an admin - if knowledge.user_id != user.id and not has_access(user.id, "write", knowledge.access_control) and user.role != "admin": + if ( + knowledge.user_id != user.id + and not has_access(user.id, "write", knowledge.access_control) + and user.role != "admin" + ): raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail=ERROR_MESSAGES.ACCESS_PROHIBITED, diff --git a/backend/open_webui/routers/prompts.py b/backend/open_webui/routers/prompts.py index 37747bfbe..014e5652e 100644 --- a/backend/open_webui/routers/prompts.py +++ b/backend/open_webui/routers/prompts.py @@ -111,9 +111,13 @@ async def update_prompt_by_command( status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.NOT_FOUND, ) - + # Is the user the original creator, in a group with write access, or an admin - if prompt.user_id != user.id and not has_access(user.id, "write", prompt.access_control) and user.role != "admin": + if ( + prompt.user_id != user.id + and not has_access(user.id, "write", prompt.access_control) + and user.role != "admin" + ): raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.ACCESS_PROHIBITED, diff --git a/backend/open_webui/routers/tools.py b/backend/open_webui/routers/tools.py index 36100e289..87729f37e 100644 --- a/backend/open_webui/routers/tools.py +++ b/backend/open_webui/routers/tools.py @@ -166,7 +166,11 @@ async def update_tools_by_id( ) # Is the user the original creator, in a group with write access, or an admin - if tools.user_id != user.id and not has_access(user.id, "write", tools.access_control) and user.role != "admin": + if ( + tools.user_id != user.id + and not has_access(user.id, "write", tools.access_control) + and user.role != "admin" + ): raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.UNAUTHORIZED,