diff --git a/apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py b/apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py index 506b1526c..d21424f75 100644 --- a/apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py +++ b/apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py @@ -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) diff --git a/apps/locales/en_US/LC_MESSAGES/django.po b/apps/locales/en_US/LC_MESSAGES/django.po index faf837bf7..f3cfb56c8 100644 --- a/apps/locales/en_US/LC_MESSAGES/django.po +++ b/apps/locales/en_US/LC_MESSAGES/django.po @@ -7472,4 +7472,19 @@ msgid "Add internal function" msgstr "" msgid "Batch generate related documents" -msgstr "Batch generate related problems" \ No newline at end of file +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 "" \ No newline at end of file diff --git a/apps/locales/zh_CN/LC_MESSAGES/django.po b/apps/locales/zh_CN/LC_MESSAGES/django.po index 3899371e9..9efa3b2fb 100644 --- a/apps/locales/zh_CN/LC_MESSAGES/django.po +++ b/apps/locales/zh_CN/LC_MESSAGES/django.po @@ -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} 未设置值" \ No newline at end of file diff --git a/apps/locales/zh_Hant/LC_MESSAGES/django.po b/apps/locales/zh_Hant/LC_MESSAGES/django.po index ec9be33f1..6ab673aa4 100644 --- a/apps/locales/zh_Hant/LC_MESSAGES/django.po +++ b/apps/locales/zh_Hant/LC_MESSAGES/django.po @@ -7645,4 +7645,19 @@ msgid "Add internal function" msgstr "添加內寘函數" msgid "Batch generate related documents" -msgstr "批量生成问题" \ No newline at end of file +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} 未設定值" \ No newline at end of file