|
@@ -17,7 +17,12 @@ import { ToastContext } from '@/app/components/base/toast'
|
|
|
import type { DataSet } from '@/models/datasets'
|
|
|
import { tagBindingsCreate, tagBindingsRemove, updateDatasetSetting } from '@/service/datasets'
|
|
|
import { useModalContext } from '@/context/modal-context'
|
|
|
-import { fetchDeptUsers, fetchTypes } from '@/service/common'
|
|
|
+import {
|
|
|
+ fetchDatasetsPermission,
|
|
|
+ fetchDeptUserTree,
|
|
|
+ fetchTypes,
|
|
|
+ setDatasetsPermission,
|
|
|
+} from '@/service/common'
|
|
|
import { TreeSelect as AntdTreeSelect } from 'antd'
|
|
|
|
|
|
type RenameDatasetModalProps = {
|
|
@@ -36,6 +41,9 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset
|
|
|
const [externalKnowledgeId, setExternalKnowledgeId] = useState<string>(dataset.external_knowledge_info.external_knowledge_id)
|
|
|
const [externalKnowledgeApiId, setExternalKnowledgeApiId] = useState<string>(dataset.external_knowledge_info.external_knowledge_api_id)
|
|
|
const [type, setType] = useState<any>(dataset.categories[0]?.id)
|
|
|
+ const [editAuth, setEditAuth] = useState()
|
|
|
+ const [editUserIds, setEditUserIds] = useState([])
|
|
|
+ const [lookUserIds, setLookUserIds] = useState([])
|
|
|
const [options, setOptions] = useState<any>([])
|
|
|
useEffect(() => {
|
|
|
fetchTypes({
|
|
@@ -87,6 +95,14 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset
|
|
|
},
|
|
|
})
|
|
|
}
|
|
|
+ await setDatasetsPermission({
|
|
|
+ url: `/datasets/${dataset.id}/permission`,
|
|
|
+ body: {
|
|
|
+ edit_auth: editAuth,
|
|
|
+ edit_permission: editUserIds.map((v: any) => ({ id: v })),
|
|
|
+ read_permission: lookUserIds.map((v: any) => ({ id: v })),
|
|
|
+ },
|
|
|
+ })
|
|
|
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
|
|
if (onSuccess)
|
|
|
onSuccess()
|
|
@@ -104,31 +120,51 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset
|
|
|
{ name: '本账号', value: 1 },
|
|
|
{ name: '本部门', value: 2 },
|
|
|
]
|
|
|
- const [editAuth, setEditAuth] = useState()
|
|
|
- const [editUserIds, setEditUserIds] = useState([])
|
|
|
- const [lookUserIds, setLookUserIds] = useState([])
|
|
|
const [optionsDeptUser, setOptionsDeptUser] = useState<any>([])
|
|
|
const [optionsDeptUserEdit, setOptionsDeptUserEdit] = useState<any>([])
|
|
|
useEffect(() => {
|
|
|
- fetchDeptUsers({
|
|
|
- url: '/xxx',
|
|
|
- params: {
|
|
|
- page: 1,
|
|
|
- limit: 99999,
|
|
|
- },
|
|
|
+ fetchDatasetsPermission({
|
|
|
+ url: `/datasets/${dataset.id}/permission`,
|
|
|
}).then((res: any) => {
|
|
|
- setOptionsDeptUser(res.data || [])
|
|
|
+ setEditAuth(res.edit_auth)
|
|
|
+ setEditUserIds(res.edit_permission.map((v: any) => v.id))
|
|
|
+ setLookUserIds(res.read_permission.map((v: any) => v.id))
|
|
|
})
|
|
|
}, [])
|
|
|
useEffect(() => {
|
|
|
- fetchDeptUsers({
|
|
|
- url: '/xxx',
|
|
|
- params: {
|
|
|
- page: 1,
|
|
|
- limit: 99999,
|
|
|
- },
|
|
|
+ fetchDeptUserTree({
|
|
|
+ url: '/dept/dept-accounts',
|
|
|
}).then((res: any) => {
|
|
|
- setOptionsDeptUserEdit(res.data || [])
|
|
|
+ const deep = (arr: any) => {
|
|
|
+ return arr.map((v: any) => {
|
|
|
+ v.treeId = v.dept_id || v.account_id
|
|
|
+ v.treeName = v.dept_name || v.email
|
|
|
+ if (v.children?.length > 0)
|
|
|
+ v.treeChildren = deep(v.children)
|
|
|
+ else if (v.accounts?.length > 0)
|
|
|
+ v.treeChildren = deep(v.accounts)
|
|
|
+ return v
|
|
|
+ })
|
|
|
+ }
|
|
|
+ setOptionsDeptUser(deep(res.data) || [])
|
|
|
+ })
|
|
|
+ }, [])
|
|
|
+ useEffect(() => {
|
|
|
+ fetchDeptUserTree({
|
|
|
+ url: '/dept/dept-accounts',
|
|
|
+ }).then((res: any) => {
|
|
|
+ const deep = (arr: any) => {
|
|
|
+ return arr.map((v: any) => {
|
|
|
+ v.treeId = v.dept_id || v.account_id
|
|
|
+ v.treeName = v.dept_name || v.email
|
|
|
+ if (v.children?.length > 0)
|
|
|
+ v.treeChildren = deep(v.children)
|
|
|
+ else if (v.accounts?.length > 0)
|
|
|
+ v.treeChildren = deep(v.accounts)
|
|
|
+ return v
|
|
|
+ })
|
|
|
+ }
|
|
|
+ setOptionsDeptUserEdit(deep(res.data) || [])
|
|
|
})
|
|
|
}, [])
|
|
|
return (
|
|
@@ -189,7 +225,7 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset
|
|
|
<SimpleSelect
|
|
|
className="h-[32px]"
|
|
|
defaultValue={editAuth}
|
|
|
- onSelect={(i) => {
|
|
|
+ onSelect={(i: any) => {
|
|
|
setEditAuth(i.value)
|
|
|
}}
|
|
|
items={optionsEditAuth}
|
|
@@ -210,7 +246,7 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset
|
|
|
treeDefaultExpandAll
|
|
|
onChange={v => setEditUserIds(v)}
|
|
|
treeData={optionsDeptUserEdit}
|
|
|
- fieldNames={{ label: 'name', value: 'id' }}
|
|
|
+ fieldNames={{ label: 'treeName', value: 'treeId', children: 'treeChildren' }}
|
|
|
multiple={true}
|
|
|
treeCheckable={true}
|
|
|
/>
|
|
@@ -227,7 +263,7 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset
|
|
|
treeDefaultExpandAll
|
|
|
onChange={v => setLookUserIds(v)}
|
|
|
treeData={optionsDeptUser}
|
|
|
- fieldNames={{ label: 'name', value: 'id' }}
|
|
|
+ fieldNames={{ label: 'treeName', value: 'treeId', children: 'treeChildren' }}
|
|
|
multiple={true}
|
|
|
treeCheckable={true}
|
|
|
/>
|