@@ -63,38 +63,22 @@ func (c *Control) LoadByID(
|
|||||||
controlID gid.GID,
|
controlID gid.GID,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
WITH control_states AS (
|
|
||||||
SELECT
|
|
||||||
control_id,
|
|
||||||
to_state,
|
|
||||||
reason,
|
|
||||||
RANK() OVER w
|
|
||||||
FROM
|
|
||||||
control_state_transitions
|
|
||||||
WHERE
|
|
||||||
control_id = @control_id
|
|
||||||
WINDOW
|
|
||||||
w AS (PARTITION BY control_id ORDER BY created_at DESC)
|
|
||||||
)
|
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
framework_id,
|
framework_id,
|
||||||
category,
|
category,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
cs.to_state AS state,
|
state,
|
||||||
content_ref,
|
content_ref,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
version
|
version
|
||||||
FROM
|
FROM
|
||||||
controls
|
controls
|
||||||
INNER JOIN
|
|
||||||
control_states cs ON cs.control_id = controls.id
|
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND id = @control_id
|
AND id = @control_id
|
||||||
AND cs.rank = 1
|
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -131,6 +115,7 @@ INSERT INTO
|
|||||||
framework_id,
|
framework_id,
|
||||||
category,
|
category,
|
||||||
name,
|
name,
|
||||||
|
state,
|
||||||
description,
|
description,
|
||||||
content_ref,
|
content_ref,
|
||||||
created_at,
|
created_at,
|
||||||
@@ -143,6 +128,7 @@ VALUES (
|
|||||||
@framework_id,
|
@framework_id,
|
||||||
@category,
|
@category,
|
||||||
@name,
|
@name,
|
||||||
|
@state,
|
||||||
@description,
|
@description,
|
||||||
@content_ref,
|
@content_ref,
|
||||||
@created_at,
|
@created_at,
|
||||||
@@ -162,6 +148,7 @@ VALUES (
|
|||||||
"content_ref": c.ContentRef,
|
"content_ref": c.ContentRef,
|
||||||
"created_at": c.CreatedAt,
|
"created_at": c.CreatedAt,
|
||||||
"updated_at": c.UpdatedAt,
|
"updated_at": c.UpdatedAt,
|
||||||
|
"state": c.State,
|
||||||
}
|
}
|
||||||
_, err := conn.Exec(ctx, q, args)
|
_, err := conn.Exec(ctx, q, args)
|
||||||
return err
|
return err
|
||||||
@@ -175,36 +162,22 @@ func (c *Controls) LoadByFrameworkID(
|
|||||||
cursor *page.Cursor,
|
cursor *page.Cursor,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
WITH control_states AS (
|
|
||||||
SELECT
|
|
||||||
control_id,
|
|
||||||
to_state,
|
|
||||||
reason,
|
|
||||||
RANK() OVER w
|
|
||||||
FROM
|
|
||||||
control_state_transitions
|
|
||||||
WINDOW
|
|
||||||
w AS (PARTITION BY control_id ORDER BY created_at DESC)
|
|
||||||
)
|
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
framework_id,
|
framework_id,
|
||||||
category,
|
category,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
cs.to_state AS state,
|
state,
|
||||||
content_ref,
|
content_ref,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
version
|
version
|
||||||
FROM
|
FROM
|
||||||
controls
|
controls
|
||||||
INNER JOIN
|
|
||||||
control_states cs ON cs.control_id = controls.id
|
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND framework_id = @framework_id
|
AND framework_id = @framework_id
|
||||||
AND cs.rank = 1
|
|
||||||
AND %s
|
AND %s
|
||||||
`
|
`
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||||
@@ -235,21 +208,11 @@ func (c *Control) Update(
|
|||||||
params UpdateControlParams,
|
params UpdateControlParams,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
WITH control_states AS (
|
|
||||||
SELECT
|
|
||||||
control_id,
|
|
||||||
to_state,
|
|
||||||
reason,
|
|
||||||
RANK() OVER w
|
|
||||||
FROM
|
|
||||||
control_state_transitions
|
|
||||||
WINDOW
|
|
||||||
w AS (PARTITION BY control_id ORDER BY created_at DESC)
|
|
||||||
)
|
|
||||||
UPDATE controls SET
|
UPDATE controls SET
|
||||||
name = COALESCE(@name, name),
|
name = COALESCE(@name, name),
|
||||||
description = COALESCE(@description, description),
|
description = COALESCE(@description, description),
|
||||||
category = COALESCE(@category, category),
|
category = COALESCE(@category, category),
|
||||||
|
state = COALESCE(@state, state),
|
||||||
updated_at = @updated_at,
|
updated_at = @updated_at,
|
||||||
version = version + 1
|
version = version + 1
|
||||||
WHERE %s
|
WHERE %s
|
||||||
@@ -261,7 +224,7 @@ RETURNING
|
|||||||
category,
|
category,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
(SELECT to_state FROM control_states WHERE control_id = controls.id AND rank = 1) AS state,
|
state,
|
||||||
content_ref,
|
content_ref,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
@@ -269,12 +232,14 @@ RETURNING
|
|||||||
`
|
`
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
args := pgx.NamedArgs{
|
||||||
"control_id": c.ID,
|
"control_id": c.ID,
|
||||||
"expected_version": params.ExpectedVersion,
|
"expected_version": params.ExpectedVersion,
|
||||||
"updated_at": time.Now(),
|
"updated_at": time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
if params.Name != nil {
|
if params.Name != nil {
|
||||||
args["name"] = *params.Name
|
args["name"] = *params.Name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,128 +0,0 @@
|
|||||||
// 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"
|
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
|
||||||
"github.com/getprobo/probo/pkg/page"
|
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"go.gearno.de/kit/pg"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
ControlStateTransition struct {
|
|
||||||
StateTransition[ControlState]
|
|
||||||
|
|
||||||
ControlID gid.GID `db:"control_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
ControlStateTransitions []*ControlStateTransition
|
|
||||||
)
|
|
||||||
|
|
||||||
func (cst ControlStateTransition) CursorKey() page.CursorKey {
|
|
||||||
return page.NewCursorKey(cst.ID, cst.CreatedAt)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cst ControlStateTransition) Insert(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
INSERT INTO
|
|
||||||
control_state_transitions (
|
|
||||||
tenant_id,
|
|
||||||
id,
|
|
||||||
control_id,
|
|
||||||
from_state,
|
|
||||||
to_state,
|
|
||||||
reason,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
)
|
|
||||||
VALUES (
|
|
||||||
@tenant_id,
|
|
||||||
@control_state_transition_id,
|
|
||||||
@control_id,
|
|
||||||
@from_state,
|
|
||||||
@to_state,
|
|
||||||
@reason,
|
|
||||||
@created_at,
|
|
||||||
@updated_at
|
|
||||||
);
|
|
||||||
`
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
|
||||||
"tenant_id": scope.GetTenantID(),
|
|
||||||
"control_state_transition_id": cst.ID,
|
|
||||||
"control_id": cst.ControlID,
|
|
||||||
"from_state": cst.FromState,
|
|
||||||
"to_state": cst.ToState,
|
|
||||||
"reason": cst.Reason,
|
|
||||||
"created_at": cst.CreatedAt,
|
|
||||||
"updated_at": cst.UpdatedAt,
|
|
||||||
}
|
|
||||||
_, err := conn.Exec(ctx, q, args)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cst *ControlStateTransitions) LoadByControlID(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
controlID gid.GID,
|
|
||||||
cursor *page.Cursor,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
tenant_id,
|
|
||||||
control_id,
|
|
||||||
from_state,
|
|
||||||
to_state,
|
|
||||||
reason,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
FROM
|
|
||||||
control_state_transitions
|
|
||||||
WHERE
|
|
||||||
%s
|
|
||||||
AND control_id = @control_id
|
|
||||||
AND %s
|
|
||||||
`
|
|
||||||
|
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{"control_id": controlID}
|
|
||||||
maps.Copy(args, scope.SQLArguments())
|
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot query control state transitions: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
controlStateTransitions, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlStateTransition])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot collect control state transitions: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
*cst = controlStateTransitions
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -162,22 +162,10 @@ func (e *Evidences) LoadByTaskID(
|
|||||||
cursor *page.Cursor,
|
cursor *page.Cursor,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
WITH
|
|
||||||
evidence_states AS (
|
|
||||||
SELECT
|
|
||||||
evidence_id,
|
|
||||||
to_state AS state,
|
|
||||||
reason,
|
|
||||||
RANK() OVER w
|
|
||||||
FROM
|
|
||||||
evidence_state_transitions
|
|
||||||
WINDOW
|
|
||||||
w AS (PARTITION BY evidence_id ORDER BY created_at DESC)
|
|
||||||
)
|
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
task_id,
|
task_id,
|
||||||
es.state,
|
state,
|
||||||
object_key,
|
object_key,
|
||||||
mime_type,
|
mime_type,
|
||||||
size,
|
size,
|
||||||
@@ -186,12 +174,9 @@ SELECT
|
|||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
evidences
|
evidences
|
||||||
INNER JOIN
|
|
||||||
evidence_states es ON es.evidence_id = evidences.id
|
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND task_id = @task_id
|
AND task_id = @task_id
|
||||||
AND es.rank = 1
|
|
||||||
AND %s
|
AND %s
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
// 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"
|
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
|
||||||
"github.com/getprobo/probo/pkg/page"
|
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"go.gearno.de/kit/pg"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
EvidenceStateTransition struct {
|
|
||||||
StateTransition[EvidenceState]
|
|
||||||
|
|
||||||
EvidenceID gid.GID `db:"evidence_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
EvidenceStateTransitions []*EvidenceStateTransition
|
|
||||||
)
|
|
||||||
|
|
||||||
func (cst EvidenceStateTransition) CursorKey() page.CursorKey {
|
|
||||||
return page.NewCursorKey(cst.ID, cst.CreatedAt)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (est EvidenceStateTransition) Insert(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
INSERT INTO
|
|
||||||
evidence_state_transitions (
|
|
||||||
tenant_id,
|
|
||||||
id,
|
|
||||||
evidence_id,
|
|
||||||
from_state,
|
|
||||||
to_state,
|
|
||||||
reason,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
)
|
|
||||||
VALUES (
|
|
||||||
@tenant_id,
|
|
||||||
@evidence_state_transition_id,
|
|
||||||
@evidence_id,
|
|
||||||
@from_state,
|
|
||||||
@to_state,
|
|
||||||
@reason,
|
|
||||||
@created_at,
|
|
||||||
@updated_at
|
|
||||||
);
|
|
||||||
`
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
|
||||||
"tenant_id": scope.GetTenantID(),
|
|
||||||
"evidence_state_transition_id": est.ID,
|
|
||||||
"evidence_id": est.EvidenceID,
|
|
||||||
"from_state": est.FromState,
|
|
||||||
"to_state": est.ToState,
|
|
||||||
"reason": est.Reason,
|
|
||||||
"created_at": est.CreatedAt,
|
|
||||||
"updated_at": est.UpdatedAt,
|
|
||||||
}
|
|
||||||
_, err := conn.Exec(ctx, q, args)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cst *EvidenceStateTransitions) LoadByEvidenceID(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
evidenceID gid.GID,
|
|
||||||
cursor *page.Cursor,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
evidence_id,
|
|
||||||
from_state,
|
|
||||||
to_state,
|
|
||||||
reason,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
FROM
|
|
||||||
evidence_state_transitions
|
|
||||||
WHERE
|
|
||||||
%s
|
|
||||||
AND evidence_id = @evidence_id
|
|
||||||
AND %s
|
|
||||||
`
|
|
||||||
|
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{"evidence_id": evidenceID}
|
|
||||||
maps.Copy(args, scope.SQLArguments())
|
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot query evidence state transitions: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
evidenceStateTransitions, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[EvidenceStateTransition])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot collect evidence state transitions: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
*cst = evidenceStateTransitions
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cst *EvidenceStateTransitions) DeleteForEvidenceID(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
evidenceID gid.GID,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
DELETE FROM
|
|
||||||
evidence_state_transitions
|
|
||||||
WHERE
|
|
||||||
%s
|
|
||||||
AND evidence_id = @evidence_id
|
|
||||||
`
|
|
||||||
|
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{"evidence_id": evidenceID}
|
|
||||||
maps.Copy(args, scope.SQLArguments())
|
|
||||||
|
|
||||||
_, err := conn.Exec(ctx, q, args)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
17
pkg/probo/coredata/migrations/20250310T161900Z.sql
Normal file
17
pkg/probo/coredata/migrations/20250310T161900Z.sql
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
DROP TABLE control_state_transitions;
|
||||||
|
DROP TABLE evidence_state_transitions;
|
||||||
|
DROP TABLE task_state_transitions;
|
||||||
|
|
||||||
|
ALTER TABLE tasks ADD COLUMN control_id TEXT;
|
||||||
|
|
||||||
|
UPDATE tasks
|
||||||
|
SET control_id = controls_tasks.control_id
|
||||||
|
FROM controls_tasks
|
||||||
|
WHERE tasks.id = controls_tasks.task_id;
|
||||||
|
|
||||||
|
ALTER TABLE tasks ALTER COLUMN control_id SET NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE tasks ADD CONSTRAINT fk_tasks_control_id
|
||||||
|
FOREIGN KEY (control_id) REFERENCES controls(id) ON DELETE CASCADE;
|
||||||
|
|
||||||
|
DROP TABLE controls_tasks;
|
||||||
3
pkg/probo/coredata/migrations/20250310T164900Z.sql
Normal file
3
pkg/probo/coredata/migrations/20250310T164900Z.sql
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE controls ADD COLUMN state control_state;
|
||||||
|
ALTER TABLE evidences ADD COLUMN state evidence_state;
|
||||||
|
ALTER TABLE tasks ADD COLUMN state task_state;
|
||||||
1
pkg/probo/coredata/migrations/20250310T181100Z.sql
Normal file
1
pkg/probo/coredata/migrations/20250310T181100Z.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE tasks ADD COLUMN version INTEGER NOT NULL DEFAULT 1;
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
//
|
|
||||||
// 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 (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
StateTransition[T any] struct {
|
|
||||||
ID gid.GID `db:"id"`
|
|
||||||
ToState T `db:"to_state"`
|
|
||||||
FromState *T `db:"from_state"`
|
|
||||||
Reason *string `db:"reason"`
|
|
||||||
CreatedAt time.Time `db:"created_at"`
|
|
||||||
UpdatedAt time.Time `db:"updated_at"`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@@ -37,9 +37,17 @@ type (
|
|||||||
ContentRef string `db:"content_ref"`
|
ContentRef string `db:"content_ref"`
|
||||||
CreatedAt time.Time `db:"created_at"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
UpdatedAt time.Time `db:"updated_at"`
|
UpdatedAt time.Time `db:"updated_at"`
|
||||||
|
Version int `db:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
Tasks []*Task
|
Tasks []*Task
|
||||||
|
|
||||||
|
UpdateTaskParams struct {
|
||||||
|
ExpectedVersion int
|
||||||
|
Name *string
|
||||||
|
Description *string
|
||||||
|
State *TaskState
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t Task) CursorKey() page.CursorKey {
|
func (t Task) CursorKey() page.CursorKey {
|
||||||
@@ -53,58 +61,27 @@ func (t *Task) LoadByID(
|
|||||||
taskID gid.GID,
|
taskID gid.GID,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
WITH
|
|
||||||
control_tasks AS (
|
|
||||||
SELECT
|
|
||||||
t.id,
|
|
||||||
ct.control_id AS control_id,
|
|
||||||
t.name,
|
|
||||||
t.description,
|
|
||||||
t.content_ref,
|
|
||||||
t.created_at,
|
|
||||||
t.updated_at
|
|
||||||
FROM
|
|
||||||
tasks t
|
|
||||||
INNER JOIN
|
|
||||||
controls_tasks ct ON
|
|
||||||
ct.task_id = t.id
|
|
||||||
WHERE
|
|
||||||
t.tenant_id = @tenant_id
|
|
||||||
AND id = @task_id
|
|
||||||
),
|
|
||||||
task_states AS (
|
|
||||||
SELECT
|
|
||||||
task_id,
|
|
||||||
to_state AS state,
|
|
||||||
reason,
|
|
||||||
RANK() OVER w
|
|
||||||
FROM
|
|
||||||
task_state_transitions
|
|
||||||
WHERE
|
|
||||||
task_id = @task_id
|
|
||||||
WINDOW
|
|
||||||
w AS (PARTITION BY task_id ORDER BY created_at DESC)
|
|
||||||
)
|
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
control_id,
|
control_id,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
ts.state AS state,
|
state,
|
||||||
content_ref,
|
content_ref,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at,
|
||||||
|
version
|
||||||
FROM
|
FROM
|
||||||
control_tasks
|
tasks
|
||||||
INNER JOIN
|
|
||||||
task_states ts ON ts.task_id = control_tasks.id
|
|
||||||
WHERE
|
WHERE
|
||||||
ts.rank = 1
|
%s
|
||||||
AND id = @task_id
|
AND task_id = @task_id
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`
|
`
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{"tenant_id": scope.GetTenantID(), "task_id": taskID}
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{"task_id": taskID}
|
||||||
maps.Copy(args, scope.SQLArguments())
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows, err := conn.Query(ctx, q, args)
|
||||||
@@ -128,38 +105,29 @@ func (t Task) Insert(
|
|||||||
scope Scoper,
|
scope Scoper,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
WITH task_insert AS (
|
INSERT INTO tasks (
|
||||||
INSERT INTO tasks (
|
tenant_id,
|
||||||
tenant_id,
|
id,
|
||||||
id,
|
name,
|
||||||
name,
|
control_id,
|
||||||
description,
|
description,
|
||||||
content_ref,
|
content_ref,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at,
|
||||||
)
|
version,
|
||||||
VALUES (
|
state
|
||||||
@tenant_id,
|
|
||||||
@task_id,
|
|
||||||
@name,
|
|
||||||
@description,
|
|
||||||
@content_ref,
|
|
||||||
@created_at,
|
|
||||||
@updated_at
|
|
||||||
)
|
|
||||||
RETURNING id
|
|
||||||
)
|
|
||||||
INSERT INTO controls_tasks (
|
|
||||||
task_id,
|
|
||||||
tenant_id,
|
|
||||||
control_id,
|
|
||||||
created_at
|
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
(SELECT id FROM task_insert),
|
@tenant_id,
|
||||||
@tenant_id,
|
@task_id,
|
||||||
@control_id,
|
@name,
|
||||||
@created_at
|
@control_id,
|
||||||
|
@description,
|
||||||
|
@content_ref,
|
||||||
|
@created_at,
|
||||||
|
@updated_at,
|
||||||
|
@version,
|
||||||
|
@state
|
||||||
);
|
);
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -172,6 +140,8 @@ VALUES (
|
|||||||
"content_ref": t.ContentRef,
|
"content_ref": t.ContentRef,
|
||||||
"created_at": t.CreatedAt,
|
"created_at": t.CreatedAt,
|
||||||
"updated_at": t.UpdatedAt,
|
"updated_at": t.UpdatedAt,
|
||||||
|
"version": t.Version,
|
||||||
|
"state": t.State,
|
||||||
}
|
}
|
||||||
_, err := conn.Exec(ctx, q, args)
|
_, err := conn.Exec(ctx, q, args)
|
||||||
return err
|
return err
|
||||||
@@ -185,57 +155,27 @@ func (t *Tasks) LoadByControlID(
|
|||||||
cursor *page.Cursor,
|
cursor *page.Cursor,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
WITH
|
|
||||||
control_tasks AS (
|
|
||||||
SELECT
|
|
||||||
t.id,
|
|
||||||
@control_id AS control_id,
|
|
||||||
t.name,
|
|
||||||
t.description,
|
|
||||||
t.content_ref,
|
|
||||||
t.created_at,
|
|
||||||
t.updated_at
|
|
||||||
FROM
|
|
||||||
tasks t
|
|
||||||
INNER JOIN
|
|
||||||
controls_tasks ct ON
|
|
||||||
ct.task_id = t.id
|
|
||||||
AND ct.control_id = @control_id
|
|
||||||
WHERE
|
|
||||||
t.tenant_id = @tenant_id
|
|
||||||
),
|
|
||||||
task_states AS (
|
|
||||||
SELECT
|
|
||||||
task_id,
|
|
||||||
to_state AS state,
|
|
||||||
reason,
|
|
||||||
RANK() OVER w
|
|
||||||
FROM
|
|
||||||
task_state_transitions
|
|
||||||
WINDOW
|
|
||||||
w AS (PARTITION BY task_id ORDER BY created_at DESC)
|
|
||||||
)
|
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
control_id,
|
control_id,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
ts.state AS state,
|
state,
|
||||||
content_ref,
|
content_ref,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at,
|
||||||
|
version
|
||||||
FROM
|
FROM
|
||||||
control_tasks
|
tasks
|
||||||
INNER JOIN
|
|
||||||
task_states ts ON ts.task_id = control_tasks.id
|
|
||||||
WHERE
|
WHERE
|
||||||
ts.rank = 1
|
%s
|
||||||
|
AND control_id = @control_id
|
||||||
AND %s
|
AND %s
|
||||||
`
|
`
|
||||||
|
|
||||||
q = fmt.Sprintf(q, cursor.SQLFragment())
|
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{"tenant_id": scope.GetTenantID(), "control_id": controlID}
|
args := pgx.StrictNamedArgs{"control_id": controlID}
|
||||||
maps.Copy(args, scope.SQLArguments())
|
maps.Copy(args, scope.SQLArguments())
|
||||||
maps.Copy(args, cursor.SQLArguments())
|
maps.Copy(args, cursor.SQLArguments())
|
||||||
|
|
||||||
@@ -254,6 +194,43 @@ WHERE
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Task) Update(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
params UpdateTaskParams,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
UPDATE tasks
|
||||||
|
SET
|
||||||
|
name = COALESCE(@name, name),
|
||||||
|
description = COALESCE(@description, description),
|
||||||
|
state = COALESCE(@state, state),
|
||||||
|
updated_at = @updated_at,
|
||||||
|
version = version + 1
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND id = @task_id
|
||||||
|
AND version = @expected_version
|
||||||
|
RETURNING
|
||||||
|
version;
|
||||||
|
`
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"task_id": t.ID,
|
||||||
|
"expected_version": params.ExpectedVersion,
|
||||||
|
"name": params.Name,
|
||||||
|
"description": params.Description,
|
||||||
|
"state": params.State,
|
||||||
|
"updated_at": time.Now(),
|
||||||
|
}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
err := conn.QueryRow(ctx, q, args).Scan(&t.Version)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Task) Delete(
|
func (t *Task) Delete(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Conn,
|
conn pg.Conn,
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
// 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"
|
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
|
||||||
"github.com/getprobo/probo/pkg/page"
|
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"go.gearno.de/kit/pg"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
TaskStateTransition struct {
|
|
||||||
StateTransition[TaskState]
|
|
||||||
TaskID gid.GID `db:"task_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
TaskStateTransitions []*TaskStateTransition
|
|
||||||
)
|
|
||||||
|
|
||||||
func (tst TaskStateTransition) CursorKey() page.CursorKey {
|
|
||||||
return page.NewCursorKey(tst.ID, tst.CreatedAt)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tst TaskStateTransition) Insert(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
INSERT INTO
|
|
||||||
task_state_transitions (
|
|
||||||
tenant_id,
|
|
||||||
id,
|
|
||||||
task_id,
|
|
||||||
from_state,
|
|
||||||
to_state,
|
|
||||||
reason,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
)
|
|
||||||
VALUES (
|
|
||||||
@tenant_id,
|
|
||||||
@task_state_transition_id,
|
|
||||||
@task_id,
|
|
||||||
@from_state,
|
|
||||||
@to_state,
|
|
||||||
@reason,
|
|
||||||
@created_at,
|
|
||||||
@updated_at
|
|
||||||
);
|
|
||||||
`
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
|
||||||
"tenant_id": scope.GetTenantID(),
|
|
||||||
"task_state_transition_id": tst.ID,
|
|
||||||
"task_id": tst.TaskID,
|
|
||||||
"from_state": tst.FromState,
|
|
||||||
"to_state": tst.ToState,
|
|
||||||
"reason": tst.Reason,
|
|
||||||
"created_at": tst.CreatedAt,
|
|
||||||
"updated_at": tst.UpdatedAt,
|
|
||||||
}
|
|
||||||
_, err := conn.Exec(ctx, q, args)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tst *TaskStateTransitions) LoadByTaskID(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
taskID gid.GID,
|
|
||||||
cursor *page.Cursor,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
task_id,
|
|
||||||
from_state,
|
|
||||||
to_state,
|
|
||||||
reason,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
FROM
|
|
||||||
task_state_transitions
|
|
||||||
WHERE
|
|
||||||
%s
|
|
||||||
AND task_id = @task_id
|
|
||||||
AND %s
|
|
||||||
`
|
|
||||||
|
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{"task_id": taskID}
|
|
||||||
maps.Copy(args, scope.SQLArguments())
|
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot query task state transitions: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
taskStateTransitions, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[TaskStateTransition])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot collect task state transitions: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
*tst = taskStateTransitions
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gearno.de/ref"
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
"github.com/getprobo/probo/pkg/probo/coredata"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
@@ -44,10 +43,6 @@ func (s Service) CreateControl(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create control global id: %w", err)
|
return nil, fmt.Errorf("cannot create control global id: %w", err)
|
||||||
}
|
}
|
||||||
controlStateTransitionID, err := gid.NewGID(s.scope.GetTenantID(), coredata.ControlStateTransitionEntityType)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot create control state transition global id: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
framework := &coredata.Framework{}
|
framework := &coredata.Framework{}
|
||||||
control := &coredata.Control{
|
control := &coredata.Control{
|
||||||
@@ -62,18 +57,6 @@ func (s Service) CreateControl(
|
|||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
controlStateTransition := coredata.ControlStateTransition{
|
|
||||||
StateTransition: coredata.StateTransition[coredata.ControlState]{
|
|
||||||
ID: controlStateTransitionID,
|
|
||||||
FromState: nil,
|
|
||||||
ToState: control.State,
|
|
||||||
Reason: ref.Ref("Initial state"),
|
|
||||||
CreatedAt: now,
|
|
||||||
UpdatedAt: now,
|
|
||||||
},
|
|
||||||
ControlID: control.ID,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = s.pg.WithTx(
|
err = s.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
@@ -85,10 +68,6 @@ func (s Service) CreateControl(
|
|||||||
return fmt.Errorf("cannot insert control: %w", err)
|
return fmt.Errorf("cannot insert control: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := controlStateTransition.Insert(ctx, conn, s.scope); err != nil {
|
|
||||||
return fmt.Errorf("cannot insert control state transition: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gearno.de/ref"
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
@@ -48,10 +47,6 @@ func (s Service) CreateEvidence(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create evidence global id: %w", err)
|
return nil, fmt.Errorf("cannot create evidence global id: %w", err)
|
||||||
}
|
}
|
||||||
evidenceStateTransitionID, err := gid.NewGID(s.scope.GetTenantID(), coredata.EvidenceStateTransitionEntityType)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot create evidence state transition: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
contentType := "application/octet-stream"
|
contentType := "application/octet-stream"
|
||||||
if req.Name != "" {
|
if req.Name != "" {
|
||||||
@@ -98,18 +93,6 @@ func (s Service) CreateEvidence(
|
|||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
evidenceStateTransition := coredata.EvidenceStateTransition{
|
|
||||||
StateTransition: coredata.StateTransition[coredata.EvidenceState]{
|
|
||||||
ID: evidenceStateTransitionID,
|
|
||||||
FromState: nil,
|
|
||||||
ToState: evidence.State,
|
|
||||||
Reason: ref.Ref("Initial state"),
|
|
||||||
CreatedAt: now,
|
|
||||||
UpdatedAt: now,
|
|
||||||
},
|
|
||||||
EvidenceID: evidence.ID,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = s.pg.WithTx(
|
err = s.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
@@ -121,10 +104,6 @@ func (s Service) CreateEvidence(
|
|||||||
return fmt.Errorf("cannot insert evidence: %w", err)
|
return fmt.Errorf("cannot insert evidence: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := evidenceStateTransition.Insert(ctx, conn, s.scope); err != nil {
|
|
||||||
return fmt.Errorf("cannot insert evidence state transition: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gearno.de/ref"
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
"github.com/getprobo/probo/pkg/probo/coredata"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
@@ -43,10 +42,6 @@ func (s Service) CreateTask(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create task global id: %w", err)
|
return nil, fmt.Errorf("cannot create task global id: %w", err)
|
||||||
}
|
}
|
||||||
taskStateTransitionID, err := gid.NewGID(s.scope.GetTenantID(), coredata.TaskStateTransitionEntityType)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot create task state transition global id: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
control := &coredata.Control{}
|
control := &coredata.Control{}
|
||||||
task := &coredata.Task{
|
task := &coredata.Task{
|
||||||
@@ -54,24 +49,12 @@ func (s Service) CreateTask(
|
|||||||
ControlID: req.ControlID,
|
ControlID: req.ControlID,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
ContentRef: req.ContentRef,
|
ContentRef: req.ContentRef,
|
||||||
Description: req.Description,
|
|
||||||
State: coredata.TaskStateTodo,
|
State: coredata.TaskStateTodo,
|
||||||
|
Description: req.Description,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
taskStateTransition := coredata.TaskStateTransition{
|
|
||||||
StateTransition: coredata.StateTransition[coredata.TaskState]{
|
|
||||||
ID: taskStateTransitionID,
|
|
||||||
FromState: nil,
|
|
||||||
ToState: task.State,
|
|
||||||
Reason: ref.Ref("Initial state"),
|
|
||||||
CreatedAt: now,
|
|
||||||
UpdatedAt: now,
|
|
||||||
},
|
|
||||||
TaskID: task.ID,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = s.pg.WithTx(
|
err = s.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
@@ -83,10 +66,6 @@ func (s Service) CreateTask(
|
|||||||
return fmt.Errorf("cannot insert task: %w", err)
|
return fmt.Errorf("cannot insert task: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := taskStateTransition.Insert(ctx, conn, s.scope); err != nil {
|
|
||||||
return fmt.Errorf("cannot insert task state transition: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,16 +27,11 @@ func (s *Service) DeleteEvidence(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
evidenceID gid.GID,
|
evidenceID gid.GID,
|
||||||
) error {
|
) error {
|
||||||
evidenceStateTransitions := &coredata.EvidenceStateTransitions{}
|
|
||||||
evidence := &coredata.Evidence{ID: evidenceID}
|
evidence := &coredata.Evidence{ID: evidenceID}
|
||||||
|
|
||||||
return s.pg.WithTx(
|
return s.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
if err := evidenceStateTransitions.DeleteForEvidenceID(ctx, conn, s.scope, evidenceID); err != nil {
|
|
||||||
return fmt.Errorf("cannot delete evidence state transitions: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := evidence.Delete(ctx, conn, s.scope); err != nil {
|
if err := evidence.Delete(ctx, conn, s.scope); err != nil {
|
||||||
return fmt.Errorf("cannot delete evidence: %w", err)
|
return fmt.Errorf("cannot delete evidence: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
// 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 probo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
|
||||||
"github.com/getprobo/probo/pkg/page"
|
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
|
||||||
"go.gearno.de/kit/pg"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s Service) ListControlStateTransitions(
|
|
||||||
ctx context.Context,
|
|
||||||
controlID gid.GID,
|
|
||||||
cursor *page.Cursor,
|
|
||||||
) (*page.Page[*coredata.ControlStateTransition], error) {
|
|
||||||
var controlStateTransitions coredata.ControlStateTransitions
|
|
||||||
|
|
||||||
err := s.pg.WithConn(
|
|
||||||
ctx,
|
|
||||||
func(conn pg.Conn) error {
|
|
||||||
return controlStateTransitions.LoadByControlID(
|
|
||||||
ctx,
|
|
||||||
conn,
|
|
||||||
s.scope,
|
|
||||||
controlID,
|
|
||||||
cursor,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return page.NewPage(controlStateTransitions, cursor), nil
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
// 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 probo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
|
||||||
"github.com/getprobo/probo/pkg/page"
|
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
|
||||||
"go.gearno.de/kit/pg"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s Service) ListTaskStateTransitions(
|
|
||||||
ctx context.Context,
|
|
||||||
taskID gid.GID,
|
|
||||||
cursor *page.Cursor,
|
|
||||||
) (*page.Page[*coredata.TaskStateTransition], error) {
|
|
||||||
var taskStateTransitions coredata.TaskStateTransitions
|
|
||||||
|
|
||||||
err := s.pg.WithConn(
|
|
||||||
ctx,
|
|
||||||
func(conn pg.Conn) error {
|
|
||||||
return taskStateTransitions.LoadByTaskID(
|
|
||||||
ctx,
|
|
||||||
conn,
|
|
||||||
s.scope,
|
|
||||||
taskID,
|
|
||||||
cursor,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return page.NewPage(taskStateTransitions, cursor), nil
|
|
||||||
}
|
|
||||||
@@ -18,34 +18,39 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
"github.com/getprobo/probo/pkg/page"
|
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
"github.com/getprobo/probo/pkg/probo/coredata"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s Service) ListEvidenceStateTransitions(
|
type UpdateTaskRequest struct {
|
||||||
ctx context.Context,
|
ID gid.GID
|
||||||
evidenceID gid.GID,
|
ExpectedVersion int
|
||||||
cursor *page.Cursor,
|
Name *string
|
||||||
) (*page.Page[*coredata.EvidenceStateTransition], error) {
|
Description *string
|
||||||
var evidenceStateTransitions coredata.EvidenceStateTransitions
|
State *coredata.TaskState
|
||||||
|
}
|
||||||
|
|
||||||
err := s.pg.WithConn(
|
func (s Service) UpdateTask(
|
||||||
|
ctx context.Context,
|
||||||
|
req UpdateTaskRequest,
|
||||||
|
) (*coredata.Task, error) {
|
||||||
|
params := coredata.UpdateTaskParams{
|
||||||
|
ExpectedVersion: req.ExpectedVersion,
|
||||||
|
Name: req.Name,
|
||||||
|
Description: req.Description,
|
||||||
|
State: req.State,
|
||||||
|
}
|
||||||
|
|
||||||
|
task := &coredata.Task{ID: req.ID}
|
||||||
|
|
||||||
|
err := s.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
return evidenceStateTransitions.LoadByEvidenceID(
|
return task.Update(ctx, conn, s.scope, params)
|
||||||
ctx,
|
})
|
||||||
conn,
|
|
||||||
s.scope,
|
|
||||||
evidenceID,
|
|
||||||
cursor,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return page.NewPage(evidenceStateTransitions, cursor), nil
|
return task, nil
|
||||||
}
|
}
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
// 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 probo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
|
||||||
"go.gearno.de/kit/pg"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UpdateTaskStateRequest struct {
|
|
||||||
TaskID gid.GID
|
|
||||||
State coredata.TaskState
|
|
||||||
Reason *string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Service) UpdateTaskState(
|
|
||||||
ctx context.Context,
|
|
||||||
req UpdateTaskStateRequest,
|
|
||||||
) (*coredata.Task, error) {
|
|
||||||
|
|
||||||
// TODO: lock the task for update to ensure that only one update can happen at a time
|
|
||||||
|
|
||||||
task, err := s.GetTask(ctx, req.TaskID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot get task: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if task.State == req.State {
|
|
||||||
return task, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
taskStateTransitionID, err := gid.NewGID(s.scope.GetTenantID(), coredata.TaskStateTransitionEntityType)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot create task state transition global id: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
currentState := task.State
|
|
||||||
|
|
||||||
taskStateTransition := coredata.TaskStateTransition{
|
|
||||||
StateTransition: coredata.StateTransition[coredata.TaskState]{
|
|
||||||
ID: taskStateTransitionID,
|
|
||||||
FromState: ¤tState,
|
|
||||||
ToState: req.State,
|
|
||||||
Reason: req.Reason,
|
|
||||||
CreatedAt: now,
|
|
||||||
UpdatedAt: now,
|
|
||||||
},
|
|
||||||
TaskID: task.ID,
|
|
||||||
}
|
|
||||||
|
|
||||||
task.State = req.State
|
|
||||||
task.UpdatedAt = now
|
|
||||||
|
|
||||||
err = s.pg.WithConn(
|
|
||||||
ctx,
|
|
||||||
func(conn pg.Conn) error {
|
|
||||||
if err := taskStateTransition.Insert(ctx, conn, s.scope); err != nil {
|
|
||||||
return fmt.Errorf("cannot insert task state transition: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return task, nil
|
|
||||||
}
|
|
||||||
@@ -225,13 +225,6 @@ type Control implements Node {
|
|||||||
description: String!
|
description: String!
|
||||||
state: ControlState!
|
state: ControlState!
|
||||||
|
|
||||||
stateTransisions(
|
|
||||||
first: Int
|
|
||||||
after: CursorKey
|
|
||||||
last: Int
|
|
||||||
before: CursorKey
|
|
||||||
): ControlStateTransitionConnection! @goField(forceResolver: true)
|
|
||||||
|
|
||||||
tasks(
|
tasks(
|
||||||
first: Int
|
first: Int
|
||||||
after: CursorKey
|
after: CursorKey
|
||||||
@@ -243,25 +236,6 @@ type Control implements Node {
|
|||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
|
|
||||||
type ControlStateTransitionConnection {
|
|
||||||
edges: [ControlStateTransitionEdge!]!
|
|
||||||
pageInfo: PageInfo!
|
|
||||||
}
|
|
||||||
|
|
||||||
type ControlStateTransitionEdge {
|
|
||||||
cursor: CursorKey!
|
|
||||||
node: ControlStateTransition!
|
|
||||||
}
|
|
||||||
|
|
||||||
type ControlStateTransition {
|
|
||||||
id: ID!
|
|
||||||
fromState: ControlState
|
|
||||||
toState: ControlState!
|
|
||||||
reason: String
|
|
||||||
createdAt: Datetime!
|
|
||||||
updatedAt: Datetime!
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskConnection {
|
type TaskConnection {
|
||||||
edges: [TaskEdge!]!
|
edges: [TaskEdge!]!
|
||||||
pageInfo: PageInfo!
|
pageInfo: PageInfo!
|
||||||
@@ -274,17 +248,11 @@ type TaskEdge {
|
|||||||
|
|
||||||
type Task implements Node {
|
type Task implements Node {
|
||||||
id: ID!
|
id: ID!
|
||||||
|
version: Int!
|
||||||
name: String!
|
name: String!
|
||||||
description: String!
|
description: String!
|
||||||
state: TaskState!
|
state: TaskState!
|
||||||
|
|
||||||
stateTransisions(
|
|
||||||
first: Int
|
|
||||||
after: CursorKey
|
|
||||||
last: Int
|
|
||||||
before: CursorKey
|
|
||||||
): TaskStateTransitionConnection! @goField(forceResolver: true)
|
|
||||||
|
|
||||||
evidences(
|
evidences(
|
||||||
first: Int
|
first: Int
|
||||||
after: CursorKey
|
after: CursorKey
|
||||||
@@ -296,25 +264,6 @@ type Task implements Node {
|
|||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskStateTransitionConnection {
|
|
||||||
edges: [TaskStateTransitionEdge!]!
|
|
||||||
pageInfo: PageInfo!
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskStateTransitionEdge {
|
|
||||||
cursor: CursorKey!
|
|
||||||
node: TaskStateTransition!
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskStateTransition {
|
|
||||||
id: ID!
|
|
||||||
fromState: TaskState
|
|
||||||
toState: TaskState!
|
|
||||||
reason: String
|
|
||||||
createdAt: Datetime!
|
|
||||||
updatedAt: Datetime!
|
|
||||||
}
|
|
||||||
|
|
||||||
type EvidenceConnection {
|
type EvidenceConnection {
|
||||||
edges: [EvidenceEdge!]!
|
edges: [EvidenceEdge!]!
|
||||||
pageInfo: PageInfo!
|
pageInfo: PageInfo!
|
||||||
@@ -333,32 +282,6 @@ type Evidence implements Node {
|
|||||||
state: EvidenceState!
|
state: EvidenceState!
|
||||||
filename: String!
|
filename: String!
|
||||||
|
|
||||||
stateTransisions(
|
|
||||||
first: Int
|
|
||||||
after: CursorKey
|
|
||||||
last: Int
|
|
||||||
before: CursorKey
|
|
||||||
): EvidenceStateTransitionConnection! @goField(forceResolver: true)
|
|
||||||
|
|
||||||
createdAt: Datetime!
|
|
||||||
updatedAt: Datetime!
|
|
||||||
}
|
|
||||||
|
|
||||||
type EvidenceStateTransitionConnection {
|
|
||||||
edges: [EvidenceStateTransitionEdge!]!
|
|
||||||
pageInfo: PageInfo!
|
|
||||||
}
|
|
||||||
|
|
||||||
type EvidenceStateTransitionEdge {
|
|
||||||
cursor: CursorKey!
|
|
||||||
node: EvidenceStateTransition!
|
|
||||||
}
|
|
||||||
|
|
||||||
type EvidenceStateTransition {
|
|
||||||
id: ID!
|
|
||||||
fromState: EvidenceState
|
|
||||||
toState: EvidenceState!
|
|
||||||
reason: String
|
|
||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
@@ -402,8 +325,8 @@ type Mutation {
|
|||||||
deleteOrganization(
|
deleteOrganization(
|
||||||
input: DeleteOrganizationInput!
|
input: DeleteOrganizationInput!
|
||||||
): DeleteOrganizationPayload!
|
): DeleteOrganizationPayload!
|
||||||
updateTaskState(input: UpdateTaskStateInput!): UpdateTaskStatePayload!
|
|
||||||
createTask(input: CreateTaskInput!): CreateTaskPayload!
|
createTask(input: CreateTaskInput!): CreateTaskPayload!
|
||||||
|
updateTask(input: UpdateTaskInput!): UpdateTaskPayload!
|
||||||
deleteTask(input: DeleteTaskInput!): DeleteTaskPayload!
|
deleteTask(input: DeleteTaskInput!): DeleteTaskPayload!
|
||||||
createFramework(input: CreateFrameworkInput!): CreateFrameworkPayload!
|
createFramework(input: CreateFrameworkInput!): CreateFrameworkPayload!
|
||||||
createControl(input: CreateControlInput!): CreateControlPayload!
|
createControl(input: CreateControlInput!): CreateControlPayload!
|
||||||
@@ -534,15 +457,6 @@ type DeleteOrganizationPayload {
|
|||||||
deletedOrganizationId: ID!
|
deletedOrganizationId: ID!
|
||||||
}
|
}
|
||||||
|
|
||||||
input UpdateTaskStateInput {
|
|
||||||
taskId: ID!
|
|
||||||
state: TaskState!
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateTaskStatePayload {
|
|
||||||
task: Task!
|
|
||||||
}
|
|
||||||
|
|
||||||
input CreateTaskInput {
|
input CreateTaskInput {
|
||||||
controlId: ID!
|
controlId: ID!
|
||||||
name: String!
|
name: String!
|
||||||
@@ -700,3 +614,15 @@ type PolicyEdge {
|
|||||||
cursor: CursorKey!
|
cursor: CursorKey!
|
||||||
node: Policy!
|
node: Policy!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input UpdateTaskInput {
|
||||||
|
taskId: ID!
|
||||||
|
expectedVersion: Int!
|
||||||
|
name: String
|
||||||
|
description: String
|
||||||
|
state: TaskState
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateTaskPayload {
|
||||||
|
task: Task!
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,58 +0,0 @@
|
|||||||
// 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/page"
|
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewControlStateTransitionConnection(
|
|
||||||
p *page.Page[*coredata.ControlStateTransition],
|
|
||||||
) *ControlStateTransitionConnection {
|
|
||||||
var edges = make([]*ControlStateTransitionEdge, len(p.Data))
|
|
||||||
|
|
||||||
for i := range edges {
|
|
||||||
edges[i] = NewControlStateTransitionEdge(p.Data[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ControlStateTransitionConnection{
|
|
||||||
Edges: edges,
|
|
||||||
PageInfo: NewPageInfo(p),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewControlStateTransitionEdge(cst *coredata.ControlStateTransition) *ControlStateTransitionEdge {
|
|
||||||
return &ControlStateTransitionEdge{
|
|
||||||
Cursor: cst.CursorKey(),
|
|
||||||
Node: NewControlStateTransition(cst),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewControlStateTransition(cst *coredata.ControlStateTransition) *ControlStateTransition {
|
|
||||||
var fromState *coredata.ControlState
|
|
||||||
if cst.FromState != nil {
|
|
||||||
fromState = cst.FromState
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ControlStateTransition{
|
|
||||||
ID: cst.ID,
|
|
||||||
FromState: fromState,
|
|
||||||
ToState: cst.ToState,
|
|
||||||
Reason: cst.Reason,
|
|
||||||
CreatedAt: cst.CreatedAt,
|
|
||||||
UpdatedAt: cst.UpdatedAt,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
// 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/page"
|
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewEvidenceStateTransitionConnection(
|
|
||||||
p *page.Page[*coredata.EvidenceStateTransition],
|
|
||||||
) *EvidenceStateTransitionConnection {
|
|
||||||
var edges = make([]*EvidenceStateTransitionEdge, len(p.Data))
|
|
||||||
|
|
||||||
for i := range edges {
|
|
||||||
edges[i] = NewEvidenceStateTransitionEdge(p.Data[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return &EvidenceStateTransitionConnection{
|
|
||||||
Edges: edges,
|
|
||||||
PageInfo: NewPageInfo(p),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEvidenceStateTransitionEdge(est *coredata.EvidenceStateTransition) *EvidenceStateTransitionEdge {
|
|
||||||
return &EvidenceStateTransitionEdge{
|
|
||||||
Cursor: est.CursorKey(),
|
|
||||||
Node: NewEvidenceStateTransition(est),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEvidenceStateTransition(est *coredata.EvidenceStateTransition) *EvidenceStateTransition {
|
|
||||||
var fromState *coredata.EvidenceState
|
|
||||||
if est.FromState != nil {
|
|
||||||
fromState = est.FromState
|
|
||||||
}
|
|
||||||
|
|
||||||
return &EvidenceStateTransition{
|
|
||||||
ID: est.ID,
|
|
||||||
FromState: fromState,
|
|
||||||
ToState: est.ToState,
|
|
||||||
Reason: est.Reason,
|
|
||||||
CreatedAt: est.CreatedAt,
|
|
||||||
UpdatedAt: est.UpdatedAt,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -47,5 +47,6 @@ func NewTask(t *coredata.Task) *Task {
|
|||||||
State: t.State,
|
State: t.State,
|
||||||
CreatedAt: t.CreatedAt,
|
CreatedAt: t.CreatedAt,
|
||||||
UpdatedAt: t.UpdatedAt,
|
UpdatedAt: t.UpdatedAt,
|
||||||
|
Version: t.Version,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
// 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/page"
|
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewTaskStateTransitionConnection(
|
|
||||||
p *page.Page[*coredata.TaskStateTransition],
|
|
||||||
) *TaskStateTransitionConnection {
|
|
||||||
var edges = make([]*TaskStateTransitionEdge, len(p.Data))
|
|
||||||
|
|
||||||
for i := range edges {
|
|
||||||
edges[i] = NewTaskStateTransitionEdge(p.Data[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return &TaskStateTransitionConnection{
|
|
||||||
Edges: edges,
|
|
||||||
PageInfo: NewPageInfo(p),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTaskStateTransitionEdge(tst *coredata.TaskStateTransition) *TaskStateTransitionEdge {
|
|
||||||
return &TaskStateTransitionEdge{
|
|
||||||
Cursor: tst.CursorKey(),
|
|
||||||
Node: NewTaskStateTransition(tst),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTaskStateTransition(tst *coredata.TaskStateTransition) *TaskStateTransition {
|
|
||||||
var fromState *coredata.TaskState
|
|
||||||
if tst.FromState != nil {
|
|
||||||
fromState = tst.FromState
|
|
||||||
}
|
|
||||||
|
|
||||||
return &TaskStateTransition{
|
|
||||||
ID: tst.ID,
|
|
||||||
FromState: fromState,
|
|
||||||
ToState: tst.ToState,
|
|
||||||
Reason: tst.Reason,
|
|
||||||
CreatedAt: tst.CreatedAt,
|
|
||||||
UpdatedAt: tst.UpdatedAt,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,16 +17,15 @@ type Node interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Control struct {
|
type Control struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
State coredata.ControlState `json:"state"`
|
State coredata.ControlState `json:"state"`
|
||||||
StateTransisions *ControlStateTransitionConnection `json:"stateTransisions"`
|
Tasks *TaskConnection `json:"tasks"`
|
||||||
Tasks *TaskConnection `json:"tasks"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Control) IsNode() {}
|
func (Control) IsNode() {}
|
||||||
@@ -42,25 +41,6 @@ type ControlEdge struct {
|
|||||||
Node *Control `json:"node"`
|
Node *Control `json:"node"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ControlStateTransition struct {
|
|
||||||
ID gid.GID `json:"id"`
|
|
||||||
FromState *coredata.ControlState `json:"fromState,omitempty"`
|
|
||||||
ToState coredata.ControlState `json:"toState"`
|
|
||||||
Reason *string `json:"reason,omitempty"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ControlStateTransitionConnection struct {
|
|
||||||
Edges []*ControlStateTransitionEdge `json:"edges"`
|
|
||||||
PageInfo *PageInfo `json:"pageInfo"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ControlStateTransitionEdge struct {
|
|
||||||
Cursor page.CursorKey `json:"cursor"`
|
|
||||||
Node *ControlStateTransition `json:"node"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateControlInput struct {
|
type CreateControlInput struct {
|
||||||
FrameworkID gid.GID `json:"frameworkId"`
|
FrameworkID gid.GID `json:"frameworkId"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -191,15 +171,14 @@ type DeleteVendorPayload struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Evidence struct {
|
type Evidence struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
FileURL string `json:"fileUrl"`
|
FileURL string `json:"fileUrl"`
|
||||||
MimeType string `json:"mimeType"`
|
MimeType string `json:"mimeType"`
|
||||||
Size int `json:"size"`
|
Size int `json:"size"`
|
||||||
State coredata.EvidenceState `json:"state"`
|
State coredata.EvidenceState `json:"state"`
|
||||||
Filename string `json:"filename"`
|
Filename string `json:"filename"`
|
||||||
StateTransisions *EvidenceStateTransitionConnection `json:"stateTransisions"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Evidence) IsNode() {}
|
func (Evidence) IsNode() {}
|
||||||
@@ -215,25 +194,6 @@ type EvidenceEdge struct {
|
|||||||
Node *Evidence `json:"node"`
|
Node *Evidence `json:"node"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EvidenceStateTransition struct {
|
|
||||||
ID gid.GID `json:"id"`
|
|
||||||
FromState *coredata.EvidenceState `json:"fromState,omitempty"`
|
|
||||||
ToState coredata.EvidenceState `json:"toState"`
|
|
||||||
Reason *string `json:"reason,omitempty"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type EvidenceStateTransitionConnection struct {
|
|
||||||
Edges []*EvidenceStateTransitionEdge `json:"edges"`
|
|
||||||
PageInfo *PageInfo `json:"pageInfo"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type EvidenceStateTransitionEdge struct {
|
|
||||||
Cursor page.CursorKey `json:"cursor"`
|
|
||||||
Node *EvidenceStateTransition `json:"node"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Framework struct {
|
type Framework struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
@@ -350,14 +310,14 @@ type Session struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
Name string `json:"name"`
|
Version int `json:"version"`
|
||||||
Description string `json:"description"`
|
Name string `json:"name"`
|
||||||
State coredata.TaskState `json:"state"`
|
Description string `json:"description"`
|
||||||
StateTransisions *TaskStateTransitionConnection `json:"stateTransisions"`
|
State coredata.TaskState `json:"state"`
|
||||||
Evidences *EvidenceConnection `json:"evidences"`
|
Evidences *EvidenceConnection `json:"evidences"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Task) IsNode() {}
|
func (Task) IsNode() {}
|
||||||
@@ -373,25 +333,6 @@ type TaskEdge struct {
|
|||||||
Node *Task `json:"node"`
|
Node *Task `json:"node"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskStateTransition struct {
|
|
||||||
ID gid.GID `json:"id"`
|
|
||||||
FromState *coredata.TaskState `json:"fromState,omitempty"`
|
|
||||||
ToState coredata.TaskState `json:"toState"`
|
|
||||||
Reason *string `json:"reason,omitempty"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskStateTransitionConnection struct {
|
|
||||||
Edges []*TaskStateTransitionEdge `json:"edges"`
|
|
||||||
PageInfo *PageInfo `json:"pageInfo"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskStateTransitionEdge struct {
|
|
||||||
Cursor page.CursorKey `json:"cursor"`
|
|
||||||
Node *TaskStateTransition `json:"node"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateControlInput struct {
|
type UpdateControlInput struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
ExpectedVersion int `json:"expectedVersion"`
|
ExpectedVersion int `json:"expectedVersion"`
|
||||||
@@ -443,6 +384,18 @@ type UpdatePolicyPayload struct {
|
|||||||
Policy *Policy `json:"policy"`
|
Policy *Policy `json:"policy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateTaskInput struct {
|
||||||
|
TaskID gid.GID `json:"taskId"`
|
||||||
|
ExpectedVersion int `json:"expectedVersion"`
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
State *coredata.TaskState `json:"state,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateTaskPayload struct {
|
||||||
|
Task *Task `json:"task"`
|
||||||
|
}
|
||||||
|
|
||||||
type UpdateTaskStateInput struct {
|
type UpdateTaskStateInput struct {
|
||||||
TaskID gid.GID `json:"taskId"`
|
TaskID gid.GID `json:"taskId"`
|
||||||
State coredata.TaskState `json:"state"`
|
State coredata.TaskState `json:"state"`
|
||||||
|
|||||||
@@ -18,19 +18,6 @@ import (
|
|||||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StateTransisions is the resolver for the stateTransisions field.
|
|
||||||
func (r *controlResolver) StateTransisions(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.ControlStateTransitionConnection, error) {
|
|
||||||
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
|
|
||||||
cursor := types.NewCursor(first, after, last, before)
|
|
||||||
|
|
||||||
page, err := svc.ListControlStateTransitions(ctx, obj.ID, cursor)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot list control tasks: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return types.NewControlStateTransitionConnection(page), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tasks is the resolver for the tasks field.
|
// Tasks is the resolver for the tasks field.
|
||||||
func (r *controlResolver) Tasks(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.TaskConnection, error) {
|
func (r *controlResolver) Tasks(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.TaskConnection, error) {
|
||||||
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
|
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
|
||||||
@@ -56,19 +43,6 @@ func (r *evidenceResolver) FileURL(ctx context.Context, obj *types.Evidence) (st
|
|||||||
return *fileURL, nil
|
return *fileURL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateTransisions is the resolver for the stateTransisions field.
|
|
||||||
func (r *evidenceResolver) StateTransisions(ctx context.Context, obj *types.Evidence, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.EvidenceStateTransitionConnection, error) {
|
|
||||||
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
|
|
||||||
cursor := types.NewCursor(first, after, last, before)
|
|
||||||
|
|
||||||
page, err := svc.ListEvidenceStateTransitions(ctx, obj.ID, cursor)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot list evidence state transitions: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return types.NewEvidenceStateTransitionConnection(page), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Controls is the resolver for the controls field.
|
// Controls is the resolver for the controls field.
|
||||||
func (r *frameworkResolver) Controls(ctx context.Context, obj *types.Framework, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.ControlConnection, error) {
|
func (r *frameworkResolver) Controls(ctx context.Context, obj *types.Framework, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.ControlConnection, error) {
|
||||||
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
|
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
|
||||||
@@ -226,24 +200,6 @@ func (r *mutationResolver) DeleteOrganization(ctx context.Context, input types.D
|
|||||||
panic(fmt.Errorf("not implemented: DeleteOrganization - deleteOrganization"))
|
panic(fmt.Errorf("not implemented: DeleteOrganization - deleteOrganization"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateTaskState is the resolver for the updateTaskState field.
|
|
||||||
func (r *mutationResolver) UpdateTaskState(ctx context.Context, input types.UpdateTaskStateInput) (*types.UpdateTaskStatePayload, error) {
|
|
||||||
svc := r.proboSvc.WithTenant(input.TaskID.TenantID())
|
|
||||||
|
|
||||||
task, err := svc.UpdateTaskState(ctx, probo.UpdateTaskStateRequest{
|
|
||||||
TaskID: input.TaskID,
|
|
||||||
State: input.State,
|
|
||||||
Reason: nil,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot update task state: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.UpdateTaskStatePayload{
|
|
||||||
Task: types.NewTask(task),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateTask is the resolver for the createTask field.
|
// CreateTask is the resolver for the createTask field.
|
||||||
func (r *mutationResolver) CreateTask(ctx context.Context, input types.CreateTaskInput) (*types.CreateTaskPayload, error) {
|
func (r *mutationResolver) CreateTask(ctx context.Context, input types.CreateTaskInput) (*types.CreateTaskPayload, error) {
|
||||||
svc := r.proboSvc.WithTenant(input.ControlID.TenantID())
|
svc := r.proboSvc.WithTenant(input.ControlID.TenantID())
|
||||||
@@ -262,6 +218,26 @@ func (r *mutationResolver) CreateTask(ctx context.Context, input types.CreateTas
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateTask is the resolver for the updateTask field.
|
||||||
|
func (r *mutationResolver) UpdateTask(ctx context.Context, input types.UpdateTaskInput) (*types.UpdateTaskPayload, error) {
|
||||||
|
svc := r.proboSvc.WithTenant(input.TaskID.TenantID())
|
||||||
|
|
||||||
|
task, err := svc.UpdateTask(ctx, probo.UpdateTaskRequest{
|
||||||
|
ID: input.TaskID,
|
||||||
|
ExpectedVersion: input.ExpectedVersion,
|
||||||
|
Name: input.Name,
|
||||||
|
Description: input.Description,
|
||||||
|
State: input.State,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot update task: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.UpdateTaskPayload{
|
||||||
|
Task: types.NewTask(task),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteTask is the resolver for the deleteTask field.
|
// DeleteTask is the resolver for the deleteTask field.
|
||||||
func (r *mutationResolver) DeleteTask(ctx context.Context, input types.DeleteTaskInput) (*types.DeleteTaskPayload, error) {
|
func (r *mutationResolver) DeleteTask(ctx context.Context, input types.DeleteTaskInput) (*types.DeleteTaskPayload, error) {
|
||||||
svc := r.proboSvc.WithTenant(input.TaskID.TenantID())
|
svc := r.proboSvc.WithTenant(input.TaskID.TenantID())
|
||||||
@@ -589,19 +565,6 @@ func (r *queryResolver) Viewer(ctx context.Context) (*types.User, error) {
|
|||||||
return types.NewUser(user), nil
|
return types.NewUser(user), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateTransisions is the resolver for the stateTransisions field.
|
|
||||||
func (r *taskResolver) StateTransisions(ctx context.Context, obj *types.Task, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.TaskStateTransitionConnection, error) {
|
|
||||||
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
|
|
||||||
cursor := types.NewCursor(first, after, last, before)
|
|
||||||
|
|
||||||
page, err := svc.ListTaskStateTransitions(ctx, obj.ID, cursor)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot list control tasks: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return types.NewTaskStateTransitionConnection(page), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evidences is the resolver for the evidences field.
|
// Evidences is the resolver for the evidences field.
|
||||||
func (r *taskResolver) Evidences(ctx context.Context, obj *types.Task, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.EvidenceConnection, error) {
|
func (r *taskResolver) Evidences(ctx context.Context, obj *types.Task, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.EvidenceConnection, error) {
|
||||||
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
|
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
|
||||||
|
|||||||
Reference in New Issue
Block a user