feat:精简
Some checks failed
Create and publish Docker images with specific build args / build-main-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-main-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda126-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda126-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-slim-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-slim-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Python CI / Format Backend (3.11.x) (push) Has been cancelled
Python CI / Format Backend (3.12.x) (push) Has been cancelled
Frontend Build / Format & Build Frontend (push) Has been cancelled
Frontend Build / Frontend Unit Tests (push) Has been cancelled
Create and publish Docker images with specific build args / merge-main-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-cuda-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-cuda126-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-ollama-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-slim-images (push) Has been cancelled
Close inactive issues / close-issues (push) Has been cancelled
Some checks failed
Create and publish Docker images with specific build args / build-main-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-main-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda126-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda126-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-slim-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-slim-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Python CI / Format Backend (3.11.x) (push) Has been cancelled
Python CI / Format Backend (3.12.x) (push) Has been cancelled
Frontend Build / Format & Build Frontend (push) Has been cancelled
Frontend Build / Frontend Unit Tests (push) Has been cancelled
Create and publish Docker images with specific build args / merge-main-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-cuda-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-cuda126-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-ollama-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-slim-images (push) Has been cancelled
Close inactive issues / close-issues (push) Has been cancelled
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import logging
|
||||
from decimal import Decimal
|
||||
from typing import Optional, List
|
||||
import base64
|
||||
import io
|
||||
@@ -15,12 +14,6 @@ from open_webui.models.oauth_sessions import OAuthSessions
|
||||
|
||||
from open_webui.models.groups import Groups
|
||||
from open_webui.models.chats import Chats
|
||||
from open_webui.models.credits import (
|
||||
Credits,
|
||||
SetCreditForm,
|
||||
SetCreditFormDetail,
|
||||
AddCreditForm,
|
||||
)
|
||||
from open_webui.models.users import (
|
||||
UserModel,
|
||||
UserGroupIdsModel,
|
||||
@@ -32,7 +25,6 @@ from open_webui.models.users import (
|
||||
Users,
|
||||
UserSettings,
|
||||
UserUpdateForm,
|
||||
UserCreditUpdateForm,
|
||||
)
|
||||
|
||||
from open_webui.constants import ERROR_MESSAGES
|
||||
@@ -87,15 +79,6 @@ async def get_users(
|
||||
users = result["users"]
|
||||
total = result["total"]
|
||||
|
||||
credit_map = {
|
||||
credit.user_id: {"credit": "%.4f" % credit.credit}
|
||||
for credit in Credits.list_credits_by_user_id(
|
||||
user_ids=(user.id for user in users)
|
||||
)
|
||||
}
|
||||
for user in users:
|
||||
setattr(user, "credit", credit_map.get(user.id, {}).get("credit", 0))
|
||||
|
||||
return {
|
||||
"users": [
|
||||
UserGroupIdsModel(
|
||||
@@ -117,15 +100,6 @@ async def get_all_users(
|
||||
user=Depends(get_admin_user),
|
||||
):
|
||||
user_data = Users.get_users()
|
||||
users = user_data["users"]
|
||||
credit_map = {
|
||||
credit.user_id: {"credit": "%.4f" % credit.credit}
|
||||
for credit in Credits.list_credits_by_user_id(
|
||||
user_ids=(user.id for user in users)
|
||||
)
|
||||
}
|
||||
for user in users:
|
||||
setattr(user, "credit", credit_map.get(user.id, {}).get("credit", 0))
|
||||
return user_data
|
||||
|
||||
|
||||
@@ -585,20 +559,6 @@ async def update_user_by_id(
|
||||
},
|
||||
)
|
||||
|
||||
if form_data.credit is not None:
|
||||
credit = Credits.set_credit_by_user_id(
|
||||
SetCreditForm(
|
||||
user_id=user_id,
|
||||
credit=Decimal(form_data.credit),
|
||||
detail=SetCreditFormDetail(
|
||||
api_path=str(request.url),
|
||||
api_params={"credit": form_data.credit},
|
||||
desc=f"updated by {session_user.name}",
|
||||
),
|
||||
)
|
||||
)
|
||||
setattr(updated_user, "credit", "%.4f" % credit.credit)
|
||||
|
||||
if updated_user:
|
||||
return updated_user
|
||||
|
||||
@@ -613,50 +573,6 @@ async def update_user_by_id(
|
||||
)
|
||||
|
||||
|
||||
############################
|
||||
# UpdateCreditByUserId
|
||||
############################
|
||||
|
||||
|
||||
@router.put("/{user_id}/credit", response_model=Optional[UserModel])
|
||||
async def update_credit_by_user_id(
|
||||
request: Request,
|
||||
user_id: str,
|
||||
form_data: UserCreditUpdateForm,
|
||||
session_user: UserModel = Depends(get_admin_user),
|
||||
) -> Response:
|
||||
user = Users.get_user_by_id(user_id)
|
||||
if not user:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=ERROR_MESSAGES.USER_NOT_FOUND,
|
||||
)
|
||||
|
||||
if form_data.amount is None and form_data.credit is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="amount or credit must be specified",
|
||||
)
|
||||
|
||||
params = {
|
||||
"user_id": user_id,
|
||||
"detail": SetCreditFormDetail(
|
||||
api_path=str(request.url),
|
||||
api_params=form_data.model_dump(),
|
||||
desc=f"updated by {session_user.name}",
|
||||
),
|
||||
}
|
||||
|
||||
if form_data.credit is not None:
|
||||
params["credit"] = Decimal(form_data.credit)
|
||||
Credits.set_credit_by_user_id(form_data=SetCreditForm(**params))
|
||||
elif form_data.amount is not None:
|
||||
params["amount"] = Decimal(form_data.amount)
|
||||
Credits.add_credit_by_user_id(form_data=AddCreditForm(**params))
|
||||
|
||||
return Response(status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
|
||||
############################
|
||||
# DeleteUserById
|
||||
############################
|
||||
|
||||
Reference in New Issue
Block a user