Skip to content

Commit 4538775

Browse files
committed
Merge branch 'deploy/dev' of https://github.com/langgenius/dify into deploy/dev
2 parents 8082246 + 529393b commit 4538775

File tree

5 files changed

+79
-21
lines changed

5 files changed

+79
-21
lines changed

web/app/components/app/configuration/dataset-config/card-item/item.tsx

+17-14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const Item: FC<ItemProps> = ({
2929
config,
3030
onSave,
3131
onRemove,
32+
readonly,
3233
}) => {
3334
const media = useBreakpoints()
3435
const isMobile = media === MediaType.mobile
@@ -68,26 +69,28 @@ const Item: FC<ItemProps> = ({
6869
<div className='flex items-center h-[18px]'>
6970
<div className='grow text-[13px] font-medium text-gray-800 truncate' title={config.name}>{config.name}</div>
7071
{config.provider === 'external'
71-
? <Badge text={t('dataset.externalTag')}></Badge>
72+
? <Badge text={t('dataset.externalTag') as string} />
7273
: <Badge
7374
text={formatIndexingTechniqueAndMethod(config.indexing_technique, config.retrieval_model_dict?.search_method)}
7475
/>}
7576
</div>
7677
</div>
77-
<div className='hidden rounded-lg group-hover:flex items-center justify-end absolute right-0 top-0 bottom-0 pr-2 w-[124px] bg-gradient-to-r from-white/50 to-white to-50%'>
78-
<div
79-
className='flex items-center justify-center mr-1 w-6 h-6 hover:bg-black/5 rounded-md cursor-pointer'
80-
onClick={() => setShowSettingsModal(true)}
81-
>
82-
<RiEditLine className='w-4 h-4 text-gray-500' />
83-
</div>
84-
<div
85-
className='group/action flex items-center justify-center w-6 h-6 hover:bg-[#FEE4E2] rounded-md cursor-pointer'
86-
onClick={() => onRemove(config.id)}
87-
>
88-
<RiDeleteBinLine className='w-4 h-4 text-gray-500 group-hover/action:text-[#D92D20]' />
78+
{!readonly && (
79+
<div className='hidden rounded-lg group-hover:flex items-center justify-end absolute right-0 top-0 bottom-0 pr-2 w-[124px] bg-gradient-to-r from-white/50 to-white to-50%'>
80+
<div
81+
className='flex items-center justify-center mr-1 w-6 h-6 hover:bg-black/5 rounded-md cursor-pointer'
82+
onClick={() => setShowSettingsModal(true)}
83+
>
84+
<RiEditLine className='w-4 h-4 text-gray-500' />
85+
</div>
86+
<div
87+
className='group/action flex items-center justify-center w-6 h-6 hover:bg-[#FEE4E2] rounded-md cursor-pointer'
88+
onClick={() => onRemove(config.id)}
89+
>
90+
<RiDeleteBinLine className='w-4 h-4 text-gray-500 group-hover/action:text-[#D92D20]' />
91+
</div>
8992
</div>
90-
</div>
93+
)}
9194
<Drawer isOpen={showSettingsModal} onClose={() => setShowSettingsModal(false)} footer={null} mask={isMobile} panelClassname='mt-16 mx-2 sm:mr-2 mb-3 !p-0 !max-w-[640px] rounded-xl'>
9295
<SettingsModal
9396
currentDataset={config}

web/app/components/app/configuration/dataset-config/index.tsx

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22
import type { FC } from 'react'
3-
import React from 'react'
3+
import React, { useMemo } from 'react'
44
import { useTranslation } from 'react-i18next'
55
import { useContext } from 'use-context-selector'
66
import produce from 'immer'
@@ -19,6 +19,8 @@ import {
1919
} from '@/app/components/workflow/nodes/knowledge-retrieval/utils'
2020
import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
2121
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
22+
import { useSelector as useAppContextSelector } from '@/context/app-context'
23+
import { hasEditPermissionForDataset } from '@/utils/permission'
2224

2325
const Icon = (
2426
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -29,6 +31,7 @@ const Icon = (
2931

3032
const DatasetConfig: FC = () => {
3133
const { t } = useTranslation()
34+
const userProfile = useAppContextSelector(s => s.userProfile)
3235
const {
3336
mode,
3437
dataSets: dataSet,
@@ -105,6 +108,20 @@ const DatasetConfig: FC = () => {
105108
setModelConfig(newModelConfig)
106109
}
107110

111+
const formattedDataset = useMemo(() => {
112+
return dataSet.map((item) => {
113+
const datasetConfig = {
114+
createdBy: item.created_by,
115+
partialMemberList: item.partial_member_list as string[],
116+
permission: item.permission,
117+
}
118+
return {
119+
...item,
120+
readonly: !hasEditPermissionForDataset(userProfile?.id as string, datasetConfig),
121+
}
122+
})
123+
}, [dataSet, userProfile?.id])
124+
108125
return (
109126
<FeaturePanel
110127
className='mt-2'
@@ -122,12 +139,13 @@ const DatasetConfig: FC = () => {
122139
{hasData
123140
? (
124141
<div className='flex flex-wrap mt-1 px-3 pb-3 justify-between'>
125-
{dataSet.map(item => (
142+
{formattedDataset.map(item => (
126143
<CardItem
127144
key={item.id}
128145
config={item}
129146
onRemove={onRemove}
130147
onSave={handleSave}
148+
readonly={item.readonly}
131149
/>
132150
))}
133151
</div>

web/app/components/workflow/nodes/knowledge-retrieval/components/dataset-item.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const DatasetItem: FC<Props> = ({
102102
{
103103
payload.provider === 'external' && <Badge
104104
className='group-hover/dataset-item:hidden shrink-0'
105-
text={t('dataset.externalTag')}
105+
text={t('dataset.externalTag') as string}
106106
/>
107107
}
108108

web/app/components/workflow/nodes/knowledge-retrieval/components/dataset-list.tsx

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use client'
22
import type { FC } from 'react'
3-
import React, { useCallback } from 'react'
3+
import React, { useCallback, useMemo } from 'react'
44
import produce from 'immer'
55
import { useTranslation } from 'react-i18next'
66
import Item from './dataset-item'
77
import type { DataSet } from '@/models/datasets'
8+
import { useSelector as useAppContextSelector } from '@/context/app-context'
9+
import { hasEditPermissionForDataset } from '@/utils/permission'
10+
811
type Props = {
912
list: DataSet[]
1013
onChange: (list: DataSet[]) => void
@@ -17,6 +20,7 @@ const DatasetList: FC<Props> = ({
1720
readonly,
1821
}) => {
1922
const { t } = useTranslation()
23+
const userProfile = useAppContextSelector(s => s.userProfile)
2024

2125
const handleRemove = useCallback((index: number) => {
2226
return () => {
@@ -35,17 +39,32 @@ const DatasetList: FC<Props> = ({
3539
onChange(newList)
3640
}
3741
}, [list, onChange])
42+
43+
const formattedList = useMemo(() => {
44+
return list.map((item) => {
45+
const datasetConfig = {
46+
createdBy: item.created_by,
47+
partialMemberList: item.partial_member_list as string[],
48+
permission: item.permission,
49+
}
50+
return {
51+
...item,
52+
readonly: !hasEditPermissionForDataset(userProfile?.id as string, datasetConfig),
53+
}
54+
})
55+
}, [list, userProfile?.id])
56+
3857
return (
3958
<div className='space-y-1'>
40-
{list.length
41-
? list.map((item, index) => {
59+
{formattedList.length
60+
? formattedList.map((item, index) => {
4261
return (
4362
<Item
4463
key={index}
4564
payload={item}
4665
onRemove={handleRemove(index)}
4766
onChange={handleChange(index)}
48-
readonly={readonly}
67+
readonly={readonly || item.readonly}
4968
/>
5069
)
5170
})

web/utils/permission.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { DatasetPermission } from '@/models/datasets'
2+
3+
type DatasetConfig = {
4+
createdBy: string
5+
partialMemberList: string[]
6+
permission: DatasetPermission
7+
}
8+
9+
export const hasEditPermissionForDataset = (userId: string, datasetConfig: DatasetConfig) => {
10+
const { createdBy, partialMemberList, permission } = datasetConfig
11+
if (permission === 'only_me')
12+
return userId === createdBy
13+
if (permission === 'all_team_members')
14+
return true
15+
if (permission === 'partial_members')
16+
return partialMemberList.includes(userId)
17+
return false
18+
}

0 commit comments

Comments
 (0)