Skip to content

Commit e54a5fe

Browse files
perf: Place the assistant menu in the workspace
1 parent b8b3727 commit e54a5fe

File tree

12 files changed

+121
-34
lines changed

12 files changed

+121
-34
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""061_assistant_oid_ddl
2+
3+
Revision ID: 547df942eb90
4+
Revises: b40e41c67db3
5+
Create Date: 2026-01-09 15:02:19.891766
6+
7+
"""
8+
import json
9+
from alembic import op
10+
import sqlalchemy as sa
11+
import sqlmodel.sql.sqltypes
12+
from sqlalchemy.dialects import postgresql
13+
14+
# revision identifiers, used by Alembic.
15+
revision = '547df942eb90'
16+
down_revision = 'b40e41c67db3'
17+
branch_labels = None
18+
depends_on = None
19+
20+
21+
def upgrade():
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
24+
op.add_column('sys_assistant', sa.Column('oid', sa.BigInteger(), nullable=True))
25+
conn = op.get_bind()
26+
conn.execute(sa.text("UPDATE sys_assistant SET oid = 1 WHERE oid IS NULL"))
27+
rows = conn.execute(
28+
sa.text("SELECT id, configuration FROM sys_assistant WHERE type = 0 AND configuration IS NOT NULL")
29+
)
30+
for row in rows:
31+
try:
32+
config = json.loads(row.configuration) if isinstance(row.configuration, str) else row.configuration
33+
oid_value = config.get('oid', 1) if isinstance(config, dict) else 1
34+
if isinstance(oid_value, int) and oid_value != 1:
35+
conn.execute(
36+
sa.text("UPDATE sys_assistant SET oid = :oid WHERE id = :id"),
37+
{"oid": oid_value, "id": row.id}
38+
)
39+
except (json.JSONDecodeError, TypeError, AttributeError):
40+
pass
41+
42+
# ### end Alembic commands ###
43+
44+
45+
def downgrade():
46+
# ### commands auto generated by Alembic - please adjust! ###
47+
op.drop_column('sys_assistant', 'oid')
48+
# ### end Alembic commands ###

backend/apps/system/api/assistant.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from apps.system.schemas.auth import CacheName, CacheNamespace
1616
from apps.system.schemas.system_schema import AssistantBase, AssistantDTO, AssistantUiSchema, AssistantValidator
1717
from common.core.config import settings
18-
from common.core.deps import SessionDep, Trans
18+
from common.core.deps import SessionDep, Trans, CurrentUser
1919
from common.core.security import create_access_token
2020
from common.core.sqlbot_cache import clear_cache
2121
from common.utils.utils import get_origin_from_referer, origin_match_domain
@@ -165,8 +165,8 @@ async def clear_ui_cache(id: int):
165165

166166

167167
@router.get("", response_model=list[AssistantModel], summary=f"{PLACEHOLDER_PREFIX}assistant_grid_api", description=f"{PLACEHOLDER_PREFIX}assistant_grid_api")
168-
async def query(session: SessionDep):
169-
list_result = session.exec(select(AssistantModel).where(AssistantModel.type != 4).order_by(AssistantModel.name,
168+
async def query(session: SessionDep, current_user: CurrentUser):
169+
list_result = session.exec(select(AssistantModel).where(AssistantModel.oid == current_user.oid, AssistantModel.type != 4).order_by(AssistantModel.name,
170170
AssistantModel.create_time)).all()
171171
return list_result
172172

@@ -180,8 +180,9 @@ async def query_advanced_application(session: SessionDep):
180180

181181
@router.post("", summary=f"{PLACEHOLDER_PREFIX}assistant_create_api", description=f"{PLACEHOLDER_PREFIX}assistant_create_api")
182182
@system_log(LogConfig(operation_type=OperationType.CREATE, module=OperationModules.APPLICATION, result_id_expr="id"))
183-
async def add(request: Request, session: SessionDep, creator: AssistantBase):
184-
return await save(request, session, creator)
183+
async def add(request: Request, session: SessionDep, current_user: CurrentUser, creator: AssistantBase):
184+
oid = current_user.oid if creator.type != 4 else 1
185+
return await save(request, session, creator, oid)
185186

186187

187188
@router.put("", summary=f"{PLACEHOLDER_PREFIX}assistant_update_api", description=f"{PLACEHOLDER_PREFIX}assistant_update_api")

backend/apps/system/crud/assistant_manage.py

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

22

3+
from typing import Optional
34
from fastapi import FastAPI, Request
45
from sqlmodel import Session, select
56
from starlette.middleware.cors import CORSMiddleware
@@ -32,9 +33,10 @@ def dynamic_upgrade_cors(request: Request, session: Session):
3233
cors_middleware.kwargs['allow_origins'] = updated_origins
3334

3435

35-
async def save(request: Request, session: Session, creator: AssistantBase):
36+
async def save(request: Request, session: Session, creator: AssistantBase, oid: Optional[int] = 1):
3637
db_model = AssistantModel.model_validate(creator)
3738
db_model.create_time = get_timestamp()
39+
db_model.oid = oid
3840
session.add(db_model)
3941
session.commit()
4042
dynamic_upgrade_cors(request=request, session=session)

backend/apps/system/models/system_model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class AssistantBaseModel(SQLModel):
5252
create_time: int = Field(default=0, sa_type=BigInteger())
5353
app_id: Optional[str] = Field(default=None, max_length=255, nullable=True)
5454
app_secret: Optional[str] = Field(default=None, max_length=255, nullable=True)
55+
oid: Optional[int] = Field(nullable=True, sa_type=BigInteger(), default=1)
5556

5657
class AssistantModel(SnowflakeBase, AssistantBaseModel, table=True):
5758
__tablename__ = "sys_assistant"

frontend/src/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@
668668
"welcome_description": "Welcome Description",
669669
"data_analysis_now": "I can query data, generate charts, detect data anomalies, predict data, and more! Enable Smart Data Analysis now!",
670670
"window_entrance_icon": "Floating window entrance icon",
671-
"preview_error": "The current page prohibits embedding using Iframe!"
671+
"preview_error": "The current page prohibits embedding using Iframe!",
672+
"assistant_app": "Assistant App"
672673
},
673674
"chat": {
674675
"type": "Chart Type",

frontend/src/i18n/ko-KR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@
668668
"welcome_description": "환영 메시지 설명",
669669
"data_analysis_now": "저는 데이터 조회, 차트 생성, 데이터 이상 감지, 데이터 예측 등을 할 수 있습니다. 빨리 스마트 데이터 조회를 시작하세요~",
670670
"window_entrance_icon": "플로팅 윈도우 입구 아이콘",
671-
"preview_error": "현재 페이지는 Iframe 임베딩을 허용하지 않습니다!"
671+
"preview_error": "현재 페이지는 Iframe 임베딩을 허용하지 않습니다!",
672+
"assistant_app": "어시스턴트 앱"
672673
},
673674
"chat": {
674675
"type": "차트 유형",

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@
668668
"welcome_description": "欢迎语描述",
669669
"data_analysis_now": "我可以查询数据、生成图表、检测数据异常、预测数据等赶快开启智能问数吧~",
670670
"window_entrance_icon": "浮窗入口图标",
671-
"preview_error": "当前页面禁止使用 Iframe 嵌入!"
671+
"preview_error": "当前页面禁止使用 Iframe 嵌入!",
672+
"assistant_app": "小助手应用"
672673
},
673674
"chat": {
674675
"type": "图表类型",

frontend/src/router/dynamic.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import LayoutDsl from '@/components/layout/LayoutDsl.vue'
22

33
import Datasource from '@/views/ds/Datasource.vue'
4+
import SetAssistant from '@/views/system/embedded/iframe.vue'
45
import { i18n } from '@/i18n'
56
import { useUserStore } from '@/stores/user'
67
import type { Router } from 'vue-router'
@@ -22,6 +23,13 @@ const dynamicRouterList = [
2223
},
2324
],
2425
},
26+
{
27+
parent: 'set',
28+
path: '/set/assistant',
29+
name: 'setAssistant',
30+
component: SetAssistant,
31+
meta: { title: t('embedded.assistant_app') },
32+
},
2533
] as any[]
2634

2735
const reduceRouters = (router: Router, invalid_router_name_list: string[]) => {
@@ -71,7 +79,17 @@ const reduceRouters = (router: Router, invalid_router_name_list: string[]) => {
7179

7280
export const generateDynamicRouters = (router: Router) => {
7381
if (userStore.isAdmin || userStore.isSpaceAdmin) {
74-
dynamicRouterList.forEach((item: any) => router.addRoute(item))
82+
dynamicRouterList.forEach((item: any) => {
83+
if (!item.parent) {
84+
router.addRoute(item)
85+
} else {
86+
router.addRoute(item.parent, item)
87+
const parentRoute: any = router.getRoutes().find((r: any) => r.name === item.parent)
88+
if (parentRoute?.children) {
89+
parentRoute.children.push(item)
90+
}
91+
}
92+
})
7593
} else {
7694
const router_name_list = [] as string[]
7795
const stack = [...dynamicRouterList]

frontend/src/router/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import DashboardEditor from '@/views/dashboard/editor/index.vue'
99
import DashboardPreview from '@//views/dashboard/preview/SQPreviewSingle.vue'
1010
import Dashboard from '@/views/dashboard/index.vue'
1111
import Model from '@/views/system/model/Model.vue'
12-
import Embedded from '@/views/system/embedded/index.vue'
12+
// import Embedded from '@/views/system/embedded/index.vue'
13+
// import SetAssistant from '@/views/system/embedded/iframe.vue'
14+
import SystemEmbedded from '@/views/system/embedded/Page.vue'
15+
1316
import assistantTest from '@/views/system/embedded/Test.vue'
1417
import assistant from '@/views/embedded/index.vue'
1518
import EmbeddedPage from '@/views/embedded/page.vue'
@@ -116,6 +119,12 @@ export const routes = [
116119
component: Permission,
117120
meta: { title: t('workspace.permission_configuration') },
118121
},
122+
/* {
123+
path: '/set/assistant',
124+
name: 'setAssistant',
125+
component: SetAssistant,
126+
meta: { title: t('embedded.assistant_app') },
127+
}, */
119128
{
120129
path: '/set/professional',
121130
name: 'professional',
@@ -184,7 +193,7 @@ export const routes = [
184193
{
185194
path: 'embedded',
186195
name: 'embedded',
187-
component: Embedded,
196+
component: SystemEmbedded,
188197
meta: {
189198
title: t('embedded.embedded_management'),
190199
iconActive: 'embedded',

frontend/src/router/watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const watchRouter = (router: Router) => {
3939
if (!userStore.getUid) {
4040
await userStore.info()
4141
generateDynamicRouters(router)
42-
isFirstDynamicPath = to?.path === '/ds/index'
42+
isFirstDynamicPath = to?.path && ['/ds/index', '/set/assistant'].includes(to.path)
4343
if (isFirstDynamicPath) {
4444
next({ ...to, replace: true })
4545
return

0 commit comments

Comments
 (0)