Add risk snapshots

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-09-02 18:52:07 +02:00
parent 781026d3e7
commit 16ced9638d
22 changed files with 639 additions and 253 deletions

View File

@@ -1100,6 +1100,7 @@ input MeasureFilter {
input RiskFilter {
query: String
snapshotId: ID
}
input PeopleFilter {
@@ -1236,7 +1237,7 @@ type Organization implements Node {
last: Int
before: CursorKey
orderBy: RiskOrder
filter: RiskFilter
filter: RiskFilter = { snapshotId: null }
): RiskConnection! @goField(forceResolver: true)
tasks(
@@ -1664,6 +1665,7 @@ type Document implements Node {
type Risk implements Node {
id: ID!
snapshotId: ID
name: String!
description: String!
category: String!

View File

@@ -1027,6 +1027,7 @@ type ComplexityRoot struct {
ResidualImpact func(childComplexity int) int
ResidualLikelihood func(childComplexity int) int
ResidualRiskScore func(childComplexity int) int
SnapshotID func(childComplexity int) int
Treatment func(childComplexity int) int
UpdatedAt func(childComplexity int) int
}
@@ -6224,6 +6225,13 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
return e.complexity.Risk.ResidualRiskScore(childComplexity), true
case "Risk.snapshotId":
if e.complexity.Risk.SnapshotID == nil {
break
}
return e.complexity.Risk.SnapshotID(childComplexity), true
case "Risk.treatment":
if e.complexity.Risk.Treatment == nil {
break
@@ -9061,6 +9069,7 @@ input MeasureFilter {
input RiskFilter {
query: String
snapshotId: ID
}
input PeopleFilter {
@@ -9197,7 +9206,7 @@ type Organization implements Node {
last: Int
before: CursorKey
orderBy: RiskOrder
filter: RiskFilter
filter: RiskFilter = { snapshotId: null }
): RiskConnection! @goField(forceResolver: true)
tasks(
@@ -9625,6 +9634,7 @@ type Document implements Node {
type Risk implements Node {
id: ID!
snapshotId: ID
name: String!
description: String!
category: String!
@@ -45984,6 +45994,47 @@ func (ec *executionContext) fieldContext_Risk_id(_ context.Context, field graphq
return fc, nil
}
func (ec *executionContext) _Risk_snapshotId(ctx context.Context, field graphql.CollectedField, obj *types.Risk) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Risk_snapshotId(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
ctx = rctx // use context from middleware stack in children
return obj.SnapshotID, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
return graphql.Null
}
res := resTmp.(*gid.GID)
fc.Result = res
return ec.marshalOID2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋgidᚐGID(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Risk_snapshotId(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Risk",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type ID does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _Risk_name(ctx context.Context, field graphql.CollectedField, obj *types.Risk) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Risk_name(ctx, field)
if err != nil {
@@ -47135,6 +47186,8 @@ func (ec *executionContext) fieldContext_RiskEdge_node(_ context.Context, field
switch field.Name {
case "id":
return ec.fieldContext_Risk_id(ctx, field)
case "snapshotId":
return ec.fieldContext_Risk_snapshotId(ctx, field)
case "name":
return ec.fieldContext_Risk_name(ctx, field)
case "description":
@@ -51015,6 +51068,8 @@ func (ec *executionContext) fieldContext_UpdateRiskPayload_risk(_ context.Contex
switch field.Name {
case "id":
return ec.fieldContext_Risk_id(ctx, field)
case "snapshotId":
return ec.fieldContext_Risk_snapshotId(ctx, field)
case "name":
return ec.fieldContext_Risk_name(ctx, field)
case "description":
@@ -63958,7 +64013,7 @@ func (ec *executionContext) unmarshalInputRiskFilter(ctx context.Context, obj an
asMap[k] = v
}
fieldsInOrder := [...]string{"query"}
fieldsInOrder := [...]string{"query", "snapshotId"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
@@ -63972,6 +64027,13 @@ func (ec *executionContext) unmarshalInputRiskFilter(ctx context.Context, obj an
return it, err
}
it.Query = data
case "snapshotId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("snapshotId"))
data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.SnapshotID = data
}
}
@@ -76125,6 +76187,8 @@ func (ec *executionContext) _Risk(ctx context.Context, sel ast.SelectionSet, obj
if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1)
}
case "snapshotId":
out.Values[i] = ec._Risk_snapshotId(ctx, field, obj)
case "name":
out.Values[i] = ec._Risk_name(ctx, field, obj)
if out.Values[i] == graphql.Null {

View File

@@ -67,6 +67,7 @@ func NewRisk(r *coredata.Risk) *Risk {
return &Risk{
ID: r.ID,
Name: r.Name,
SnapshotID: r.SnapshotID,
Description: r.Description,
Treatment: r.Treatment,
InherentLikelihood: r.InherentLikelihood,

View File

@@ -1336,6 +1336,7 @@ type RequestSignaturePayload struct {
type Risk struct {
ID gid.GID `json:"id"`
SnapshotID *gid.GID `json:"snapshotId,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"`
@@ -1365,7 +1366,8 @@ type RiskEdge struct {
}
type RiskFilter struct {
Query *string `json:"query,omitempty"`
Query *string `json:"query,omitempty"`
SnapshotID *gid.GID `json:"snapshotId,omitempty"`
}
type SendSigningNotificationsInput struct {

View File

@@ -1034,9 +1034,9 @@ func (r *measureResolver) Risks(ctx context.Context, obj *types.Measure, first *
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
var riskFilter = coredata.NewRiskFilter(nil)
var riskFilter = coredata.NewRiskFilter(nil, nil)
if filter != nil {
riskFilter = coredata.NewRiskFilter(filter.Query)
riskFilter = coredata.NewRiskFilter(filter.Query, &filter.SnapshotID)
}
page, err := prb.Risks.ListForMeasureID(ctx, obj.ID, cursor, riskFilter)
@@ -3595,9 +3595,9 @@ func (r *organizationResolver) Risks(ctx context.Context, obj *types.Organizatio
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
var riskFilter = coredata.NewRiskFilter(nil)
var riskFilter = coredata.NewRiskFilter(nil, nil)
if filter != nil {
riskFilter = coredata.NewRiskFilter(filter.Query)
riskFilter = coredata.NewRiskFilter(filter.Query, &filter.SnapshotID)
}
page, err := prb.Risks.ListForOrganizationID(ctx, obj.ID, cursor, riskFilter)