Skip to content

Commit c362223

Browse files
perf: User change oid api
1 parent cebf845 commit c362223

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

backend/apps/system/api/user.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from fastapi import APIRouter, HTTPException, Query
33
from sqlmodel import func, or_, select, delete as sqlmodel_delete
44
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
5-
from apps.system.models.system_model import UserWsModel
5+
from apps.system.models.system_model import UserWsModel, WorkspaceModel
66
from apps.system.models.user import UserModel
77
from apps.system.schemas.auth import CacheName, CacheNamespace
88
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
9696

9797
@router.put("/ws/{oid}")
9898
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="current_user.id")
99-
async def ws_change(session: SessionDep, current_user: CurrentUser, oid: int):
99+
async def ws_change(session: SessionDep, current_user: CurrentUser, trans:Trans, oid: int):
100100
ws_list: list[UserWs] = await user_ws_options(session, current_user.id)
101101
if not any(x.id == oid for x in ws_list):
102-
raise Exception(f"oid [{oid}] is invalid!")
102+
db_ws = session.get(WorkspaceModel, oid)
103+
if db_ws:
104+
raise Exception(trans('i18n_user.user_ws_miss', msg = db_ws.name))
105+
raise Exception(trans('i18n_not_exist', msg = f"{trans('i18n_ws.title')}[{oid}]"))
103106
user_model: UserModel = get_db_user(session = session, user_id = current_user.id)
104107
user_model.oid = oid
105108
session.add(user_model)

backend/locales/en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"i18n_ds_name_exist": "Name already exists",
44
"i18n_concat_admin": "Please contact administrator!",
55
"i18n_exist": "{msg} already exists!",
6+
"i18n_not_exist": "{msg} not exists",
67
"i18n_error": "{key} error!",
78
"i18n_miss_args": "Missing {key} parameter!",
89
"i18n_format_invalid": "{key} format is incorrect!",
@@ -15,7 +16,11 @@
1516
"account": "Account",
1617
"email": "Email",
1718
"password": "Password",
18-
"language_not_support": "System does not support [{key}] language!"
19+
"language_not_support": "System does not support [{key}] language!",
20+
"user_ws_miss:": "The current user is not in the workspace [{msg}]!"
21+
},
22+
"i18n_ws": {
23+
"title": "Workspace"
1924
},
2025
"i18n_permission": {
2126
"only_admin": "Only administrators can call this!",

backend/locales/zh-CN.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"i18n_ds_name_exist": "名称已存在",
44
"i18n_concat_admin": "请联系管理员!",
55
"i18n_exist": "{msg}已存在!",
6+
"i18n_not_exist": "{msg}不存在!",
67
"i18n_error": "{key}错误!",
78
"i18n_miss_args": "缺失{key}参数!",
89
"i18n_format_invalid": "{key}格式不正确!",
@@ -15,7 +16,11 @@
1516
"account": "账号",
1617
"email": "邮箱",
1718
"password": "密码",
18-
"language_not_support": "系统不支持[{key}]语言!"
19+
"language_not_support": "系统不支持[{key}]语言!",
20+
"user_ws_miss:": "当前用户不在工作空间[{msg}]中!"
21+
},
22+
"i18n_ws": {
23+
"title": "工作空间"
1924
},
2025
"i18n_permission": {
2126
"only_admin": "仅支持管理员调用!",

0 commit comments

Comments
 (0)