CzRger 3 hónapja%!(EXTRA string=óta)
szülő
commit
188679e2d2

+ 57 - 21
web/app/components/datasets/rename-modal/index.tsx

@@ -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}
           />

+ 3 - 3
web/app/components/header/account-setting/dept-page/user-modal.tsx

@@ -71,7 +71,7 @@ const UserModal = ({
     <div>
       <Modal overflowVisible isShow onClose={() => { }} className="p-[24px 32px] w-[800px] max-w-[800px]">
         <div className='mb-2 flex justify-between'>
-          <div className='text-xl font-semibold text-text-primary'>关联用户</div>
+          <div className='text-xl font-semibold text-text-primary'>{transfer.row.dept_name}关联用户</div>
           <RiCloseLine className='h-4 w-4 cursor-pointer text-text-tertiary' onClick={onCancel} />
         </div>
         <div className='flex h-[600px] flex-col'>
@@ -115,7 +115,7 @@ const UserModal = ({
                 <table className={'mt-3 w-full min-w-[700px] max-w-full border-collapse border-0 text-sm'}>
                   <thead className="h-8 border-b border-divider-subtle text-xs font-medium uppercase leading-8 text-text-tertiary">
                     <tr>
-                      <td>用户名称</td>
+                      {/* <td>用户名称</td> */}
                       <td>用户账号</td>
                       <td className="w-[120px] text-center">操作</td>
                     </tr>
@@ -126,7 +126,7 @@ const UserModal = ({
                         key={item.id}
                         className={'h-8 border-b border-divider-subtle hover:bg-background-default-hover'}
                       >
-                        <td>{item.name}</td>
+                        {/* <td>{item.name}</td> */}
                         <td>{item.email}</td>
                         <td className="flex justify-center gap-2">
                           <Button variant='ghost' size='small' className={cn('shrink-0 text-red-600')} onClick={() => {

+ 15 - 0
web/service/common.ts

@@ -613,3 +613,18 @@ export const deptDelUsers = ({ url, body }: any) => {
   console.log('部门删除用户', url, body)
   return del(url, { body })
 }
+
+export const fetchDeptUserTree = ({ url, params }: any) => {
+  console.log('部门账号树', url, params)
+  return get(url, { params })
+}
+
+export const fetchDatasetsPermission = ({ url, params }: any) => {
+  console.log('查询知识库权限', url, params)
+  return get(url, { params })
+}
+
+export const setDatasetsPermission = ({ url, body }: any) => {
+  console.log('配置知识库权限', url, body)
+  return post(url, { body })
+}