Add control-policy mappings and rename control APIs

This introduces the ability to map controls to policies alongside the
existing control-mitigation mappings. The feature adds bidirectional
relationships with new GraphQL fields on Control and Policy types.

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-04-08 21:14:11 -07:00
parent 348e2641bb
commit 4ce72c03f7
17 changed files with 1630 additions and 207 deletions

View File

@@ -4,11 +4,26 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
### BREAKING CHANGES
### BREAKING CHANGES
- **BREAKING:** Renamed GraphQL mutations for control-mitigation mappings:
- `createControlMapping` → `createControlMitigationMapping`
- `deleteControlMapping` → `deleteControlMitigationMapping`
- Input and payload types have been updated accordingly
### Added
- Add import control <> mitigation mapping.
- Add mitigation tasks import.
- Add auto-scroll to opened category.
- Added support for mapping controls to policies:
- New GraphQL mutations `createControlPolicyMapping` and `deleteControlPolicyMapping`
- Controls can now be associated with both mitigations and policies
- New bidirectional relationships:
- Control objects now expose a `policies` field to list associated policies
- Policy objects now expose a `controls` field to list associated controls
### Changed

View File

@@ -93,9 +93,9 @@ const organizationMitigationsQuery = graphql`
// Mutation to create a mapping between a control and a mitigation
const createMitigationMappingMutation = graphql`
mutation ControlCreateMitigationMappingMutation(
$input: CreateControlMappingInput!
$input: CreateControlMitigationMappingInput!
) {
createControlMapping(input: $input) {
createControlMitigationMapping(input: $input) {
success
}
}
@@ -104,9 +104,9 @@ const createMitigationMappingMutation = graphql`
// Mutation to delete a mapping between a control and a mitigation
const deleteMitigationMappingMutation = graphql`
mutation ControlDeleteMitigationMappingMutation(
$input: DeleteControlMappingInput!
$input: DeleteControlMitigationMappingInput!
) {
deleteControlMapping(input: $input) {
deleteControlMitigationMapping(input: $input) {
success
}
}

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<7598a6cf0314f71bab809d65acc60237>>
* @generated SignedSource<<2eea3e72c7001db14095958b3bcd750a>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,15 +9,15 @@
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type CreateControlMappingInput = {
export type CreateControlMitigationMappingInput = {
controlId: string;
mitigationId: string;
};
export type ControlCreateMitigationMappingMutation$variables = {
input: CreateControlMappingInput;
input: CreateControlMitigationMappingInput;
};
export type ControlCreateMitigationMappingMutation$data = {
readonly createControlMapping: {
readonly createControlMitigationMapping: {
readonly success: boolean;
};
};
@@ -44,9 +44,9 @@ v1 = [
"variableName": "input"
}
],
"concreteType": "CreateControlMappingPayload",
"concreteType": "CreateControlMitigationMappingPayload",
"kind": "LinkedField",
"name": "createControlMapping",
"name": "createControlMitigationMapping",
"plural": false,
"selections": [
{
@@ -78,16 +78,16 @@ return {
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "57ab0bf99dd6ed3d2e980c51f185b9c0",
"cacheID": "955241a049e81cd7faed45d69ce3b145",
"id": null,
"metadata": {},
"name": "ControlCreateMitigationMappingMutation",
"operationKind": "mutation",
"text": "mutation ControlCreateMitigationMappingMutation(\n $input: CreateControlMappingInput!\n) {\n createControlMapping(input: $input) {\n success\n }\n}\n"
"text": "mutation ControlCreateMitigationMappingMutation(\n $input: CreateControlMitigationMappingInput!\n) {\n createControlMitigationMapping(input: $input) {\n success\n }\n}\n"
}
};
})();
(node as any).hash = "17ef8f09acabf19168dad896e4225e3d";
(node as any).hash = "ffbcf187d7f2d3c65a2d1fb5c6a180bb";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<c1cd34e6543447b414b10f63225883c2>>
* @generated SignedSource<<7c4ad77e70fa42cf8257113897a607ec>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,15 +9,15 @@
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type DeleteControlMappingInput = {
export type DeleteControlMitigationMappingInput = {
controlId: string;
mitigationId: string;
};
export type ControlDeleteMitigationMappingMutation$variables = {
input: DeleteControlMappingInput;
input: DeleteControlMitigationMappingInput;
};
export type ControlDeleteMitigationMappingMutation$data = {
readonly deleteControlMapping: {
readonly deleteControlMitigationMapping: {
readonly success: boolean;
};
};
@@ -44,9 +44,9 @@ v1 = [
"variableName": "input"
}
],
"concreteType": "DeleteControlMappingPayload",
"concreteType": "DeleteControlMitigationMappingPayload",
"kind": "LinkedField",
"name": "deleteControlMapping",
"name": "deleteControlMitigationMapping",
"plural": false,
"selections": [
{
@@ -78,16 +78,16 @@ return {
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "31dcbb70c0b32e78dcb3fd2a2dc1a58b",
"cacheID": "3d09a29c8ae06a97d098e565a7f2d172",
"id": null,
"metadata": {},
"name": "ControlDeleteMitigationMappingMutation",
"operationKind": "mutation",
"text": "mutation ControlDeleteMitigationMappingMutation(\n $input: DeleteControlMappingInput!\n) {\n deleteControlMapping(input: $input) {\n success\n }\n}\n"
"text": "mutation ControlDeleteMitigationMappingMutation(\n $input: DeleteControlMitigationMappingInput!\n) {\n deleteControlMitigationMapping(input: $input) {\n success\n }\n}\n"
}
};
})();
(node as any).hash = "6070b58009682dfa712e445363f0ebf5";
(node as any).hash = "6905236aeeb313e5deed3e569a0c7c54";
export default node;

View File

@@ -394,9 +394,9 @@ const linkedControlsQuery = graphql`
const createControlMappingMutation = graphql`
mutation MitigationViewCreateControlMappingMutation(
$input: CreateControlMappingInput!
$input: CreateControlMitigationMappingInput!
) {
createControlMapping(input: $input) {
createControlMitigationMapping(input: $input) {
success
}
}
@@ -404,9 +404,9 @@ const createControlMappingMutation = graphql`
const deleteControlMappingMutation = graphql`
mutation MitigationViewDeleteControlMappingMutation(
$input: DeleteControlMappingInput!
$input: DeleteControlMitigationMappingInput!
) {
deleteControlMapping(input: $input) {
deleteControlMitigationMapping(input: $input) {
success
}
}

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<d072ba12f8b6bd81f47e8d2fbe56db9c>>
* @generated SignedSource<<53f255c3852774870c7d294d64e6808d>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,15 +9,15 @@
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type CreateControlMappingInput = {
export type CreateControlMitigationMappingInput = {
controlId: string;
mitigationId: string;
};
export type MitigationViewCreateControlMappingMutation$variables = {
input: CreateControlMappingInput;
input: CreateControlMitigationMappingInput;
};
export type MitigationViewCreateControlMappingMutation$data = {
readonly createControlMapping: {
readonly createControlMitigationMapping: {
readonly success: boolean;
};
};
@@ -44,9 +44,9 @@ v1 = [
"variableName": "input"
}
],
"concreteType": "CreateControlMappingPayload",
"concreteType": "CreateControlMitigationMappingPayload",
"kind": "LinkedField",
"name": "createControlMapping",
"name": "createControlMitigationMapping",
"plural": false,
"selections": [
{
@@ -78,16 +78,16 @@ return {
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "79290e466d2aa856113aae8a4e7a0035",
"cacheID": "fa46c5cf8b96b70117d12cf985247824",
"id": null,
"metadata": {},
"name": "MitigationViewCreateControlMappingMutation",
"operationKind": "mutation",
"text": "mutation MitigationViewCreateControlMappingMutation(\n $input: CreateControlMappingInput!\n) {\n createControlMapping(input: $input) {\n success\n }\n}\n"
"text": "mutation MitigationViewCreateControlMappingMutation(\n $input: CreateControlMitigationMappingInput!\n) {\n createControlMitigationMapping(input: $input) {\n success\n }\n}\n"
}
};
})();
(node as any).hash = "32a27dc5fdd06c261258e80db3db50fc";
(node as any).hash = "af6e4d7933e5c428eec0e97cdf0b73dd";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<aee67baf82965259c299a4ae9947bda3>>
* @generated SignedSource<<f34a09cd4eda414409384386a4cea5b4>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,15 +9,15 @@
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type DeleteControlMappingInput = {
export type DeleteControlMitigationMappingInput = {
controlId: string;
mitigationId: string;
};
export type MitigationViewDeleteControlMappingMutation$variables = {
input: DeleteControlMappingInput;
input: DeleteControlMitigationMappingInput;
};
export type MitigationViewDeleteControlMappingMutation$data = {
readonly deleteControlMapping: {
readonly deleteControlMitigationMapping: {
readonly success: boolean;
};
};
@@ -44,9 +44,9 @@ v1 = [
"variableName": "input"
}
],
"concreteType": "DeleteControlMappingPayload",
"concreteType": "DeleteControlMitigationMappingPayload",
"kind": "LinkedField",
"name": "deleteControlMapping",
"name": "deleteControlMitigationMapping",
"plural": false,
"selections": [
{
@@ -78,16 +78,16 @@ return {
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "824394c9cc09d7d428ad42835d3737ef",
"cacheID": "b18a11215ba33a6c770cc08c88a28769",
"id": null,
"metadata": {},
"name": "MitigationViewDeleteControlMappingMutation",
"operationKind": "mutation",
"text": "mutation MitigationViewDeleteControlMappingMutation(\n $input: DeleteControlMappingInput!\n) {\n deleteControlMapping(input: $input) {\n success\n }\n}\n"
"text": "mutation MitigationViewDeleteControlMappingMutation(\n $input: DeleteControlMitigationMappingInput!\n) {\n deleteControlMitigationMapping(input: $input) {\n success\n }\n}\n"
}
};
})();
(node as any).hash = "4d7bd098ed16e825abec0e5d996b06e9";
(node as any).hash = "f4f01abb45a3288558d7e8a1d19ce1ed";
export default node;

View File

@@ -56,6 +56,66 @@ func (c Control) CursorKey(orderBy ControlOrderField) page.CursorKey {
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
}
func (c *Controls) LoadByPolicyID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
policyID gid.GID,
cursor *page.Cursor[ControlOrderField],
) error {
q := `
WITH ctrl AS (
SELECT
c.id,
c.reference_id,
c.framework_id,
c.tenant_id,
c.name,
c.description,
c.created_at,
c.updated_at
FROM
controls c
INNER JOIN
controls_policies cp ON c.id = cp.control_id
WHERE
cp.policy_id = @policy_id
)
SELECT
id,
reference_id,
framework_id,
tenant_id,
name,
description,
created_at,
updated_at
FROM
ctrl
WHERE %s
AND %s
`
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"policy_id": policyID}
maps.Copy(args, scope.SQLArguments())
maps.Copy(args, cursor.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query controls: %w", err)
}
controls, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Control])
if err != nil {
return fmt.Errorf("cannot collect controls: %w", err)
}
*c = controls
return nil
}
func (c *Controls) LoadByMitigationID(
ctx context.Context,
conn pg.Conn,

View File

@@ -0,0 +1,95 @@
// 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 coredata
import (
"context"
"fmt"
"maps"
"time"
"github.com/getprobo/probo/pkg/gid"
"github.com/jackc/pgx/v5"
"go.gearno.de/kit/pg"
)
type (
ControlPolicy struct {
ControlID gid.GID `db:"control_id"`
PolicyID gid.GID `db:"policy_id"`
TenantID gid.TenantID `db:"tenant_id"`
CreatedAt time.Time `db:"created_at"`
}
ControlPolicies []*ControlPolicy
)
func (cp ControlPolicy) Insert(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
INSERT INTO
controls_mitigations (
control_id,
policy_id,
tenant_id,
created_at
)
VALUES (
@control_id,
@policy_id,
@tenant_id,
@created_at
);
`
args := pgx.StrictNamedArgs{
"control_id": cp.ControlID,
"policy_id": cp.PolicyID,
"tenant_id": scope.GetTenantID(),
"created_at": cp.CreatedAt,
}
_, err := conn.Exec(ctx, q, args)
return err
}
func (cp ControlPolicy) Delete(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
DELETE
FROM
controls_mitigations
WHERE
%s
AND control_id = @control_id
AND policy_id = @policy_id;
`
args := pgx.StrictNamedArgs{
"control_id": cp.ControlID,
"policy_id": cp.PolicyID,
}
maps.Copy(args, scope.SQLArguments())
q = fmt.Sprintf(q, scope.SQLFragment())
_, err := conn.Exec(ctx, q, args)
return err
}

View File

@@ -0,0 +1,7 @@
CREATE TABLE controls_policies (
control_id TEXT NOT NULL REFERENCES controls(id),
policy_id TEXT NOT NULL REFERENCES policies(id),
tenant_id TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
PRIMARY KEY (control_id, policy_id)
);

View File

@@ -271,3 +271,67 @@ RETURNING
return nil
}
func (p *Policies) LoadByControlID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
controlID gid.GID,
cursor *page.Cursor[PolicyOrderField],
) error {
q := `
WITH plcs AS (
SELECT
p.id,
p.tenant_id,
p.organization_id,
p.owner_id,
p.name,
p.content,
p.status,
p.review_date,
p.created_at,
p.updated_at
FROM
policies p
INNER JOIN
controls_policies cp ON p.id = cp.policy_id
WHERE
cp.control_id = @control_id
)
SELECT
id,
tenant_id,
organization_id,
owner_id,
name,
content,
status,
review_date,
created_at,
updated_at
FROM
plcs
WHERE %s
AND %s
`
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.StrictNamedArgs{"control_id": controlID}
maps.Copy(args, scope.SQLArguments())
maps.Copy(args, cursor.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query policies: %w", err)
}
policies, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Policy])
if err != nil {
return fmt.Errorf("cannot collect policies: %w", err)
}
*p = policies
return nil
}

View File

@@ -55,6 +55,27 @@ type (
}
)
func (s ControlService) ListForPolicyID(
ctx context.Context,
policyID gid.GID,
cursor *page.Cursor[coredata.ControlOrderField],
) (*page.Page[*coredata.Control, coredata.ControlOrderField], error) {
var controls coredata.Controls
err := s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
return controls.LoadByPolicyID(ctx, conn, s.svc.scope, policyID, cursor)
},
)
if err != nil {
return nil, fmt.Errorf("cannot list controls: %w", err)
}
return page.NewPage(controls, cursor), nil
}
func (s ControlService) ListForMitigationID(
ctx context.Context,
mitigationID gid.GID,
@@ -76,7 +97,7 @@ func (s ControlService) ListForMitigationID(
return page.NewPage(controls, cursor), nil
}
func (s ControlService) CreateMapping(
func (s ControlService) CreateMitigationMapping(
ctx context.Context,
controlID gid.GID,
mitigationID gid.GID,
@@ -96,7 +117,7 @@ func (s ControlService) CreateMapping(
)
}
func (s ControlService) DeleteMapping(
func (s ControlService) DeleteMitigationMapping(
ctx context.Context,
controlID gid.GID,
mitigationID gid.GID,
@@ -116,6 +137,46 @@ func (s ControlService) DeleteMapping(
)
}
func (s ControlService) CreatePolicyMapping(
ctx context.Context,
controlID gid.GID,
policyID gid.GID,
) error {
controlPolicy := &coredata.ControlPolicy{
ControlID: controlID,
PolicyID: policyID,
TenantID: s.svc.scope.GetTenantID(),
CreatedAt: time.Now(),
}
return s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
return controlPolicy.Insert(ctx, conn, s.svc.scope)
},
)
}
func (s ControlService) DeletePolicyMapping(
ctx context.Context,
controlID gid.GID,
policyID gid.GID,
) error {
controlPolicy := &coredata.ControlPolicy{
ControlID: controlID,
PolicyID: policyID,
TenantID: s.svc.scope.GetTenantID(),
CreatedAt: time.Now(),
}
return s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
return controlPolicy.Delete(ctx, conn, s.svc.scope)
},
)
}
// Create creates a new control
func (s ControlService) Create(
ctx context.Context,

View File

@@ -168,3 +168,24 @@ func (s *PolicyService) ListByOrganizationID(
return page.NewPage(policies, cursor), nil
}
func (s *PolicyService) ListForControlID(
ctx context.Context,
controlID gid.GID,
cursor *page.Cursor[coredata.PolicyOrderField],
) (*page.Page[*coredata.Policy, coredata.PolicyOrderField], error) {
var policies coredata.Policies
err := s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
return policies.LoadByControlID(ctx, conn, s.svc.scope, controlID, cursor)
},
)
if err != nil {
return nil, err
}
return page.NewPage(policies, cursor), nil
}

View File

@@ -448,6 +448,14 @@ type Control implements Node {
orderBy: MitigationOrder
): MitigationConnection! @goField(forceResolver: true)
policies(
first: Int
after: CursorKey
last: Int
before: CursorKey
orderBy: PolicyOrder
): PolicyConnection! @goField(forceResolver: true)
createdAt: Datetime!
updatedAt: Datetime!
}
@@ -530,6 +538,15 @@ type Policy implements Node {
content: String!
reviewDate: Datetime
owner: People! @goField(forceResolver: true)
controls(
first: Int
after: CursorKey
last: Int
before: CursorKey
orderBy: ControlOrder
): ControlConnection! @goField(forceResolver: true)
createdAt: Datetime!
updatedAt: Datetime!
}
@@ -727,12 +744,18 @@ type Mutation {
importMitigation(input: ImportMitigationInput!): ImportMitigationPayload!
# Control mutations
createControlMapping(
input: CreateControlMappingInput!
): CreateControlMappingPayload!
deleteControlMapping(
input: DeleteControlMappingInput!
): DeleteControlMappingPayload!
createControlMitigationMapping(
input: CreateControlMitigationMappingInput!
): CreateControlMitigationMappingPayload!
createControlPolicyMapping(
input: CreateControlPolicyMappingInput!
): CreateControlPolicyMappingPayload!
deleteControlMitigationMapping(
input: DeleteControlMitigationMappingInput!
): DeleteControlMitigationMappingPayload!
deleteControlPolicyMapping(
input: DeleteControlPolicyMappingInput!
): DeleteControlPolicyMappingPayload!
# Task mutations
createTask(input: CreateTaskInput!): CreateTaskPayload!
@@ -897,16 +920,26 @@ input UnassignTaskInput {
taskId: ID!
}
input CreateControlMappingInput {
input CreateControlMitigationMappingInput {
controlId: ID!
mitigationId: ID!
}
input DeleteControlMappingInput {
input CreateControlPolicyMappingInput {
controlId: ID!
policyId: ID!
}
input DeleteControlMitigationMappingInput {
controlId: ID!
mitigationId: ID!
}
input DeleteControlPolicyMappingInput {
controlId: ID!
policyId: ID!
}
input CreateRiskInput {
organizationId: ID!
name: String!
@@ -1088,11 +1121,19 @@ type UnassignTaskPayload {
task: Task!
}
type CreateControlMappingPayload {
type CreateControlMitigationMappingPayload {
success: Boolean!
}
type DeleteControlMappingPayload {
type CreateControlPolicyMappingPayload {
success: Boolean!
}
type DeleteControlMitigationMappingPayload {
success: Boolean!
}
type DeleteControlPolicyMappingPayload {
success: Boolean!
}

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,7 @@ type Control struct {
Name string `json:"name"`
Description string `json:"description"`
Mitigations *MitigationConnection `json:"mitigations"`
Policies *PolicyConnection `json:"policies"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
@@ -59,12 +60,21 @@ type ControlEdge struct {
Node *Control `json:"node"`
}
type CreateControlMappingInput struct {
type CreateControlMitigationMappingInput struct {
ControlID gid.GID `json:"controlId"`
MitigationID gid.GID `json:"mitigationId"`
}
type CreateControlMappingPayload struct {
type CreateControlMitigationMappingPayload struct {
Success bool `json:"success"`
}
type CreateControlPolicyMappingInput struct {
ControlID gid.GID `json:"controlId"`
PolicyID gid.GID `json:"policyId"`
}
type CreateControlPolicyMappingPayload struct {
Success bool `json:"success"`
}
@@ -188,12 +198,21 @@ type CreateVendorPayload struct {
VendorEdge *VendorEdge `json:"vendorEdge"`
}
type DeleteControlMappingInput struct {
type DeleteControlMitigationMappingInput struct {
ControlID gid.GID `json:"controlId"`
MitigationID gid.GID `json:"mitigationId"`
}
type DeleteControlMappingPayload struct {
type DeleteControlMitigationMappingPayload struct {
Success bool `json:"success"`
}
type DeleteControlPolicyMappingInput struct {
ControlID gid.GID `json:"controlId"`
PolicyID gid.GID `json:"policyId"`
}
type DeleteControlPolicyMappingPayload struct {
Success bool `json:"success"`
}
@@ -458,6 +477,7 @@ type Policy struct {
Content string `json:"content"`
ReviewDate *time.Time `json:"reviewDate,omitempty"`
Owner *People `json:"owner"`
Controls *ControlConnection `json:"controls"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}

View File

@@ -44,6 +44,31 @@ func (r *controlResolver) Mitigations(ctx context.Context, obj *types.Control, f
return types.NewMitigationConnection(page), nil
}
// Policies is the resolver for the policies field.
func (r *controlResolver) Policies(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PolicyOrderBy) (*types.PolicyConnection, error) {
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
pageOrderBy := page.OrderBy[coredata.PolicyOrderField]{
Field: coredata.PolicyOrderFieldCreatedAt,
Direction: page.OrderDirectionDesc,
}
if orderBy != nil {
pageOrderBy = page.OrderBy[coredata.PolicyOrderField]{
Field: orderBy.Field,
Direction: orderBy.Direction,
}
}
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
page, err := svc.Policies.ListForControlID(ctx, obj.ID, cursor)
if err != nil {
return nil, fmt.Errorf("cannot list policies: %w", err)
}
return types.NewPolicyConnection(page), nil
}
// FileURL is the resolver for the fileUrl field.
func (r *evidenceResolver) FileURL(ctx context.Context, obj *types.Evidence) (*string, error) {
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
@@ -521,30 +546,58 @@ func (r *mutationResolver) ImportMitigation(ctx context.Context, input types.Imp
}, nil
}
// CreateControlMapping is the resolver for the createControlMapping field.
func (r *mutationResolver) CreateControlMapping(ctx context.Context, input types.CreateControlMappingInput) (*types.CreateControlMappingPayload, error) {
// CreateControlMitigationMapping is the resolver for the createControlMitigationMapping field.
func (r *mutationResolver) CreateControlMitigationMapping(ctx context.Context, input types.CreateControlMitigationMappingInput) (*types.CreateControlMitigationMappingPayload, error) {
svc := r.GetTenantServiceIfAuthorized(ctx, input.MitigationID.TenantID())
err := svc.Controls.CreateMapping(ctx, input.ControlID, input.MitigationID)
err := svc.Controls.CreateMitigationMapping(ctx, input.ControlID, input.MitigationID)
if err != nil {
return nil, fmt.Errorf("cannot create control mapping: %w", err)
panic(fmt.Errorf("cannot create control mitigation mapping: %w", err))
}
return &types.CreateControlMappingPayload{
return &types.CreateControlMitigationMappingPayload{
Success: true,
}, nil
}
// DeleteControlMapping is the resolver for the deleteControlMapping field.
func (r *mutationResolver) DeleteControlMapping(ctx context.Context, input types.DeleteControlMappingInput) (*types.DeleteControlMappingPayload, error) {
svc := r.GetTenantServiceIfAuthorized(ctx, input.MitigationID.TenantID())
// CreateControlPolicyMapping is the resolver for the createControlPolicyMapping field.
func (r *mutationResolver) CreateControlPolicyMapping(ctx context.Context, input types.CreateControlPolicyMappingInput) (*types.CreateControlPolicyMappingPayload, error) {
svc := r.GetTenantServiceIfAuthorized(ctx, input.PolicyID.TenantID())
err := svc.Controls.DeleteMapping(ctx, input.ControlID, input.MitigationID)
err := svc.Controls.CreatePolicyMapping(ctx, input.ControlID, input.PolicyID)
if err != nil {
return nil, fmt.Errorf("cannot delete control mapping: %w", err)
panic(fmt.Errorf("cannot create control policy mapping: %w", err))
}
return &types.DeleteControlMappingPayload{
return &types.CreateControlPolicyMappingPayload{
Success: true,
}, nil
}
// DeleteControlMitigationMapping is the resolver for the deleteControlMitigationMapping field.
func (r *mutationResolver) DeleteControlMitigationMapping(ctx context.Context, input types.DeleteControlMitigationMappingInput) (*types.DeleteControlMitigationMappingPayload, error) {
svc := r.GetTenantServiceIfAuthorized(ctx, input.MitigationID.TenantID())
err := svc.Controls.DeleteMitigationMapping(ctx, input.ControlID, input.MitigationID)
if err != nil {
panic(fmt.Errorf("cannot delete control mitigation mapping: %w", err))
}
return &types.DeleteControlMitigationMappingPayload{
Success: true,
}, nil
}
// DeleteControlPolicyMapping is the resolver for the deleteControlPolicyMapping field.
func (r *mutationResolver) DeleteControlPolicyMapping(ctx context.Context, input types.DeleteControlPolicyMappingInput) (*types.DeleteControlPolicyMappingPayload, error) {
svc := r.GetTenantServiceIfAuthorized(ctx, input.PolicyID.TenantID())
err := svc.Controls.DeletePolicyMapping(ctx, input.ControlID, input.PolicyID)
if err != nil {
panic(fmt.Errorf("cannot delete control policy mapping: %w", err))
}
return &types.DeleteControlPolicyMappingPayload{
Success: true,
}, nil
}
@@ -1067,6 +1120,31 @@ func (r *policyResolver) Owner(ctx context.Context, obj *types.Policy) (*types.P
return types.NewPeople(owner), nil
}
// Controls is the resolver for the controls field.
func (r *policyResolver) Controls(ctx context.Context, obj *types.Policy, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ControlOrderBy) (*types.ControlConnection, error) {
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
pageOrderBy := page.OrderBy[coredata.ControlOrderField]{
Field: coredata.ControlOrderFieldCreatedAt,
Direction: page.OrderDirectionDesc,
}
if orderBy != nil {
pageOrderBy = page.OrderBy[coredata.ControlOrderField]{
Field: orderBy.Field,
Direction: orderBy.Direction,
}
}
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
page, err := svc.Controls.ListForPolicyID(ctx, obj.ID, cursor)
if err != nil {
panic(fmt.Errorf("cannot list policy controls: %w", err))
}
return types.NewControlConnection(page), nil
}
// Node is the resolver for the node field.
func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error) {
svc := r.GetTenantServiceIfAuthorized(ctx, id.TenantID())