|
@@ -18,7 +18,7 @@ from open_webui.apps.webui.models.auths import (
|
|
|
UserResponse,
|
|
|
)
|
|
|
from open_webui.apps.webui.models.users import Users
|
|
|
-from open_webui.config import ENABLE_API_KEY_AUTH
|
|
|
+
|
|
|
from open_webui.constants import ERROR_MESSAGES, WEBHOOK_MESSAGES
|
|
|
from open_webui.env import (
|
|
|
WEBUI_AUTH,
|
|
@@ -581,6 +581,7 @@ async def get_admin_config(request: Request, user=Depends(get_admin_user)):
|
|
|
return {
|
|
|
"SHOW_ADMIN_DETAILS": request.app.state.config.SHOW_ADMIN_DETAILS,
|
|
|
"ENABLE_SIGNUP": request.app.state.config.ENABLE_SIGNUP,
|
|
|
+ "ENABLE_API_KEY": request.app.state.config.ENABLE_API_KEY,
|
|
|
"DEFAULT_USER_ROLE": request.app.state.config.DEFAULT_USER_ROLE,
|
|
|
"JWT_EXPIRES_IN": request.app.state.config.JWT_EXPIRES_IN,
|
|
|
"ENABLE_COMMUNITY_SHARING": request.app.state.config.ENABLE_COMMUNITY_SHARING,
|
|
@@ -591,6 +592,7 @@ async def get_admin_config(request: Request, user=Depends(get_admin_user)):
|
|
|
class AdminConfig(BaseModel):
|
|
|
SHOW_ADMIN_DETAILS: bool
|
|
|
ENABLE_SIGNUP: bool
|
|
|
+ ENABLE_API_KEY: bool
|
|
|
DEFAULT_USER_ROLE: str
|
|
|
JWT_EXPIRES_IN: str
|
|
|
ENABLE_COMMUNITY_SHARING: bool
|
|
@@ -603,6 +605,7 @@ async def update_admin_config(
|
|
|
):
|
|
|
request.app.state.config.SHOW_ADMIN_DETAILS = form_data.SHOW_ADMIN_DETAILS
|
|
|
request.app.state.config.ENABLE_SIGNUP = form_data.ENABLE_SIGNUP
|
|
|
+ request.app.state.config.ENABLE_API_KEY = form_data.ENABLE_API_KEY
|
|
|
|
|
|
if form_data.DEFAULT_USER_ROLE in ["pending", "user", "admin"]:
|
|
|
request.app.state.config.DEFAULT_USER_ROLE = form_data.DEFAULT_USER_ROLE
|
|
@@ -621,6 +624,7 @@ async def update_admin_config(
|
|
|
return {
|
|
|
"SHOW_ADMIN_DETAILS": request.app.state.config.SHOW_ADMIN_DETAILS,
|
|
|
"ENABLE_SIGNUP": request.app.state.config.ENABLE_SIGNUP,
|
|
|
+ "ENABLE_API_KEY": request.app.state.config.ENABLE_API_KEY,
|
|
|
"DEFAULT_USER_ROLE": request.app.state.config.DEFAULT_USER_ROLE,
|
|
|
"JWT_EXPIRES_IN": request.app.state.config.JWT_EXPIRES_IN,
|
|
|
"ENABLE_COMMUNITY_SHARING": request.app.state.config.ENABLE_COMMUNITY_SHARING,
|
|
@@ -734,14 +738,16 @@ async def update_ldap_config(
|
|
|
|
|
|
# create api key
|
|
|
@router.post("/api_key", response_model=ApiKey)
|
|
|
-async def create_api_key_(user=Depends(get_current_user)):
|
|
|
- if not ENABLE_API_KEY_AUTH:
|
|
|
+async def create_api_key(request: Request, user=Depends(get_current_user)):
|
|
|
+ if not request.app.config.state.ENABLE_API_KEY:
|
|
|
raise HTTPException(
|
|
|
- status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.API_KEY_CREATION_NOT_ALLOWED
|
|
|
+ status.HTTP_403_FORBIDDEN,
|
|
|
+ detail=ERROR_MESSAGES.API_KEY_CREATION_NOT_ALLOWED,
|
|
|
)
|
|
|
|
|
|
api_key = create_api_key()
|
|
|
success = Users.update_user_api_key_by_id(user.id, api_key)
|
|
|
+
|
|
|
if success:
|
|
|
return {
|
|
|
"api_key": api_key,
|