Skip to content

Commit a1c90cf

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents a12001c + f898eef commit a1c90cf

File tree

30 files changed

+311
-70
lines changed

30 files changed

+311
-70
lines changed

backend/apps/datasource/crud/datasource.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ def updateNum(session: SessionDep, ds: CoreDatasource):
400400

401401
def get_table_obj_by_ds(session: SessionDep, current_user: CurrentUser, ds: CoreDatasource) -> List[TableAndFields]:
402402
_list: List = []
403-
tables = session.query(CoreTable).filter(CoreTable.ds_id == ds.id).all()
403+
tables = session.query(CoreTable).filter(
404+
and_(CoreTable.ds_id == ds.id, CoreTable.checked == True)
405+
).all()
404406
conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if ds.type != "excel" else get_engine_config()
405407
schema = conf.dbSchema if conf.dbSchema is not None and conf.dbSchema != "" else conf.database
406408

backend/apps/db/db.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ def check_sql_read(sql: str, ds: CoreDatasource | AssistantOutDsSchema):
670670
write_types = (
671671
exp.Insert, exp.Update, exp.Delete,
672672
exp.Create, exp.Drop, exp.Alter,
673-
exp.Merge, exp.Command
673+
exp.Merge, exp.Command, exp.Copy
674674
)
675675

676676
for stmt in statements:
@@ -688,6 +688,7 @@ def check_sql_read(sql: str, ds: CoreDatasource | AssistantOutDsSchema):
688688
def checkParams(extraParams: str, illegalParams: List[str]):
689689
kvs = extraParams.split('&')
690690
for kv in kvs:
691-
k, v = kv.split('=')
692-
if k in illegalParams:
693-
raise HTTPException(status_code=500, detail=f'Illegal Parameter: {k}')
691+
if kv and '=' in kv:
692+
k, v = kv.split('=')
693+
if k in illegalParams:
694+
raise HTTPException(status_code=500, detail=f'Illegal Parameter: {k}')

backend/apps/system/api/user.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ async def create(session: SessionDep, creator: UserCreator, trans: Trans):
180180
raise Exception(trans('i18n_exist', msg = f"{trans('i18n_user.email')} [{creator.email}]"))
181181
if not check_email_format(creator.email):
182182
raise Exception(trans('i18n_format_invalid', key = f"{trans('i18n_user.email')} [{creator.email}]"))
183-
data = creator.model_dump(exclude_unset=True)
183+
#data = creator.model_dump(exclude_unset=True)
184+
data = creator.model_dump()
184185
user_model = UserModel.model_validate(data)
185186
#user_model.create_time = get_timestamp()
186187
user_model.language = "zh-CN"

backend/apps/system/crud/assistant.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from common.utils.aes_crypto import simple_aes_decrypt
2222
from common.utils.utils import SQLBotLogUtil, equals_ignore_case, get_domain_list, string_to_numeric_hash
2323
from common.core.deps import Trans
24+
from common.core.response_middleware import ResponseMiddleware
2425

2526

2627
@cache(namespace=CacheNamespace.EMBEDDED_INFO, cacheName=CacheName.ASSISTANT_INFO, keyExpression="assistant_id")
@@ -87,13 +88,20 @@ def init_dynamic_cors(app: FastAPI):
8788
seen.add(domain)
8889
unique_domains.append(domain)
8990
cors_middleware = None
91+
response_middleware = None
9092
for middleware in app.user_middleware:
91-
if middleware.cls == CORSMiddleware:
93+
if not cors_middleware and middleware.cls == CORSMiddleware:
9294
cors_middleware = middleware
95+
if not response_middleware and middleware.cls == ResponseMiddleware:
96+
response_middleware = middleware
97+
if cors_middleware and response_middleware:
9398
break
99+
100+
updated_origins = list(set(settings.all_cors_origins + unique_domains))
94101
if cors_middleware:
95-
updated_origins = list(set(settings.all_cors_origins + unique_domains))
96102
cors_middleware.kwargs['allow_origins'] = updated_origins
103+
if response_middleware:
104+
response_middleware.kwargs['allow_origins'] = updated_origins
97105
except Exception as e:
98106
return False, e
99107

backend/apps/system/crud/system_variable.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Author: Junjun
22
# Date: 2026/1/26
33
import datetime
4-
54
from typing import List
5+
66
from fastapi import HTTPException
77
from sqlalchemy import and_
88
from sqlmodel import select
@@ -37,11 +37,12 @@ def delete(session: SessionDep, ids: List[int]):
3737

3838
def list_all(session: SessionDep, trans: Trans, variable: SystemVariable):
3939
if variable.name is None:
40-
records = session.query(SystemVariable).order_by(SystemVariable.type.desc()).all()
40+
records = session.query(SystemVariable).order_by(SystemVariable.type.desc(),
41+
SystemVariable.name.asc()).all()
4142
else:
4243
records = session.query(SystemVariable).filter(
43-
and_(SystemVariable.name.like(f'%{variable.name}%'), SystemVariable.type != 'system')).order_by(
44-
SystemVariable.type.desc()).all()
44+
and_(SystemVariable.name.ilike(f'%{variable.name}%'), SystemVariable.type != 'system')).order_by(
45+
SystemVariable.type.desc(), SystemVariable.name.asc()).all()
4546

4647
res = []
4748
for r in records:
@@ -58,11 +59,11 @@ async def list_page(session: SessionDep, trans: Trans, pageNum: int, pageSize: i
5859
filters = {}
5960

6061
if variable.name is None:
61-
stmt = select(SystemVariable).order_by(SystemVariable.type.desc())
62+
stmt = select(SystemVariable).order_by(SystemVariable.type.desc(), SystemVariable.name.asc())
6263
else:
6364
stmt = select(SystemVariable).where(
64-
and_(SystemVariable.name.like(f'%{variable.name}%'), SystemVariable.type != 'system')).order_by(
65-
SystemVariable.type.desc())
65+
and_(SystemVariable.name.ilike(f'%{variable.name}%'), SystemVariable.type != 'system')).order_by(
66+
SystemVariable.type.desc(), SystemVariable.name.asc())
6667

6768
variable_page = await paginator.get_paginated_response(
6869
stmt=stmt,
@@ -92,7 +93,7 @@ def checkName(session: SessionDep, trans: Trans, variable: SystemVariable):
9293
raise HTTPException(status_code=500, detail=trans('i18n_variable.name_exist'))
9394

9495

95-
def checkValue(session: SessionDep, trans: Trans, values:List):
96+
def checkValue(session: SessionDep, trans: Trans, values: List):
9697
# values: [{"variableId":1,"variableValues":["a","b"]}]
9798

98-
pass
99+
pass

backend/apps/system/schemas/system_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class UserCreator(BaseUser):
5858
status: int = Field(default=1, description=f"{PLACEHOLDER_PREFIX}status")
5959
origin: Optional[int] = Field(default=0, description=f"{PLACEHOLDER_PREFIX}origin")
6060
oid_list: Optional[list[int]] = Field(default=None, description=f"{PLACEHOLDER_PREFIX}oid")
61-
system_variables: Optional[List] = Field(default=None)
61+
system_variables: Optional[List] = Field(default=[])
6262

6363
""" @field_validator("email")
6464
def validate_email(cls, lang: str) -> str:

backend/apps/terminology/api/terminology.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def inner():
165165

166166
@router.post("/uploadExcel", summary=f"{PLACEHOLDER_PREFIX}upload_term")
167167
@system_log(LogConfig(operation_type=OperationType.IMPORT, module=OperationModules.TERMINOLOGY))
168+
@require_permissions(permission=SqlbotPermission(role=['ws_admin']))
168169
async def upload_excel(trans: Trans, current_user: CurrentUser, file: UploadFile = File(...)):
169170
ALLOWED_EXTENSIONS = {"xlsx", "xls"}
170171
if not file.filename.lower().endswith(tuple(ALLOWED_EXTENSIONS)):

backend/common/core/response_middleware.py

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

3+
from redis import typing
34
from starlette.exceptions import HTTPException
45
from starlette.middleware.base import BaseHTTPMiddleware
56
from starlette.requests import Request
@@ -11,6 +12,7 @@
1112

1213
class ResponseMiddleware(BaseHTTPMiddleware):
1314
def __init__(self, app):
15+
self.allow_origins = ["'self'"]
1416
super().__init__(app)
1517

1618
async def dispatch(self, request, call_next):
@@ -76,7 +78,13 @@ async def dispatch(self, request, call_next):
7678
if k.lower() not in ("content-length", "content-type")
7779
}
7880
)
79-
81+
content_type = response.headers.get("content-type", "")
82+
static_content_types = ["text/html", "javascript", "typescript", "css"]
83+
if any(ct in content_type for ct in static_content_types):
84+
if self.allow_origins:
85+
frame_ancestors_value = " ".join(self.allow_origins)
86+
response.headers["Content-Security-Policy"] = f"frame-ancestors {frame_ancestors_value};"
87+
8088
return response
8189

8290

frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"eslint-plugin-prettier": "^5.4.1",
6565
"eslint-plugin-vue": "^10.2.0",
6666
"globals": "^16.2.0",
67-
"less": "^4.3.0",
67+
"less": "4.4.2",
6868
"pinia": "^3.0.2",
6969
"prettier": "^3.5.3",
7070
"typescript": "~5.7.2",
@@ -76,4 +76,4 @@
7676
"vite-svg-loader": "^5.1.0",
7777
"vue-tsc": "^2.2.8"
7878
}
79-
}
79+
}
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)