@@ -58,6 +58,11 @@ type (
|
|||||||
Standards []string `json:"standards"`
|
Standards []string `json:"standards"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
Tasks []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
TimeEstimate int `json:"time-estimate"`
|
||||||
|
} `json:"tasks"`
|
||||||
} `json:"controls"`
|
} `json:"controls"`
|
||||||
} `json:"framework"`
|
} `json:"framework"`
|
||||||
}
|
}
|
||||||
@@ -207,6 +212,7 @@ func (s FrameworkService) Import(
|
|||||||
}
|
}
|
||||||
|
|
||||||
importedControls := coredata.Controls{}
|
importedControls := coredata.Controls{}
|
||||||
|
importedTasks := coredata.Tasks{}
|
||||||
for _, control := range req.Data.Framework.Controls {
|
for _, control := range req.Data.Framework.Controls {
|
||||||
controlID, err := gid.NewGID(organizationID.TenantID(), coredata.ControlEntityType)
|
controlID, err := gid.NewGID(organizationID.TenantID(), coredata.ControlEntityType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -228,6 +234,25 @@ func (s FrameworkService) Import(
|
|||||||
}
|
}
|
||||||
|
|
||||||
importedControls = append(importedControls, importedControl)
|
importedControls = append(importedControls, importedControl)
|
||||||
|
|
||||||
|
for _, task := range control.Tasks {
|
||||||
|
taskID, err := gid.NewGID(organizationID.TenantID(), coredata.TaskEntityType)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot create global id: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
importedTasks = append(importedTasks, &coredata.Task{
|
||||||
|
ID: taskID,
|
||||||
|
ControlID: controlID,
|
||||||
|
Name: task.Name,
|
||||||
|
TimeEstimate: time.Duration(task.TimeEstimate) * time.Second,
|
||||||
|
State: coredata.TaskStateTodo,
|
||||||
|
Description: task.Description,
|
||||||
|
ContentRef: "",
|
||||||
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.svc.pg.WithTx(
|
err = s.svc.pg.WithTx(
|
||||||
@@ -245,6 +270,12 @@ func (s FrameworkService) Import(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, importedTask := range importedTasks {
|
||||||
|
if err := importedTask.Insert(ctx, tx, s.svc.scope); err != nil {
|
||||||
|
return fmt.Errorf("cannot insert task: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user