Skip to content

Commit a37fc35

Browse files
fix: Assistant change ds by workspace
1 parent a26b8e5 commit a37fc35

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

backend/apps/datasource/api/datasource.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
router = APIRouter(tags=["datasource"], prefix="/datasource")
1919
path = "/opt/sqlbot/data/excel"
2020

21+
@router.get("/ws/{oid}", include_in_schema=False)
22+
async def query_by_oid(session: SessionDep, user: CurrentUser, oid: int) -> List[CoreDatasource]:
23+
if not user.isAdmin:
24+
raise Exception("no permission to execute")
25+
return get_datasource_list(session=session, user=user, oid=oid)
2126

2227
@router.get("/list")
2328
async def datasource_list(session: SessionDep, user: CurrentUser):

backend/apps/datasource/crud/datasource.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22
import json
3-
from typing import List
3+
from typing import List, Optional
44

55
from fastapi import HTTPException
66
from sqlalchemy import and_, text, cast, or_, func
@@ -25,10 +25,13 @@
2525
DatasourceConf, TableAndFields
2626

2727

28-
def get_datasource_list(session: SessionDep, user: CurrentUser):
29-
oid = user.oid if user.oid is not None else 1
30-
return session.query(CoreDatasource).filter(CoreDatasource.oid == oid).order_by(
31-
func.convert_to(CoreDatasource.name, 'gbk')).all()
28+
def get_datasource_list(session: SessionDep, user: CurrentUser, oid: Optional[int] = None) -> List[CoreDatasource]:
29+
current_oid = user.oid if user.oid is not None else 1
30+
if user.isAdmin and oid:
31+
current_oid = oid
32+
return session.exec(select(CoreDatasource).where(CoreDatasource.oid == current_oid).order_by(
33+
func.convert_to(CoreDatasource.name, 'gbk'))).all()
34+
3235

3336

3437
def get_ds(session: SessionDep, id: int):

frontend/src/api/embedded.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export const updateAssistant = (data: any) => request.put('/system/assistant', d
55
export const saveAssistant = (data: any) => request.post('/system/assistant', data)
66
export const getOne = (id: any) => request.get(`/system/assistant/${id}`)
77
export const delOne = (id: any) => request.delete(`/system/assistant/${id}`)
8+
export const dsApi = (id: any) => request.get(`/datasource/ws/${id}`)

frontend/src/views/system/embedded/index.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import icon_copy_outlined from '@/assets/embedded/icon_copy_outlined.svg'
1414
import Card from './Card.vue'
1515
import { workspaceList } from '@/api/workspace'
1616
import DsCard from './DsCard.vue'
17-
import { datasourceApi } from '@/api/datasource'
18-
import { getList, updateAssistant, saveAssistant, delOne } from '@/api/embedded'
17+
import { getList, updateAssistant, saveAssistant, delOne, dsApi } from '@/api/embedded'
1918
import { useI18n } from 'vue-i18n'
2019
import { cloneDeep } from 'lodash-es'
2120
@@ -49,7 +48,7 @@ const currentEmbedded = reactive<any>(cloneDeep(defaultEmbedded))
4948
5049
const isCreate = ref(false)
5150
const defaultForm = {
52-
oid: '',
51+
oid: 1,
5352
private_list: [] as any,
5453
}
5554
const dsForm = reactive(cloneDeep(defaultForm))
@@ -107,9 +106,13 @@ const handleAddEmbedded = (val: any) => {
107106
handleAdvancedEmbedded(null)
108107
}
109108
}
110-
109+
const wsChanged = (val: any) => {
110+
dsForm.private_list = []
111+
dsForm.oid = val
112+
getDsList()
113+
}
111114
const getDsList = () => {
112-
datasourceApi.list().then((res: any) => {
115+
dsApi(dsForm.oid).then((res: any) => {
113116
dsListOptions.value = res || []
114117
if (!currentEmbedded.id) {
115118
dsForm.private_list = dsListOptions.value.map((ele) => ele.id)
@@ -119,10 +122,10 @@ const getDsList = () => {
119122
const handleBaseEmbedded = (row: any) => {
120123
advancedApplication.value = false
121124
initWorkspace()
122-
getDsList()
123125
if (row) {
124126
Object.assign(dsForm, JSON.parse(row.configuration))
125127
}
128+
getDsList()
126129
ruleConfigvVisible.value = true
127130
dialogTitle.value = row?.id
128131
? t('embedded.edit_basic_applications')
@@ -697,6 +700,7 @@ const saveHandler = () => {
697700
:placeholder="
698701
$t('datasource.please_enter') + $t('common.empty') + $t('user.workspace')
699702
"
703+
@change="wsChanged"
700704
>
701705
<el-option
702706
v-for="item in workspaces"

0 commit comments

Comments
 (0)