fix(knowledge_base): Unchecked metadata name length (#21454)
Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
@@ -19,6 +19,10 @@ from services.entities.knowledge_entities.knowledge_entities import (
|
|||||||
class MetadataService:
|
class MetadataService:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_metadata(dataset_id: str, metadata_args: MetadataArgs) -> DatasetMetadata:
|
def create_metadata(dataset_id: str, metadata_args: MetadataArgs) -> DatasetMetadata:
|
||||||
|
# check if metadata name is too long
|
||||||
|
if len(metadata_args.name) > 255:
|
||||||
|
raise ValueError("Metadata name cannot exceed 255 characters.")
|
||||||
|
|
||||||
# check if metadata name already exists
|
# check if metadata name already exists
|
||||||
if (
|
if (
|
||||||
db.session.query(DatasetMetadata)
|
db.session.query(DatasetMetadata)
|
||||||
@@ -42,6 +46,10 @@ class MetadataService:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_metadata_name(dataset_id: str, metadata_id: str, name: str) -> DatasetMetadata: # type: ignore
|
def update_metadata_name(dataset_id: str, metadata_id: str, name: str) -> DatasetMetadata: # type: ignore
|
||||||
|
# check if metadata name is too long
|
||||||
|
if len(name) > 255:
|
||||||
|
raise ValueError("Metadata name cannot exceed 255 characters.")
|
||||||
|
|
||||||
lock_key = f"dataset_metadata_lock_{dataset_id}"
|
lock_key = f"dataset_metadata_lock_{dataset_id}"
|
||||||
# check if metadata name already exists
|
# check if metadata name already exists
|
||||||
if (
|
if (
|
||||||
|
@@ -18,6 +18,12 @@ const useCheckMetadataName = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name.length > 255) {
|
||||||
|
return {
|
||||||
|
errorMsg: t(`${i18nPrefix}.tooLong`, { max: 255 }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
errorMsg: '',
|
errorMsg: '',
|
||||||
}
|
}
|
||||||
|
@@ -183,6 +183,7 @@ const translation = {
|
|||||||
checkName: {
|
checkName: {
|
||||||
empty: 'Metadata name cannot be empty',
|
empty: 'Metadata name cannot be empty',
|
||||||
invalid: 'Metadata name can only contain lowercase letters, numbers, and underscores and must start with a lowercase letter',
|
invalid: 'Metadata name can only contain lowercase letters, numbers, and underscores and must start with a lowercase letter',
|
||||||
|
tooLong: 'Metadata name cannot exceed {{max}} characters',
|
||||||
},
|
},
|
||||||
batchEditMetadata: {
|
batchEditMetadata: {
|
||||||
editMetadata: 'Edit Metadata',
|
editMetadata: 'Edit Metadata',
|
||||||
|
Reference in New Issue
Block a user