|
2 | 2 | from fastapi import APIRouter, HTTPException, Query |
3 | 3 | from sqlmodel import func, or_, select, delete as sqlmodel_delete |
4 | 4 | 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 |
6 | 6 | from apps.system.models.user import UserModel |
7 | 7 | from apps.system.schemas.auth import CacheName, CacheNamespace |
8 | 8 | 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 |
96 | 96 |
|
97 | 97 | @router.put("/ws/{oid}") |
98 | 98 | @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): |
100 | 100 | ws_list: list[UserWs] = await user_ws_options(session, current_user.id) |
101 | 101 | 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}]")) |
103 | 106 | user_model: UserModel = get_db_user(session = session, user_id = current_user.id) |
104 | 107 | user_model.oid = oid |
105 | 108 | session.add(user_model) |
|
0 commit comments