fix: After setting the function library to private, the workflow used should report an error stating that the current function is not authorized to be used (#2742)

This commit is contained in:
shaohuzhang1 2025-03-31 13:58:38 +08:00 committed by GitHub
parent cb104cc211
commit b3feb243d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 69 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import time
from typing import Dict
from django.db.models import QuerySet
from django.utils.translation import gettext as _
from application.flow.i_step_node import NodeResult
from application.flow.step_node.function_lib_node.i_function_lib_node import IFunctionLibNode
@ -39,7 +40,7 @@ def get_field_value(debug_field_list, name, is_required):
if len(result) > 0:
return result[-1]['value']
if is_required:
raise AppApiException(500, f"{name}字段未设置值")
raise AppApiException(500, _('Field: {name} No value set').format(name=name))
return None
@ -55,9 +56,12 @@ def valid_reference_value(_type, value, name):
elif _type == 'string':
instance_type = str
else:
raise Exception(500, f'字段:{name}类型:{_type} 不支持的类型')
raise Exception(_('Field: {name} Type: {_type} Value: {value} Unsupported types').format(name=name,
_type=_type))
if not isinstance(value, instance_type):
raise Exception(f'字段:{name}类型:{_type}值:{value}类型错误')
raise Exception(
_('Field: {name} Type: {_type} Value: {value} Type error').format(name=name, _type=_type,
value=value))
def convert_value(name: str, value, _type, is_required, source, node):
@ -84,15 +88,26 @@ def convert_value(name: str, value, _type, is_required, source, node):
v = json.loads(value)
if isinstance(v, dict):
return v
raise Exception("类型错误")
raise Exception(_('type error'))
if _type == 'array':
v = json.loads(value)
if isinstance(v, list):
return v
raise Exception("类型错误")
raise Exception(_('type error'))
return value
except Exception as e:
raise Exception(f'字段:{name}类型:{_type}值:{value}类型错误')
raise Exception(
_('Field: {name} Type: {_type} Value: {value} Type error').format(name=name, _type=_type,
value=value))
def valid_function(function_lib, user_id):
if function_lib is None:
raise Exception(_('Function does not exist'))
if function_lib.permission_type == 'PRIVATE' and str(function_lib.user_id) != str(user_id):
raise Exception(_('No permission to use this function {name}').format(name=function_lib.name))
if not function_lib.is_active:
raise Exception(_('Function {name} is unavailable').format(name=function_lib.name))
class BaseFunctionLibNodeNode(IFunctionLibNode):
@ -102,8 +117,7 @@ class BaseFunctionLibNodeNode(IFunctionLibNode):
def execute(self, function_lib_id, input_field_list, **kwargs) -> NodeResult:
function_lib = QuerySet(FunctionLib).filter(id=function_lib_id).first()
if not function_lib.is_active:
raise Exception(f'函数:{function_lib.name} 不可用')
valid_function(function_lib, self.flow_params_serializer.data.get('user_id'))
params = {field.get('name'): convert_value(field.get('name'), field.get('value'), field.get('type'),
field.get('is_required'),
field.get('source'), self)

View File

@ -7472,4 +7472,19 @@ msgid "Add internal function"
msgstr ""
msgid "Batch generate related documents"
msgstr "Batch generate related problems"
msgstr "Batch generate related problems"
msgid "No permission to use this function {name}"
msgstr ""
msgid "Function {name} is unavailable"
msgstr ""
msgid "Field: {name} Type: {_type} Value: {value} Type error"
msgstr ""
msgid "Field: {name} Type: {_type} Value: {value} Unsupported types"
msgstr ""
msgid "Field: {name} No value set"
msgstr ""

View File

@ -7636,3 +7636,18 @@ msgstr "添加内置函数"
msgid "Batch generate related documents"
msgstr "批量生成问题"
msgid "No permission to use this function {name}"
msgstr "无权使用此模型 {name}"
msgid "Function {name} is unavailable"
msgstr "函数{name} 不可用"
msgid "Field: {name} Type: {_type} Value: {value} Type error"
msgstr "字段: {name} 类型: {_type} 值: {value} 类型错误"
msgid "Field: {name} Type: {_type} Value: {value} Unsupported types"
msgstr "字段: {name} 类型: {_type} 值: {value} 不支持的类型"
msgid "Field: {name} No value set"
msgstr "字段: {name} 未设置值"

View File

@ -7645,4 +7645,19 @@ msgid "Add internal function"
msgstr "添加內寘函數"
msgid "Batch generate related documents"
msgstr "批量生成问题"
msgstr "批量生成问题"
msgid "No permission to use this function {name}"
msgstr "無權使用此模型{name}"
msgid "Function {name} is unavailable"
msgstr "函數{name} 不可用"
msgid "Field: {name} Type: {_type} Value: {value} Type error"
msgstr "欄位: {name} 類型: {_type} 值: {value} 類型錯誤"
msgid "Field: {name} Type: {_type} Value: {value} Unsupported types"
msgstr "欄位: {name} 類型: {_type} 值: {value} 不支持的類型"
msgid "Field: {name} No value set"
msgstr "欄位: {name} 未設定值"