Unverified Commit 4d99c689 authored by Jyong's avatar Jyong Committed by GitHub

prohibit enable and disable function when segment is not completed (#1954)

Co-authored-by: 's avatarjyong <jyong@dify.ai>
Co-authored-by: 's avatarJoel <iamjoel007@gmail.com>
parent 28b26f67
...@@ -156,6 +156,9 @@ class DatasetDocumentSegmentApi(Resource): ...@@ -156,6 +156,9 @@ class DatasetDocumentSegmentApi(Resource):
if not segment: if not segment:
raise NotFound('Segment not found.') raise NotFound('Segment not found.')
if segment.status != 'completed':
raise NotFound('Segment is not completed, enable or disable function is not allowed')
document_indexing_cache_key = 'document_{}_indexing'.format(segment.document_id) document_indexing_cache_key = 'document_{}_indexing'.format(segment.document_id)
cache_result = redis_client.get(document_indexing_cache_key) cache_result = redis_client.get(document_indexing_cache_key)
if cache_result is not None: if cache_result is not None:
......
...@@ -27,7 +27,7 @@ def disable_segment_from_index_task(segment_id: str): ...@@ -27,7 +27,7 @@ def disable_segment_from_index_task(segment_id: str):
raise NotFound('Segment not found') raise NotFound('Segment not found')
if segment.status != 'completed': if segment.status != 'completed':
return raise NotFound('Segment is not completed , disable action is not allowed.')
indexing_cache_key = 'segment_{}_indexing'.format(segment.id) indexing_cache_key = 'segment_{}_indexing'.format(segment.id)
......
...@@ -29,7 +29,7 @@ def enable_segment_to_index_task(segment_id: str): ...@@ -29,7 +29,7 @@ def enable_segment_to_index_task(segment_id: str):
raise NotFound('Segment not found') raise NotFound('Segment not found')
if segment.status != 'completed': if segment.status != 'completed':
return raise NotFound('Segment is not completed, enable action is not allowed.')
indexing_cache_key = 'segment_{}_indexing'.format(segment.id) indexing_cache_key = 'segment_{}_indexing'.format(segment.id)
......
...@@ -128,7 +128,7 @@ const SegmentCard: FC<ISegmentCardProps> = ({ ...@@ -128,7 +128,7 @@ const SegmentCard: FC<ISegmentCardProps> = ({
> >
<Switch <Switch
size='md' size='md'
disabled={archived} disabled={archived || detail.status !== 'completed'}
defaultValue={enabled} defaultValue={enabled}
onChange={async (val) => { onChange={async (val) => {
await onChangeSwitch?.(id, val) await onChangeSwitch?.(id, val)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment