Skip to content

Commit 3102633

Browse files
committed
Merge branch 'main' of https://github.com/dataease/SQLBot
2 parents 759e7ae + 85ab1ec commit 3102633

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

backend/apps/chat/task/llm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ def run_task(self, in_chat: bool = True):
834834

835835
# execute sql
836836
result = self.execute_sql(sql=sql)
837+
print(result)
837838
self.save_sql_data(data_obj=result)
838839
if in_chat:
839840
yield orjson.dumps({'content': 'execute-success', 'type': 'sql-data'}).decode() + '\n\n'

backend/apps/system/api/login.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def local_login(
2121

2222
if not user.oid or user.oid == 0:
2323
raise HTTPException(status_code=400, detail="No associated workspace, Please contact the administrator")
24+
if user.status != 1:
25+
raise HTTPException(status_code=400, detail="User is disabled, Please contact the administrator")
2426
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
2527
user_dict = user.to_dict()
2628
return Token(access_token=create_access_token(

backend/apps/system/api/user.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Optional
22
from fastapi import APIRouter, HTTPException, Query
33
from sqlmodel import func, or_, select, delete as sqlmodel_delete
4-
from apps.system.crud.user import get_db_user, single_delete, user_ws_options
4+
from apps.system.crud.user import check_account_exists, get_db_user, single_delete, user_ws_options
55
from apps.system.models.system_model import UserWsModel
66
from apps.system.models.user import UserModel
77
from apps.system.schemas.auth import CacheName, CacheNamespace
@@ -116,6 +116,9 @@ async def query(session: SessionDep, trans: Trans, id: int) -> UserEditor:
116116

117117
@router.post("")
118118
async def create(session: SessionDep, creator: UserCreator):
119+
count = check_account_exists(session=session, account=creator.account)
120+
if count > 0:
121+
raise Exception(f"Account [{creator.account}] already exists!")
119122
data = creator.model_dump(exclude_unset=True)
120123
user_model = UserModel.model_validate(data)
121124
#user_model.create_time = get_timestamp()
@@ -140,6 +143,10 @@ async def create(session: SessionDep, creator: UserCreator):
140143
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="editor.id")
141144
async def update(session: SessionDep, editor: UserEditor):
142145
user_model: UserModel = get_db_user(session = session, user_id = editor.id)
146+
if not user_model:
147+
raise Exception(f"User with id [{editor.id}] not found!")
148+
if editor.account != user_model.account:
149+
raise Exception(f"account cannot be changed!")
143150
origin_oid: int = user_model.oid
144151
del_stmt = sqlmodel_delete(UserWsModel).where(UserWsModel.uid == editor.id)
145152
session.exec(del_stmt)

backend/apps/system/crud/user.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
from typing import Optional
3-
from sqlmodel import Session, select, delete as sqlmodel_delete
3+
from sqlmodel import Session, func, select, delete as sqlmodel_delete
44
from apps.system.models.system_model import UserWsModel, WorkspaceModel
55
from apps.system.schemas.auth import CacheName, CacheNamespace
66
from apps.system.schemas.system_schema import BaseUserDTO, UserInfoDTO, UserWs
@@ -69,3 +69,7 @@ async def single_delete(session: SessionDep, id: int):
6969
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="id")
7070
async def clean_user_cache(id: int):
7171
SQLBotLogUtil.info(f"User cache for [{id}] has been cleaned")
72+
73+
74+
def check_account_exists(*, session: Session, account: str) -> bool:
75+
return session.exec(select(func.count()).select_from(UserModel).where(UserModel.account == account)).one()

backend/apps/system/schemas/system_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class BaseUser(BaseModel):
1919
class BaseUserDTO(BaseUser, BaseCreatorDTO):
2020
language: str
2121
password: str
22+
status: int = 1
2223
def to_dict(self):
2324
return {
2425
"id": self.id,

0 commit comments

Comments
 (0)