|
8 | 8 | from django.db.models import QuerySet |
9 | 9 | from django.utils.translation import gettext_lazy as _ |
10 | 10 | from rest_framework import serializers |
11 | | - |
| 11 | +from django.db.models.query_utils import Q |
12 | 12 | from common.config.embedding_config import ModelManage |
13 | 13 | from common.database_model_manage.database_model_manage import DatabaseModelManage |
14 | 14 | from common.exception.app_exception import AppApiException |
@@ -413,16 +413,26 @@ def save_model_params_form(self, model_params_form, with_valid=True): |
413 | 413 |
|
414 | 414 |
|
415 | 415 | def get_authorized_tool(tool_query_set, workspace_id, model_workspace_authorization): |
| 416 | + # 对所有工作空间拉黑的工具 |
| 417 | + non_auths = QuerySet(model_workspace_authorization).filter( |
| 418 | + Q(workspace_id='None') & Q(authentication_type='WHITE_LIST') |
| 419 | + ).values_list('model_id', flat=True) |
| 420 | + # 授权给所有工作空间的工具 |
| 421 | + all_auths = QuerySet(model_workspace_authorization).filter( |
| 422 | + Q(workspace_id='None') & Q(authentication_type='BLACK_LIST') |
| 423 | + ).values_list('model_id', flat=True) |
| 424 | + # 查询白名单授权的工具 |
416 | 425 | white_authorized_tool_ids = QuerySet(model_workspace_authorization).filter( |
417 | 426 | workspace_id=workspace_id, authentication_type='WHITE_LIST' |
418 | 427 | ).values_list('model_id', flat=True) |
| 428 | + # 查询黑名单授权的工具 |
419 | 429 | black_authorized_tool_ids = QuerySet(model_workspace_authorization).filter( |
420 | 430 | workspace_id=workspace_id, authentication_type='BLACK_LIST' |
421 | 431 | ).values_list('model_id', flat=True) |
422 | 432 | tool_query_set = tool_query_set.filter( |
423 | | - id__in=white_authorized_tool_ids |
| 433 | + id__in=list(white_authorized_tool_ids) + list(all_auths) |
424 | 434 | ).exclude( |
425 | | - id__in=black_authorized_tool_ids |
| 435 | + id__in=list(black_authorized_tool_ids) + list(non_auths) |
426 | 436 | ) |
427 | 437 | return tool_query_set |
428 | 438 |
|
|
0 commit comments