Render mermaid diagram per risk assessment scope

Each scope card now shows a flowchart of its nodes, processes, and
threats, with a distinct shape per type: stadium for entities,
hexagon for boundaries, rectangle for assets, cylinder for data, and
a red hexagon for threats attached via dashed edges to their process
target. The Mermaid source is built on the backend and exposed as a
new `mermaid` field on RiskAssessmentScope; the frontend just renders
it via @probo/ui's MermaidDiagram and shows a copy button + legend.

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2026-05-12 17:31:35 +02:00
parent b9262b5150
commit eedfdcecc8
11 changed files with 714 additions and 5 deletions

View File

@@ -228,6 +228,8 @@ type RiskAssessmentScope implements Node {
orderBy: RiskAssessmentScenarioOrder
): RiskAssessmentScenarioConnection @goField(forceResolver: true)
mermaidChart: String! @goField(forceResolver: true)
createdAt: Datetime!
updatedAt: Datetime!
}

View File

@@ -854,6 +854,20 @@ func (r *riskAssessmentScopeResolver) Scenarios(ctx context.Context, obj *types.
return types.NewRiskAssessmentScenarioConnection(p, r, obj.ID), nil
}
// MermaidChart is the resolver for the mermaidChart field.
func (r *riskAssessmentScopeResolver) MermaidChart(ctx context.Context, obj *types.RiskAssessmentScope) (string, error) {
if err := r.authorize(ctx, obj.ID, probo.ActionRiskAssessmentScopeGet); err != nil {
return "", err
}
scope := coredata.NewScopeFromObjectID(obj.ID)
chart, err := r.riskManagement.BuildScopeMermaidChart(ctx, scope, obj.ID)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot build risk assessment scope mermaid chart", log.Error(err))
return "", gqlutils.Internal(ctx)
}
return chart, nil
}
// TotalCount is the resolver for the totalCount field.
func (r *riskAssessmentScopeConnectionResolver) TotalCount(ctx context.Context, obj *types.RiskAssessmentScopeConnection) (*int, error) {
if err := r.authorize(ctx, obj.ParentID, probo.ActionRiskAssessmentScopeList); err != nil {