|
|
|
|
|
|
|
|
raise NotFound("Document not found.") |
|
|
raise NotFound("Document not found.") |
|
|
segment_ids = request.args.getlist("segment_id") |
|
|
segment_ids = request.args.getlist("segment_id") |
|
|
|
|
|
|
|
|
# The role of the current user in the ta table must be admin or owner |
|
|
|
|
|
if not current_user.is_editor: |
|
|
|
|
|
|
|
|
# The role of the current user in the ta table must be admin, owner, dataset_operator, or editor |
|
|
|
|
|
if not current_user.is_dataset_editor: |
|
|
raise Forbidden() |
|
|
raise Forbidden() |
|
|
try: |
|
|
try: |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
|
|
|
|
|
|
raise NotFound("Document not found.") |
|
|
raise NotFound("Document not found.") |
|
|
# check user's model setting |
|
|
# check user's model setting |
|
|
DatasetService.check_dataset_model_setting(dataset) |
|
|
DatasetService.check_dataset_model_setting(dataset) |
|
|
# The role of the current user in the ta table must be admin, owner, or editor |
|
|
|
|
|
if not current_user.is_editor: |
|
|
|
|
|
|
|
|
# The role of the current user in the ta table must be admin, owner, dataset_operator, or editor |
|
|
|
|
|
if not current_user.is_dataset_editor: |
|
|
raise Forbidden() |
|
|
raise Forbidden() |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
|
|
|
|
|
|
document = DocumentService.get_document(dataset_id, document_id) |
|
|
document = DocumentService.get_document(dataset_id, document_id) |
|
|
if not document: |
|
|
if not document: |
|
|
raise NotFound("Document not found.") |
|
|
raise NotFound("Document not found.") |
|
|
if not current_user.is_editor: |
|
|
|
|
|
|
|
|
if not current_user.is_dataset_editor: |
|
|
raise Forbidden() |
|
|
raise Forbidden() |
|
|
# check embedding model setting |
|
|
# check embedding model setting |
|
|
if dataset.indexing_technique == "high_quality": |
|
|
if dataset.indexing_technique == "high_quality": |
|
|
|
|
|
|
|
|
).first() |
|
|
).first() |
|
|
if not segment: |
|
|
if not segment: |
|
|
raise NotFound("Segment not found.") |
|
|
raise NotFound("Segment not found.") |
|
|
# The role of the current user in the ta table must be admin, owner, or editor |
|
|
|
|
|
if not current_user.is_editor: |
|
|
|
|
|
|
|
|
# The role of the current user in the ta table must be admin, owner, dataset_operator, or editor |
|
|
|
|
|
if not current_user.is_dataset_editor: |
|
|
raise Forbidden() |
|
|
raise Forbidden() |
|
|
try: |
|
|
try: |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
|
|
|
|
|
|
).first() |
|
|
).first() |
|
|
if not segment: |
|
|
if not segment: |
|
|
raise NotFound("Segment not found.") |
|
|
raise NotFound("Segment not found.") |
|
|
# The role of the current user in the ta table must be admin or owner |
|
|
|
|
|
if not current_user.is_editor: |
|
|
|
|
|
|
|
|
# The role of the current user in the ta table must be admin, owner, dataset_operator, or editor |
|
|
|
|
|
if not current_user.is_dataset_editor: |
|
|
raise Forbidden() |
|
|
raise Forbidden() |
|
|
try: |
|
|
try: |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
|
|
|
|
|
|
).first() |
|
|
).first() |
|
|
if not segment: |
|
|
if not segment: |
|
|
raise NotFound("Segment not found.") |
|
|
raise NotFound("Segment not found.") |
|
|
if not current_user.is_editor: |
|
|
|
|
|
|
|
|
if not current_user.is_dataset_editor: |
|
|
raise Forbidden() |
|
|
raise Forbidden() |
|
|
# check embedding model setting |
|
|
# check embedding model setting |
|
|
if dataset.indexing_technique == "high_quality": |
|
|
if dataset.indexing_technique == "high_quality": |
|
|
|
|
|
|
|
|
).first() |
|
|
).first() |
|
|
if not segment: |
|
|
if not segment: |
|
|
raise NotFound("Segment not found.") |
|
|
raise NotFound("Segment not found.") |
|
|
# The role of the current user in the ta table must be admin, owner, or editor |
|
|
|
|
|
if not current_user.is_editor: |
|
|
|
|
|
|
|
|
# The role of the current user in the ta table must be admin, owner, dataset_operator, or editor |
|
|
|
|
|
if not current_user.is_dataset_editor: |
|
|
raise Forbidden() |
|
|
raise Forbidden() |
|
|
try: |
|
|
try: |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
|
|
|
|
|
|
).first() |
|
|
).first() |
|
|
if not child_chunk: |
|
|
if not child_chunk: |
|
|
raise NotFound("Child chunk not found.") |
|
|
raise NotFound("Child chunk not found.") |
|
|
# The role of the current user in the ta table must be admin or owner |
|
|
|
|
|
if not current_user.is_editor: |
|
|
|
|
|
|
|
|
# The role of the current user in the ta table must be admin, owner, dataset_operator, or editor |
|
|
|
|
|
if not current_user.is_dataset_editor: |
|
|
raise Forbidden() |
|
|
raise Forbidden() |
|
|
try: |
|
|
try: |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
|
|
|
|
|
|
).first() |
|
|
).first() |
|
|
if not child_chunk: |
|
|
if not child_chunk: |
|
|
raise NotFound("Child chunk not found.") |
|
|
raise NotFound("Child chunk not found.") |
|
|
# The role of the current user in the ta table must be admin or owner |
|
|
|
|
|
if not current_user.is_editor: |
|
|
|
|
|
|
|
|
# The role of the current user in the ta table must be admin, owner, dataset_operator, or editor |
|
|
|
|
|
if not current_user.is_dataset_editor: |
|
|
raise Forbidden() |
|
|
raise Forbidden() |
|
|
try: |
|
|
try: |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |
|
|
DatasetService.check_dataset_permission(dataset, current_user) |