This commit is contained in:
dataeaseShu
2025-07-28 10:58:13 +08:00
3 changed files with 18 additions and 5 deletions
+6 -3
View File
@@ -2,7 +2,7 @@ from typing import Optional
from fastapi import APIRouter, HTTPException, Query
from sqlmodel import func, or_, select, delete as sqlmodel_delete
from apps.system.crud.user import check_account_exists, check_email_exists, check_email_format, check_pwd_format, get_db_user, single_delete, user_ws_options
from apps.system.models.system_model import UserWsModel
from apps.system.models.system_model import UserWsModel, WorkspaceModel
from apps.system.models.user import UserModel
from apps.system.schemas.auth import CacheName, CacheNamespace
from apps.system.schemas.system_schema import PwdEditor, UserCreator, UserEditor, UserGrid, UserLanguage, UserStatus, UserWs
@@ -96,10 +96,13 @@ async def ws_options(session: SessionDep, current_user: CurrentUser, trans: Tran
@router.put("/ws/{oid}")
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="current_user.id")
async def ws_change(session: SessionDep, current_user: CurrentUser, oid: int):
async def ws_change(session: SessionDep, current_user: CurrentUser, trans:Trans, oid: int):
ws_list: list[UserWs] = await user_ws_options(session, current_user.id)
if not any(x.id == oid for x in ws_list):
raise Exception(f"oid [{oid}] is invalid!")
db_ws = session.get(WorkspaceModel, oid)
if db_ws:
raise Exception(trans('i18n_user.ws_miss', ws = db_ws.name))
raise Exception(trans('i18n_not_exist', msg = f"{trans('i18n_ws.title')}[{oid}]"))
user_model: UserModel = get_db_user(session = session, user_id = current_user.id)
user_model.oid = oid
session.add(user_model)
+6 -1
View File
@@ -3,6 +3,7 @@
"i18n_ds_name_exist": "Name already exists",
"i18n_concat_admin": "Please contact administrator!",
"i18n_exist": "{msg} already exists!",
"i18n_not_exist": "{msg} not exists",
"i18n_error": "{key} error!",
"i18n_miss_args": "Missing {key} parameter!",
"i18n_format_invalid": "{key} format is incorrect!",
@@ -15,7 +16,11 @@
"account": "Account",
"email": "Email",
"password": "Password",
"language_not_support": "System does not support [{key}] language!"
"language_not_support": "System does not support [{key}] language!",
"ws_miss": "The current user is not in the workspace [{ws}]!"
},
"i18n_ws": {
"title": "Workspace"
},
"i18n_permission": {
"only_admin": "Only administrators can call this!",
+6 -1
View File
@@ -3,6 +3,7 @@
"i18n_ds_name_exist": "名称已存在",
"i18n_concat_admin": "请联系管理员!",
"i18n_exist": "{msg}已存在!",
"i18n_not_exist": "{msg}不存在!",
"i18n_error": "{key}错误!",
"i18n_miss_args": "缺失{key}参数!",
"i18n_format_invalid": "{key}格式不正确!",
@@ -15,7 +16,11 @@
"account": "账号",
"email": "邮箱",
"password": "密码",
"language_not_support": "系统不支持[{key}]语言!"
"language_not_support": "系统不支持[{key}]语言!",
"ws_miss": "当前用户不在工作空间[{ws}]中!"
},
"i18n_ws": {
"title": "工作空间"
},
"i18n_permission": {
"only_admin": "仅支持管理员调用!",