Unverified Commit 984c53ec authored by Marius van den Beek's avatar Marius van den Beek Committed by GitHub
Browse files

Merge pull request #18060 from ElectronicBlueberry/fix-comments-lost-on-import

[24.0] Fix comments lost on import
parents 21a57d24 69fb6cee
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -7705,6 +7705,25 @@ class Workflow(Base, Dictifiable, RepresentById):
        for old_step, new_step in zip(self.steps, copied_steps):
            old_step.copy_to(new_step, step_mapping, user=user)
        copied_workflow.steps = copied_steps

        copied_comments = [comment.copy() for comment in self.comments]
        steps_by_id = {s.order_index: s for s in copied_workflow.steps}
        comments_by_id = {c.order_index: c for c in copied_comments}

        # copy comment relationships
        for old_comment, new_comment in zip(self.comments, copied_comments):
            for step_id in [step.order_index for step in old_comment.child_steps]:
                child_step = steps_by_id.get(step_id)
                if child_step:
                    child_step.parent_comment = new_comment

            for comment_id in [comment.order_index for comment in old_comment.child_comments]:
                child_comment = comments_by_id.get(comment_id)
                if child_comment:
                    child_comment.parent_comment = new_comment

        copied_workflow.comments = copied_comments

        return copied_workflow

    @property
@@ -8264,6 +8283,17 @@ class WorkflowComment(Base, RepresentById):
        comment.data = dict.get("data", None)
        return comment

    def copy(self):
        comment = WorkflowComment()
        comment.order_index = self.order_index
        comment.type = self.type
        comment.position = self.position
        comment.size = self.size
        comment.color = self.color
        comment.data = self.data

        return comment


class StoredWorkflowUserShareAssociation(Base, UserShareAssociation):
    __tablename__ = "stored_workflow_user_share_connection"