From 2542efe6e19448f2dddebac585ca86551eb5c721 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Thu, 26 Dec 2024 19:23:48 +0800 Subject: [PATCH] fix: add properties to retrieve created by account and end user in WorkflowRun model Signed-off-by: -LAN- --- api/models/workflow.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/models/workflow.py b/api/models/workflow.py index 32a0860b77bbea..8642df8adb55c5 100644 --- a/api/models/workflow.py +++ b/api/models/workflow.py @@ -414,6 +414,18 @@ class WorkflowRun(db.Model): # type: ignore[name-defined] finished_at = db.Column(db.DateTime) exceptions_count = db.Column(db.Integer, server_default=db.text("0")) + @property + def created_by_account(self): + created_by_role = CreatedByRole(self.created_by_role) + return db.session.get(Account, self.created_by) if created_by_role == CreatedByRole.ACCOUNT else None + + @property + def created_by_end_user(self): + from models.model import EndUser + + created_by_role = CreatedByRole(self.created_by_role) + return db.session.get(EndUser, self.created_by) if created_by_role == CreatedByRole.END_USER else None + @property def graph_dict(self): return json.loads(self.graph) if self.graph else {}