Add risk list and create risk
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -215,6 +215,14 @@ enum PolicyOrderField
|
||||
NAME
|
||||
}
|
||||
|
||||
enum RiskOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.RiskOrderField") {
|
||||
CREATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.RiskOrderFieldCreatedAt"
|
||||
)
|
||||
}
|
||||
|
||||
enum EvidenceOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.EvidenceOrderField") {
|
||||
CREATED_AT
|
||||
@@ -291,6 +299,14 @@ input PolicyOrder
|
||||
field: PolicyOrderField!
|
||||
}
|
||||
|
||||
input RiskOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.RiskOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: RiskOrderField!
|
||||
}
|
||||
|
||||
input EvidenceOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.EvidenceOrderBy"
|
||||
@@ -358,6 +374,14 @@ type Organization implements Node {
|
||||
orderBy: MitigationOrder
|
||||
): MitigationConnection! @goField(forceResolver: true)
|
||||
|
||||
risks(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: RiskOrder
|
||||
): RiskConnection! @goField(forceResolver: true)
|
||||
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
@@ -487,6 +511,14 @@ type Policy implements Node {
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type Risk implements Node {
|
||||
id: ID!
|
||||
name: String!
|
||||
description: String!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type Session {
|
||||
id: ID!
|
||||
expiresAt: Datetime!
|
||||
@@ -606,6 +638,16 @@ type PolicyEdge {
|
||||
node: Policy!
|
||||
}
|
||||
|
||||
type RiskConnection {
|
||||
edges: [RiskEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type RiskEdge {
|
||||
cursor: CursorKey!
|
||||
node: Risk!
|
||||
}
|
||||
|
||||
# Root Types
|
||||
type Query {
|
||||
node(id: ID!): Node!
|
||||
@@ -657,6 +699,11 @@ type Mutation {
|
||||
assignTask(input: AssignTaskInput!): AssignTaskPayload!
|
||||
unassignTask(input: UnassignTaskInput!): UnassignTaskPayload!
|
||||
|
||||
# Risk mutations
|
||||
createRisk(input: CreateRiskInput!): CreateRiskPayload!
|
||||
updateRisk(input: UpdateRiskInput!): UpdateRiskPayload!
|
||||
deleteRisk(input: DeleteRiskInput!): DeleteRiskPayload!
|
||||
|
||||
# Evidence mutations
|
||||
uploadEvidence(input: UploadEvidenceInput!): UploadEvidencePayload!
|
||||
deleteEvidence(input: DeleteEvidenceInput!): DeleteEvidencePayload!
|
||||
@@ -804,6 +851,22 @@ input UnassignTaskInput {
|
||||
taskId: ID!
|
||||
}
|
||||
|
||||
input CreateRiskInput {
|
||||
organizationId: ID!
|
||||
name: String!
|
||||
description: String!
|
||||
}
|
||||
|
||||
input UpdateRiskInput {
|
||||
id: ID!
|
||||
name: String
|
||||
description: String
|
||||
}
|
||||
|
||||
input DeleteRiskInput {
|
||||
riskId: ID!
|
||||
}
|
||||
|
||||
input UploadEvidenceInput {
|
||||
taskId: ID!
|
||||
name: String!
|
||||
@@ -939,6 +1002,18 @@ type UnassignTaskPayload {
|
||||
task: Task!
|
||||
}
|
||||
|
||||
type CreateRiskPayload {
|
||||
riskEdge: RiskEdge!
|
||||
}
|
||||
|
||||
type UpdateRiskPayload {
|
||||
risk: Risk!
|
||||
}
|
||||
|
||||
type DeleteRiskPayload {
|
||||
deletedRiskId: ID!
|
||||
}
|
||||
|
||||
type UploadEvidencePayload {
|
||||
evidenceEdge: EvidenceEdge!
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
54
pkg/server/api/console/v1/types/risk.go
Normal file
54
pkg/server/api/console/v1/types/risk.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
type (
|
||||
RiskOrderBy OrderBy[coredata.RiskOrderField]
|
||||
)
|
||||
|
||||
func NewRiskConnection(p *page.Page[*coredata.Risk, coredata.RiskOrderField]) *RiskConnection {
|
||||
var edges = make([]*RiskEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
edges[i] = NewRiskEdge(p.Data[i], p.Cursor.OrderBy.Field)
|
||||
}
|
||||
|
||||
return &RiskConnection{
|
||||
Edges: edges,
|
||||
PageInfo: NewPageInfo(p),
|
||||
}
|
||||
}
|
||||
|
||||
func NewRiskEdge(r *coredata.Risk, orderBy coredata.RiskOrderField) *RiskEdge {
|
||||
return &RiskEdge{
|
||||
Cursor: r.CursorKey(orderBy),
|
||||
Node: NewRisk(r),
|
||||
}
|
||||
}
|
||||
|
||||
func NewRisk(r *coredata.Risk) *Risk {
|
||||
return &Risk{
|
||||
ID: r.ID,
|
||||
Name: r.Name,
|
||||
Description: r.Description,
|
||||
CreatedAt: r.CreatedAt,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,16 @@ type CreatePolicyPayload struct {
|
||||
PolicyEdge *PolicyEdge `json:"policyEdge"`
|
||||
}
|
||||
|
||||
type CreateRiskInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type CreateRiskPayload struct {
|
||||
RiskEdge *RiskEdge `json:"riskEdge"`
|
||||
}
|
||||
|
||||
type CreateTaskInput struct {
|
||||
MitigationID gid.GID `json:"mitigationId"`
|
||||
Name string `json:"name"`
|
||||
@@ -182,6 +192,14 @@ type DeletePolicyPayload struct {
|
||||
DeletedPolicyID gid.GID `json:"deletedPolicyId"`
|
||||
}
|
||||
|
||||
type DeleteRiskInput struct {
|
||||
RiskID gid.GID `json:"riskId"`
|
||||
}
|
||||
|
||||
type DeleteRiskPayload struct {
|
||||
DeletedRiskID gid.GID `json:"deletedRiskId"`
|
||||
}
|
||||
|
||||
type DeleteTaskInput struct {
|
||||
TaskID gid.GID `json:"taskId"`
|
||||
}
|
||||
@@ -313,6 +331,7 @@ type Organization struct {
|
||||
Peoples *PeopleConnection `json:"peoples"`
|
||||
Policies *PolicyConnection `json:"policies"`
|
||||
Mitigations *MitigationConnection `json:"mitigations"`
|
||||
Risks *RiskConnection `json:"risks"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
@@ -401,6 +420,27 @@ type RemoveUserPayload struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type Risk struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (Risk) IsNode() {}
|
||||
func (this Risk) GetID() gid.GID { return this.ID }
|
||||
|
||||
type RiskConnection struct {
|
||||
Edges []*RiskEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
}
|
||||
|
||||
type RiskEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *Risk `json:"node"`
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
ID gid.GID `json:"id"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
@@ -497,6 +537,16 @@ type UpdatePolicyPayload struct {
|
||||
Policy *Policy `json:"policy"`
|
||||
}
|
||||
|
||||
type UpdateRiskInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateRiskPayload struct {
|
||||
Risk *Risk `json:"risk"`
|
||||
}
|
||||
|
||||
type UpdateTaskInput struct {
|
||||
TaskID gid.GID `json:"taskId"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
|
||||
@@ -457,7 +457,7 @@ func (r *mutationResolver) CreateTask(ctx context.Context, input types.CreateTas
|
||||
TimeEstimate: input.TimeEstimate,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create task: %w", err)
|
||||
panic(fmt.Errorf("cannot create task: %w", err))
|
||||
}
|
||||
|
||||
return &types.CreateTaskPayload{
|
||||
@@ -477,7 +477,7 @@ func (r *mutationResolver) UpdateTask(ctx context.Context, input types.UpdateTas
|
||||
TimeEstimate: input.TimeEstimate,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot update task: %w", err)
|
||||
panic(fmt.Errorf("cannot update task: %w", err))
|
||||
}
|
||||
|
||||
return &types.UpdateTaskPayload{
|
||||
@@ -491,7 +491,7 @@ func (r *mutationResolver) DeleteTask(ctx context.Context, input types.DeleteTas
|
||||
|
||||
err := svc.Tasks.Delete(ctx, input.TaskID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot delete task: %w", err)
|
||||
panic(fmt.Errorf("cannot delete task: %w", err))
|
||||
}
|
||||
|
||||
return &types.DeleteTaskPayload{
|
||||
@@ -505,7 +505,7 @@ func (r *mutationResolver) AssignTask(ctx context.Context, input types.AssignTas
|
||||
|
||||
task, err := svc.Tasks.Assign(ctx, input.TaskID, input.AssignedToID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot assign task: %w", err)
|
||||
panic(fmt.Errorf("cannot assign task: %w", err))
|
||||
}
|
||||
|
||||
return &types.AssignTaskPayload{
|
||||
@@ -519,7 +519,7 @@ func (r *mutationResolver) UnassignTask(ctx context.Context, input types.Unassig
|
||||
|
||||
task, err := svc.Tasks.Unassign(ctx, input.TaskID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot unassign task: %w", err)
|
||||
panic(fmt.Errorf("cannot unassign task: %w", err))
|
||||
}
|
||||
|
||||
return &types.UnassignTaskPayload{
|
||||
@@ -527,6 +527,62 @@ func (r *mutationResolver) UnassignTask(ctx context.Context, input types.Unassig
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateRisk is the resolver for the createRisk field.
|
||||
func (r *mutationResolver) CreateRisk(ctx context.Context, input types.CreateRiskInput) (*types.CreateRiskPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.OrganizationID.TenantID())
|
||||
|
||||
risk, err := svc.Risks.Create(
|
||||
ctx,
|
||||
probo.CreateRiskRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
Name: input.Name,
|
||||
Description: input.Description,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create risk: %w", err))
|
||||
}
|
||||
|
||||
return &types.CreateRiskPayload{
|
||||
RiskEdge: types.NewRiskEdge(risk, coredata.RiskOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateRisk is the resolver for the updateRisk field.
|
||||
func (r *mutationResolver) UpdateRisk(ctx context.Context, input types.UpdateRiskInput) (*types.UpdateRiskPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.ID.TenantID())
|
||||
|
||||
risk, err := svc.Risks.Update(
|
||||
ctx,
|
||||
probo.UpdateRiskRequest{
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
Description: input.Description,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot update risk: %w", err))
|
||||
}
|
||||
|
||||
return &types.UpdateRiskPayload{
|
||||
Risk: types.NewRisk(risk),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteRisk is the resolver for the deleteRisk field.
|
||||
func (r *mutationResolver) DeleteRisk(ctx context.Context, input types.DeleteRiskInput) (*types.DeleteRiskPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.RiskID.TenantID())
|
||||
|
||||
err := svc.Risks.Delete(ctx, input.RiskID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot delete risk: %w", err))
|
||||
}
|
||||
|
||||
return &types.DeleteRiskPayload{
|
||||
DeletedRiskID: input.RiskID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UploadEvidence is the resolver for the uploadEvidence field.
|
||||
func (r *mutationResolver) UploadEvidence(ctx context.Context, input types.UploadEvidenceInput) (*types.UploadEvidencePayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.TaskID.TenantID())
|
||||
@@ -790,6 +846,31 @@ func (r *organizationResolver) Mitigations(ctx context.Context, obj *types.Organ
|
||||
return types.NewMitigationConnection(page), nil
|
||||
}
|
||||
|
||||
// Risks is the resolver for the risks field.
|
||||
func (r *organizationResolver) Risks(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.RiskOrderBy) (*types.RiskConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.RiskOrderField]{
|
||||
Field: coredata.RiskOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.RiskOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Risks.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list organization risks: %w", err))
|
||||
}
|
||||
|
||||
return types.NewRiskConnection(page), nil
|
||||
}
|
||||
|
||||
// Owner is the resolver for the owner field.
|
||||
func (r *policyResolver) Owner(ctx context.Context, obj *types.Policy) (*types.People, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
@@ -875,6 +956,12 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
|
||||
}
|
||||
|
||||
return types.NewControl(control), nil
|
||||
case coredata.RiskEntityType:
|
||||
risk, err := svc.Risks.Get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return types.NewRisk(risk), nil
|
||||
default:
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user