Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ require (
github.com/theopenlane/eddy v0.1.0
github.com/theopenlane/entx v0.36.3
github.com/theopenlane/go-client v0.15.0
github.com/theopenlane/gqlgen-plugins v0.18.4
github.com/theopenlane/gqlgen-plugins v0.19.0
github.com/theopenlane/httpsling v0.3.0
github.com/theopenlane/iam v0.41.1
github.com/theopenlane/logx v0.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,8 @@ github.com/theopenlane/entx v0.36.3 h1:BMVtL+FESaSAI5AtNQSly/DU6WZyep3ENYeyHhcC6
github.com/theopenlane/entx v0.36.3/go.mod h1:p1eAOkVRExjf17q7WkFknI7/Q+l8tOGpFH4pI/98odc=
github.com/theopenlane/go-client v0.15.0 h1:Jz1y0cm46lN24rog8YakV7u7jxgTZ9NZ4iIxP6mbMLs=
github.com/theopenlane/go-client v0.15.0/go.mod h1:E0KiZ+wOpJf/GAD0F223vpsizFmqRomJETKMtMaLmZI=
github.com/theopenlane/gqlgen-plugins v0.18.4 h1:433KyDIW5y72aqMqkMAiIq0R7Y4OJ7laRBJaO6UchYM=
github.com/theopenlane/gqlgen-plugins v0.18.4/go.mod h1:AhBPUZSil2tXQOejR1co98DQznofub4PXFeK/7SXsxA=
github.com/theopenlane/gqlgen-plugins v0.19.0 h1:tMnVF6ET2oKRewhlO78lCGUROOp4B/MTpi2al+SgQ6I=
github.com/theopenlane/gqlgen-plugins v0.19.0/go.mod h1:27Najan1nmCf2X79lYVvHJBs0R+kOzuwzGaP8uTQXF8=
github.com/theopenlane/httpsling v0.3.0 h1:Bad0dGdqCqAB8UVDyVo+YCevzRvGHhmkK22F7T3pXtY=
github.com/theopenlane/httpsling v0.3.0/go.mod h1:iJc3XRLYTFIpfCnPpLZVMBP0xsWIPAb7ozARtQoclAE=
github.com/theopenlane/iam v0.41.1 h1:Rgeh1xod4emmv1BKgK0IWeg7G98ouUfziFDtcdP7Vwk=
Expand Down
4 changes: 4 additions & 0 deletions internal/ent/schema/mixin_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

"github.com/theopenlane/entx/accessmap"

"github.com/theopenlane/gqlgen-plugins/groupby"

"github.com/theopenlane/core/common/enums"
"github.com/theopenlane/core/common/models"
"github.com/theopenlane/core/v2/internal/ent/generated/hook"
Expand Down Expand Up @@ -363,6 +365,7 @@ var controlFields = []ent.Field{
entgql.OrderField("category"),
entx.FieldWorkflowEligible(),
directives.ExternalSourceDirectiveAnnotation,
groupby.Groupable(),
).
Comment("category of the control"),
field.String("category_id").
Expand All @@ -379,6 +382,7 @@ var controlFields = []ent.Field{
entgql.OrderField("subcategory"),
directives.ExternalSourceDirectiveAnnotation,
entx.FieldWorkflowEligible(),
groupby.Groupable(),
).
Comment("subcategory of the control"),
field.Strings("mapped_categories").
Expand Down
19 changes: 16 additions & 3 deletions internal/ent/schema/mixin_customenums.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/theopenlane/core/v2/internal/ent/hooks"
"github.com/theopenlane/entx"
"github.com/theopenlane/entx/accessmap"
"github.com/theopenlane/gqlgen-plugins/groupby"
)

// CustomEnumMixin holds the schema definition for the custom enums
Expand All @@ -28,6 +29,8 @@ type CustomEnumMixin struct {
GlobalEnum bool
// DisableAutoCreate disables auto-creation of the enum if it doesn't exist
DisableAutoCreate bool
// GroupBy adds the enum name field to the schema's generated group by query
GroupBy bool
}

// newCustomEnumMixin creates a new CustomEnumMixin with the given schema type and options
Expand Down Expand Up @@ -68,16 +71,26 @@ func withGlobalEnum() customEnumOptions {
}
}

// withGroupByEnum makes the enum name field groupable in the schema's group by query
func withGroupByEnum() customEnumOptions {
return func(c *CustomEnumMixin) {
c.GroupBy = true
}
}

// Fields of the CustomEnumMixin.
func (c CustomEnumMixin) Fields() []ent.Field {
nameAnnotations := []schema.Annotation{entx.FieldCaseInsensitive()}
if c.GroupBy {
nameAnnotations = append(nameAnnotations, groupby.Groupable())
}

schema := toSchemaFuncs(c.schemaType)
fields := []ent.Field{
field.String(c.getEnumFieldName()).
Comment("the " + c.fieldName + " of the " + schema.Name()).
Optional().
Annotations(
entx.FieldCaseInsensitive(),
),
Annotations(nameAnnotations...),
field.String(c.getEnumEdgeName() + "_id").
Comment("the " + c.fieldName + " of the " + schema.Name()).
Optional(),
Expand Down
14 changes: 11 additions & 3 deletions internal/ent/schema/vulnerability.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"github.com/theopenlane/iam/entfga"

"github.com/theopenlane/core/common/enums"

"github.com/theopenlane/core/common/models"

"github.com/theopenlane/gqlgen-plugins/groupby"

"github.com/theopenlane/core/v2/internal/ent/generated"
"github.com/theopenlane/core/v2/internal/ent/hooks"
"github.com/theopenlane/core/v2/internal/ent/mixin"
Expand Down Expand Up @@ -56,6 +58,7 @@ func (Vulnerability) Fields() []ent.Field {
Annotations(
entx.FieldSearchable(),
entgql.OrderField("external_owner_id"),
groupby.Groupable(),
),
field.Enum("security_level").
Comment("security level of the vulnerability").
Expand All @@ -74,10 +77,14 @@ func (Vulnerability) Fields() []ent.Field {
entx.FieldSearchable(),
entgql.OrderField("cve_id"),
entx.IntegrationMappingField(),
groupby.Groupable(),
),
field.String("source").
Comment("system that produced the vulnerability record").
Optional(),
Optional().
Annotations(
groupby.Groupable(),
),
field.String("display_name").
Comment("display name for the vulnerability when provided").
Optional(),
Expand All @@ -94,6 +101,7 @@ func (Vulnerability) Fields() []ent.Field {
entgql.OrderField("severity"),
entx.FieldSearchable(),
entx.FieldWorkflowEligible(),
groupby.Groupable(),
),
field.Float("score").
Comment("overall score such as CVSS for the vulnerability").
Expand Down Expand Up @@ -396,7 +404,7 @@ func (v Vulnerability) Mixin() []ent.Mixin {
mixin.NewSystemOwnedMixin(mixin.SkipTupleCreation()),
newCustomEnumMixin(v, withEnumFieldName("environment"), withGlobalEnum()),
newCustomEnumMixin(v, withEnumFieldName("scope"), withGlobalEnum()),
newCustomEnumMixin(v, withEnumFieldName("status")),
newCustomEnumMixin(v, withEnumFieldName("status"), withGroupByEnum()),
WorkflowApprovalMixin{},
},
}.getMixins(v)
Expand Down
2 changes: 1 addition & 1 deletion internal/graphapi/checksum/.history_schema_checksum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fb5cd59253feb3228c795d7555c6d07ce8bff65a719c3b20f4ab212d89a3481e
32829015adf08e77033cdb594304b9314db26283cf1a0221a054802ef292a543
Loading
Loading