Skip to content

Commit c8d901b

Browse files
committed
refactor: use consistent tool ID generation and add automatic permission assignment for tool creators
1 parent 7e3589a commit c8d901b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

apps/tools/serializers/tool.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,9 @@ def import_(self, scope=ToolScope.WORKSPACE):
397397
except Exception as e:
398398
raise AppApiException(1001, _("Unsupported file format"))
399399
tool = tool_instance.tool
400+
tool_id = uuid.uuid7()
400401
tool_model = Tool(
401-
id=uuid.uuid7(),
402+
id=tool_id,
402403
name=tool.get('name'),
403404
desc=tool.get('desc'),
404405
code=tool.get('code'),
@@ -411,6 +412,14 @@ def import_(self, scope=ToolScope.WORKSPACE):
411412
is_active=False
412413
)
413414
tool_model.save()
415+
416+
# 自动授权给创建者
417+
UserResourcePermissionSerializer(data={
418+
'workspace_id': self.data.get('workspace_id'),
419+
'user_id': self.data.get('user_id'),
420+
'auth_target_type': AuthTargetType.TOOL.value
421+
}).auth_resource(str(tool_id))
422+
414423
return True
415424

416425
class IconOperate(serializers.Serializer):

0 commit comments

Comments
 (0)