Add assets

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-05-30 15:07:57 -07:00
parent b315be96bc
commit fa1cd6fb51
38 changed files with 9121 additions and 7 deletions

View File

@@ -343,6 +343,23 @@ enum DocumentType @goModel(model: "github.com/getprobo/probo/pkg/coredata.Docume
POLICY @goEnum(value: "github.com/getprobo/probo/pkg/coredata.DocumentTypePolicy")
}
enum AssetType @goModel(model: "github.com/getprobo/probo/pkg/coredata.AssetType") {
PHYSICAL @goEnum(value: "github.com/getprobo/probo/pkg/coredata.AssetTypePhysical")
VIRTUAL @goEnum(value: "github.com/getprobo/probo/pkg/coredata.AssetTypeVirtual")
}
enum CriticityLevel @goModel(model: "github.com/getprobo/probo/pkg/coredata.CriticityLevel") {
LOW @goEnum(value: "github.com/getprobo/probo/pkg/coredata.CriticityLevelLow")
MEDIUM @goEnum(value: "github.com/getprobo/probo/pkg/coredata.CriticityLevelMedium")
HIGH @goEnum(value: "github.com/getprobo/probo/pkg/coredata.CriticityLevelHigh")
}
enum AssetOrderField @goModel(model: "github.com/getprobo/probo/pkg/coredata.AssetOrderField") {
CREATED_AT @goEnum(value: "github.com/getprobo/probo/pkg/coredata.AssetOrderFieldCreatedAt")
AMOUNT @goEnum(value: "github.com/getprobo/probo/pkg/coredata.AssetOrderFieldAmount")
CRITICITY @goEnum(value: "github.com/getprobo/probo/pkg/coredata.AssetOrderFieldCriticity")
}
# Order Input Types
input UserOrder
@goModel(
@@ -532,6 +549,14 @@ type Organization implements Node {
orderBy: TaskOrder
): TaskConnection! @goField(forceResolver: true)
assets(
first: Int
after: CursorKey
last: Int
before: CursorKey
orderBy: AssetOrder
): AssetConnection! @goField(forceResolver: true)
createdAt: Datetime!
updatedAt: Datetime!
}
@@ -1126,6 +1151,12 @@ type Mutation {
exportAudit(input: ExportAuditInput!): ExportAuditPayload!
assessVendor(input: AssessVendorInput!): AssessVendorPayload!
createAsset(input: CreateAssetInput!): CreateAssetPayload!
updateAsset(input: UpdateAssetInput!): UpdateAssetPayload!
deleteAsset(input: DeleteAssetInput!): DeleteAssetPayload!
addAssetVendor(input: AddAssetVendorInput!): AddAssetVendorPayload!
removeAssetVendor(input: RemoveAssetVendorInput!): RemoveAssetVendorPayload!
}
# Input Types
@@ -1832,3 +1863,94 @@ input AssessVendorInput {
type AssessVendorPayload {
vendor: Vendor!
}
type Asset implements Node {
id: ID!
name: String!
amount: Int!
owner: People! @goField(forceResolver: true)
vendors(
first: Int
after: CursorKey
last: Int
before: CursorKey
orderBy: VendorOrder
): VendorConnection! @goField(forceResolver: true)
criticity: CriticityLevel!
assetType: AssetType! @goField(forceResolver: true)
dataTypesStored: String!
organization: Organization! @goField(forceResolver: true)
createdAt: Datetime!
updatedAt: Datetime!
}
type AssetConnection {
edges: [AssetEdge!]!
pageInfo: PageInfo!
}
type AssetEdge {
cursor: CursorKey!
node: Asset!
}
input AssetOrder {
direction: OrderDirection!
field: AssetOrderField!
}
input CreateAssetInput {
organizationId: ID!
name: String!
amount: Int!
ownerId: ID!
criticity: CriticityLevel! = MEDIUM
assetType: AssetType!
dataTypesStored: String!
vendorIds: [ID!]
}
input UpdateAssetInput {
id: ID!
name: String
amount: Int
ownerId: ID
criticity: CriticityLevel
assetType: AssetType
dataTypesStored: String
vendorIds: [ID!]
}
input DeleteAssetInput {
assetId: ID!
}
input AddAssetVendorInput {
assetId: ID!
vendorId: ID!
}
input RemoveAssetVendorInput {
assetId: ID!
vendorId: ID!
}
type CreateAssetPayload {
assetEdge: AssetEdge!
}
type UpdateAssetPayload {
asset: Asset!
}
type DeleteAssetPayload {
deletedAssetId: ID!
}
type AddAssetVendorPayload {
asset: Asset!
}
type RemoveAssetVendorPayload {
asset: Asset!
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
package types
import (
"github.com/getprobo/probo/pkg/coredata"
"github.com/getprobo/probo/pkg/page"
)
func NewAsset(asset *coredata.Asset) *Asset {
return &Asset{
ID: asset.ID,
Name: asset.Name,
Amount: asset.Amount,
Criticity: asset.Criticity,
AssetType: asset.AssetType,
DataTypesStored: asset.DataTypesStored,
CreatedAt: asset.CreatedAt,
UpdatedAt: asset.UpdatedAt,
}
}
func NewAssetEdge(asset *coredata.Asset, orderField coredata.AssetOrderField) *AssetEdge {
return &AssetEdge{
Node: NewAsset(asset),
Cursor: asset.CursorKey(orderField),
}
}
func NewAssetConnection(page *page.Page[*coredata.Asset, coredata.AssetOrderField]) *AssetConnection {
edges := make([]*AssetEdge, len(page.Data))
for i, asset := range page.Data {
edges[i] = NewAssetEdge(asset, page.Cursor.OrderBy.Field)
}
return &AssetConnection{
Edges: edges,
PageInfo: NewPageInfo(page),
}
}

View File

@@ -20,6 +20,15 @@ type Node interface {
GetID() gid.GID
}
type AddAssetVendorInput struct {
AssetID gid.GID `json:"assetId"`
VendorID gid.GID `json:"vendorId"`
}
type AddAssetVendorPayload struct {
Asset *Asset `json:"asset"`
}
type AssessVendorInput struct {
ID gid.GID `json:"id"`
WebsiteURL string `json:"websiteUrl"`
@@ -29,6 +38,38 @@ type AssessVendorPayload struct {
Vendor *Vendor `json:"vendor"`
}
type Asset struct {
ID gid.GID `json:"id"`
Name string `json:"name"`
Amount int `json:"amount"`
Owner *People `json:"owner"`
Vendors *VendorConnection `json:"vendors"`
Criticity coredata.CriticityLevel `json:"criticity"`
AssetType coredata.AssetType `json:"assetType"`
DataTypesStored string `json:"dataTypesStored"`
Organization *Organization `json:"organization"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (Asset) IsNode() {}
func (this Asset) GetID() gid.GID { return this.ID }
type AssetConnection struct {
Edges []*AssetEdge `json:"edges"`
PageInfo *PageInfo `json:"pageInfo"`
}
type AssetEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *Asset `json:"node"`
}
type AssetOrder struct {
Direction page.OrderDirection `json:"direction"`
Field coredata.AssetOrderField `json:"field"`
}
type AssignTaskInput struct {
TaskID gid.GID `json:"taskId"`
AssignedToID gid.GID `json:"assignedToId"`
@@ -97,6 +138,21 @@ type ControlEdge struct {
Node *Control `json:"node"`
}
type CreateAssetInput struct {
OrganizationID gid.GID `json:"organizationId"`
Name string `json:"name"`
Amount int `json:"amount"`
OwnerID gid.GID `json:"ownerId"`
Criticity coredata.CriticityLevel `json:"criticity"`
AssetType coredata.AssetType `json:"assetType"`
DataTypesStored string `json:"dataTypesStored"`
VendorIds []gid.GID `json:"vendorIds,omitempty"`
}
type CreateAssetPayload struct {
AssetEdge *AssetEdge `json:"assetEdge"`
}
type CreateControlDocumentMappingInput struct {
ControlID gid.GID `json:"controlId"`
DocumentID gid.GID `json:"documentId"`
@@ -285,6 +341,14 @@ type CreateVendorRiskAssessmentPayload struct {
VendorRiskAssessmentEdge *VendorRiskAssessmentEdge `json:"vendorRiskAssessmentEdge"`
}
type DeleteAssetInput struct {
AssetID gid.GID `json:"assetId"`
}
type DeleteAssetPayload struct {
DeletedAssetID gid.GID `json:"deletedAssetId"`
}
type DeleteControlDocumentMappingInput struct {
ControlID gid.GID `json:"controlId"`
DocumentID gid.GID `json:"documentId"`
@@ -635,6 +699,7 @@ type Organization struct {
Measures *MeasureConnection `json:"measures"`
Risks *RiskConnection `json:"risks"`
Tasks *TaskConnection `json:"tasks"`
Assets *AssetConnection `json:"assets"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
@@ -702,6 +767,15 @@ type PublishDocumentVersionPayload struct {
type Query struct {
}
type RemoveAssetVendorInput struct {
AssetID gid.GID `json:"assetId"`
VendorID gid.GID `json:"vendorId"`
}
type RemoveAssetVendorPayload struct {
Asset *Asset `json:"asset"`
}
type RemoveUserInput struct {
OrganizationID gid.GID `json:"organizationId"`
UserID gid.GID `json:"userId"`
@@ -814,6 +888,21 @@ type UnassignTaskPayload struct {
Task *Task `json:"task"`
}
type UpdateAssetInput struct {
ID gid.GID `json:"id"`
Name *string `json:"name,omitempty"`
Amount *int `json:"amount,omitempty"`
OwnerID *gid.GID `json:"ownerId,omitempty"`
Criticity *coredata.CriticityLevel `json:"criticity,omitempty"`
AssetType *coredata.AssetType `json:"assetType,omitempty"`
DataTypesStored *string `json:"dataTypesStored,omitempty"`
VendorIds []gid.GID `json:"vendorIds,omitempty"`
}
type UpdateAssetPayload struct {
Asset *Asset `json:"asset"`
}
type UpdateDocumentInput struct {
ID gid.GID `json:"id"`
Title *string `json:"title,omitempty"`

View File

@@ -20,6 +20,65 @@ import (
"github.com/vektah/gqlparser/v2/gqlerror"
)
// Owner is the resolver for the owner field.
func (r *assetResolver) Owner(ctx context.Context, obj *types.Asset) (*types.People, error) {
svc := GetTenantService(ctx, r.proboSvc, obj.ID.TenantID())
asset, err := svc.Assets.Get(ctx, obj.ID)
if err != nil {
panic(fmt.Errorf("cannot get asset: %w", err))
}
owner, err := svc.Peoples.Get(ctx, asset.OwnerID)
if err != nil {
panic(fmt.Errorf("cannot get owner: %w", err))
}
return types.NewPeople(owner), nil
}
// Vendors is the resolver for the vendors field.
func (r *assetResolver) Vendors(ctx context.Context, obj *types.Asset, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.VendorOrderBy) (*types.VendorConnection, error) {
svc := GetTenantService(ctx, r.proboSvc, obj.ID.TenantID())
pageOrderBy := page.OrderBy[coredata.VendorOrderField]{
Field: coredata.VendorOrderFieldCreatedAt,
Direction: page.OrderDirectionDesc,
}
if orderBy != nil {
pageOrderBy = page.OrderBy[coredata.VendorOrderField]{
Field: orderBy.Field,
Direction: orderBy.Direction,
}
}
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
page, err := svc.Assets.ListVendors(ctx, obj.ID, cursor)
if err != nil {
panic(fmt.Errorf("cannot list asset vendors: %w", err))
}
return types.NewVendorConnection(page), nil
}
// AssetType is the resolver for the assetType field.
func (r *assetResolver) AssetType(ctx context.Context, obj *types.Asset) (coredata.AssetType, error) {
svc := GetTenantService(ctx, r.proboSvc, obj.ID.TenantID())
asset, err := svc.Assets.Get(ctx, obj.ID)
if err != nil {
panic(fmt.Errorf("cannot get asset: %w", err))
}
return asset.AssetType, nil
}
// Organization is the resolver for the organization field.
func (r *assetResolver) Organization(ctx context.Context, obj *types.Asset) (*types.Organization, error) {
panic(fmt.Errorf("not implemented: Organization - organization"))
}
// Framework is the resolver for the framework field.
func (r *controlResolver) Framework(ctx context.Context, obj *types.Control) (*types.Framework, error) {
svc := GetTenantService(ctx, r.proboSvc, obj.ID.TenantID())
@@ -1557,6 +1616,77 @@ func (r *mutationResolver) AssessVendor(ctx context.Context, input types.AssessV
}, nil
}
// CreateAsset is the resolver for the createAsset field.
func (r *mutationResolver) CreateAsset(ctx context.Context, input types.CreateAssetInput) (*types.CreateAssetPayload, error) {
svc := GetTenantService(ctx, r.proboSvc, input.OrganizationID.TenantID())
asset, err := svc.Assets.Create(ctx, probo.CreateAssetRequest{
OrganizationID: input.OrganizationID,
Name: input.Name,
Amount: input.Amount,
OwnerID: input.OwnerID,
Criticity: input.Criticity,
AssetType: input.AssetType,
DataTypesStored: input.DataTypesStored,
VendorIDs: input.VendorIds,
})
if err != nil {
return nil, fmt.Errorf("cannot create asset: %w", err)
}
return &types.CreateAssetPayload{
AssetEdge: types.NewAssetEdge(asset, coredata.AssetOrderFieldCreatedAt),
}, nil
}
// UpdateAsset is the resolver for the updateAsset field.
func (r *mutationResolver) UpdateAsset(ctx context.Context, input types.UpdateAssetInput) (*types.UpdateAssetPayload, error) {
svc := GetTenantService(ctx, r.proboSvc, input.ID.TenantID())
asset, err := svc.Assets.Update(ctx, probo.UpdateAssetRequest{
ID: input.ID,
Name: input.Name,
Amount: input.Amount,
OwnerID: input.OwnerID,
Criticity: input.Criticity,
AssetType: input.AssetType,
DataTypesStored: input.DataTypesStored,
VendorIDs: input.VendorIds,
})
if err != nil {
return nil, fmt.Errorf("cannot update asset: %w", err)
}
return &types.UpdateAssetPayload{
Asset: types.NewAsset(asset),
}, nil
}
// DeleteAsset is the resolver for the deleteAsset field.
func (r *mutationResolver) DeleteAsset(ctx context.Context, input types.DeleteAssetInput) (*types.DeleteAssetPayload, error) {
svc := GetTenantService(ctx, r.proboSvc, input.AssetID.TenantID())
err := svc.Assets.Delete(ctx, input.AssetID)
if err != nil {
return nil, fmt.Errorf("cannot delete asset: %w", err)
}
return &types.DeleteAssetPayload{
DeletedAssetID: input.AssetID,
}, nil
}
// AddAssetVendor is the resolver for the addAssetVendor field.
func (r *mutationResolver) AddAssetVendor(ctx context.Context, input types.AddAssetVendorInput) (*types.AddAssetVendorPayload, error) {
panic(fmt.Errorf("not implemented: AddAssetVendor - addAssetVendor"))
}
// RemoveAssetVendor is the resolver for the removeAssetVendor field.
func (r *mutationResolver) RemoveAssetVendor(ctx context.Context, input types.RemoveAssetVendorInput) (*types.RemoveAssetVendorPayload, error) {
panic(fmt.Errorf("not implemented: RemoveAssetVendor - removeAssetVendor"))
}
// LogoURL is the resolver for the logoUrl field.
func (r *organizationResolver) LogoURL(ctx context.Context, obj *types.Organization) (*string, error) {
svc := GetTenantService(ctx, r.proboSvc, obj.ID.TenantID())
@@ -1787,6 +1917,31 @@ func (r *organizationResolver) Tasks(ctx context.Context, obj *types.Organizatio
return types.NewTaskConnection(page), nil
}
// Assets is the resolver for the assets field.
func (r *organizationResolver) Assets(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.AssetOrder) (*types.AssetConnection, error) {
svc := GetTenantService(ctx, r.proboSvc, obj.ID.TenantID())
pageOrderBy := page.OrderBy[coredata.AssetOrderField]{
Field: coredata.AssetOrderFieldCreatedAt,
Direction: page.OrderDirectionDesc,
}
if orderBy != nil {
pageOrderBy = page.OrderBy[coredata.AssetOrderField]{
Field: orderBy.Field,
Direction: orderBy.Direction,
}
}
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
page, err := svc.Assets.ListForOrganizationID(ctx, obj.ID, cursor)
if err != nil {
panic(fmt.Errorf("cannot list organization assets: %w", err))
}
return types.NewAssetConnection(page), nil
}
// Node is the resolver for the node field.
func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error) {
svc := GetTenantService(ctx, r.proboSvc, id.TenantID())
@@ -1878,6 +2033,12 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
panic(fmt.Errorf("cannot get document version signature: %w", err))
}
return types.NewDocumentVersionSignature(documentVersionSignature), nil
case coredata.AssetEntityType:
asset, err := svc.Assets.Get(ctx, id)
if err != nil {
panic(fmt.Errorf("cannot get asset: %w", err))
}
return types.NewAsset(asset), nil
default:
}
@@ -2190,7 +2351,6 @@ func (r *vendorResolver) BusinessOwner(ctx context.Context, obj *types.Vendor) (
// SecurityOwner is the resolver for the securityOwner field.
func (r *vendorResolver) SecurityOwner(ctx context.Context, obj *types.Vendor) (*types.People, error) {
svc := GetTenantService(ctx, r.proboSvc, obj.ID.TenantID())
vendor, err := svc.Vendors.Get(ctx, obj.ID)
if err != nil {
panic(fmt.Errorf("failed to get vendor: %w", err))
@@ -2286,6 +2446,9 @@ func (r *viewerResolver) Organizations(ctx context.Context, obj *types.Viewer, f
}, nil
}
// Asset returns schema.AssetResolver implementation.
func (r *Resolver) Asset() schema.AssetResolver { return &assetResolver{r} }
// Control returns schema.ControlResolver implementation.
func (r *Resolver) Control() schema.ControlResolver { return &controlResolver{r} }
@@ -2345,6 +2508,7 @@ func (r *Resolver) VendorRiskAssessment() schema.VendorRiskAssessmentResolver {
// Viewer returns schema.ViewerResolver implementation.
func (r *Resolver) Viewer() schema.ViewerResolver { return &viewerResolver{r} }
type assetResolver struct{ *Resolver }
type controlResolver struct{ *Resolver }
type documentResolver struct{ *Resolver }
type documentVersionResolver struct{ *Resolver }