Skip to content

Commit cac8dc8

Browse files
feat: Search user api
1 parent 9a02f6d commit cac8dc8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

backend/apps/system/api/workspace.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ async def option_pager(
4242
stmt=stmt,
4343
pagination=pagination,
4444
)
45+
46+
@router.get("/uws/option", response_model=UserWsOption)
47+
async def option_user(
48+
session: SessionDep,
49+
current_user: CurrentUser,
50+
keyword: str = Query(description="搜索关键字")
51+
):
52+
if (not current_user.isAdmin) and current_user.weight == 0:
53+
raise RuntimeError("no permission to execute this api")
54+
oid = current_user.oid
55+
56+
stmt = select(UserModel.id, UserModel.account, UserModel.name).where(
57+
~exists().where(UserWsModel.uid == UserModel.id, UserWsModel.oid == oid)
58+
)
59+
60+
if keyword:
61+
stmt = stmt.where(
62+
or_(
63+
UserModel.account == int(keyword),
64+
UserModel.name == keyword,
65+
)
66+
)
67+
return session.exec(stmt).first()
4568

4669
@router.get("/uws/pager/{pageNum}/{pageSize}", response_model=PaginatedResponse[WorkspaceUser])
4770
async def pager(

0 commit comments

Comments
 (0)