Skip to content

Commit 311c3f8

Browse files
committed
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
1 parent 7a99c78 commit 311c3f8

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
lines changed

apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Dict
1212

1313
from django.db.models import QuerySet
14+
from django.utils.translation import gettext as _
1415

1516
from application.flow.i_step_node import NodeResult
1617
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):
3940
if len(result) > 0:
4041
return result[-1]['value']
4142
if is_required:
42-
raise AppApiException(500, f"{name}字段未设置值")
43+
raise AppApiException(500, _('Field: {name} No value set').format(name=name))
4344
return None
4445

4546

@@ -55,9 +56,12 @@ def valid_reference_value(_type, value, name):
5556
elif _type == 'string':
5657
instance_type = str
5758
else:
58-
raise Exception(500, f'字段:{name}类型:{_type} 不支持的类型')
59+
raise Exception(_('Field: {name} Type: {_type} Value: {value} Unsupported types').format(name=name,
60+
_type=_type))
5961
if not isinstance(value, instance_type):
60-
raise Exception(f'字段:{name}类型:{_type}值:{value}类型错误')
62+
raise Exception(
63+
_('Field: {name} Type: {_type} Value: {value} Type error').format(name=name, _type=_type,
64+
value=value))
6165

6266

6367
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):
8488
v = json.loads(value)
8589
if isinstance(v, dict):
8690
return v
87-
raise Exception("类型错误")
91+
raise Exception(_('type error'))
8892
if _type == 'array':
8993
v = json.loads(value)
9094
if isinstance(v, list):
9195
return v
92-
raise Exception("类型错误")
96+
raise Exception(_('type error'))
9397
return value
9498
except Exception as e:
95-
raise Exception(f'字段:{name}类型:{_type}值:{value}类型错误')
99+
raise Exception(
100+
_('Field: {name} Type: {_type} Value: {value} Type error').format(name=name, _type=_type,
101+
value=value))
102+
103+
104+
def valid_function(function_lib, user_id):
105+
if function_lib is None:
106+
raise Exception(_('Function does not exist'))
107+
if function_lib.permission_type == 'PRIVATE' and str(function_lib.user_id) != str(user_id):
108+
raise Exception(_('No permission to use this function {name}').format(name=function_lib.name))
109+
if not function_lib.is_active:
110+
raise Exception(_('Function {name} is unavailable').format(name=function_lib.name))
96111

97112

98113
class BaseFunctionLibNodeNode(IFunctionLibNode):
@@ -102,8 +117,7 @@ def save_context(self, details, workflow_manage):
102117

103118
def execute(self, function_lib_id, input_field_list, **kwargs) -> NodeResult:
104119
function_lib = QuerySet(FunctionLib).filter(id=function_lib_id).first()
105-
if not function_lib.is_active:
106-
raise Exception(f'函数:{function_lib.name} 不可用')
120+
valid_function(function_lib, self.flow_params_serializer.data.get('user_id'))
107121
params = {field.get('name'): convert_value(field.get('name'), field.get('value'), field.get('type'),
108122
field.get('is_required'),
109123
field.get('source'), self)

apps/locales/en_US/LC_MESSAGES/django.po

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7472,4 +7472,19 @@ msgid "Add internal function"
74727472
msgstr ""
74737473

74747474
msgid "Batch generate related documents"
7475-
msgstr "Batch generate related problems"
7475+
msgstr "Batch generate related problems"
7476+
7477+
msgid "No permission to use this function {name}"
7478+
msgstr ""
7479+
7480+
msgid "Function {name} is unavailable"
7481+
msgstr ""
7482+
7483+
msgid "Field: {name} Type: {_type} Value: {value} Type error"
7484+
msgstr ""
7485+
7486+
msgid "Field: {name} Type: {_type} Value: {value} Unsupported types"
7487+
msgstr ""
7488+
7489+
msgid "Field: {name} No value set"
7490+
msgstr ""

apps/locales/zh_CN/LC_MESSAGES/django.po

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7636,3 +7636,18 @@ msgstr "添加内置函数"
76367636

76377637
msgid "Batch generate related documents"
76387638
msgstr "批量生成问题"
7639+
7640+
msgid "No permission to use this function {name}"
7641+
msgstr "无权使用此模型 {name}"
7642+
7643+
msgid "Function {name} is unavailable"
7644+
msgstr "函数{name} 不可用"
7645+
7646+
msgid "Field: {name} Type: {_type} Value: {value} Type error"
7647+
msgstr "字段: {name} 类型: {_type} 值: {value} 类型错误"
7648+
7649+
msgid "Field: {name} Type: {_type} Value: {value} Unsupported types"
7650+
msgstr "字段: {name} 类型: {_type} 值: {value} 不支持的类型"
7651+
7652+
msgid "Field: {name} No value set"
7653+
msgstr "字段: {name} 未设置值"

apps/locales/zh_Hant/LC_MESSAGES/django.po

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7645,4 +7645,19 @@ msgid "Add internal function"
76457645
msgstr "添加內寘函數"
76467646

76477647
msgid "Batch generate related documents"
7648-
msgstr "批量生成问题"
7648+
msgstr "批量生成问题"
7649+
7650+
msgid "No permission to use this function {name}"
7651+
msgstr "無權使用此模型{name}"
7652+
7653+
msgid "Function {name} is unavailable"
7654+
msgstr "函數{name} 不可用"
7655+
7656+
msgid "Field: {name} Type: {_type} Value: {value} Type error"
7657+
msgstr "欄位: {name} 類型: {_type} 值: {value} 類型錯誤"
7658+
7659+
msgid "Field: {name} Type: {_type} Value: {value} Unsupported types"
7660+
msgstr "欄位: {name} 類型: {_type} 值: {value} 不支持的類型"
7661+
7662+
msgid "Field: {name} No value set"
7663+
msgstr "欄位: {name} 未設定值"

0 commit comments

Comments
 (0)