Refactor DocumentSignaturesTab to DocumentSignaturesPage + fix count bug

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-01-27 15:46:59 +04:00
parent fb09bed247
commit 7c721e5ff7
42 changed files with 2661 additions and 1361 deletions

View File

@@ -4728,9 +4728,13 @@ type DocumentVersion implements Node {
permission(action: String!): Boolean! @goField(forceResolver: true)
}
type DocumentVersionSignatureConnection {
type DocumentVersionSignatureConnection
@goModel(
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.DocumentVersionSignatureConnection"
) {
edges: [DocumentVersionSignatureEdge!]!
pageInfo: PageInfo!
totalCount: Int! @goField(forceResolver: true)
}
type DocumentVersionSignatureEdge {
@@ -4745,6 +4749,7 @@ input DocumentVersionSignatureOrder {
input DocumentVersionSignatureFilter {
states: [DocumentVersionSignatureState!]
activeContract: Boolean
}
enum DocumentVersionSignatureState

View File

@@ -67,6 +67,7 @@ type ResolverRoot interface {
DocumentVersion() DocumentVersionResolver
DocumentVersionConnection() DocumentVersionConnectionResolver
DocumentVersionSignature() DocumentVersionSignatureResolver
DocumentVersionSignatureConnection() DocumentVersionSignatureConnectionResolver
Evidence() EvidenceResolver
EvidenceConnection() EvidenceConnectionResolver
File() FileResolver
@@ -767,8 +768,9 @@ type ComplexityRoot struct {
}
DocumentVersionSignatureConnection struct {
Edges func(childComplexity int) int
PageInfo func(childComplexity int) int
Edges func(childComplexity int) int
PageInfo func(childComplexity int) int
TotalCount func(childComplexity int) int
}
DocumentVersionSignatureEdge struct {
@@ -2032,6 +2034,9 @@ type DocumentVersionSignatureResolver interface {
Permission(ctx context.Context, obj *types.DocumentVersionSignature, action string) (bool, error)
}
type DocumentVersionSignatureConnectionResolver interface {
TotalCount(ctx context.Context, obj *types.DocumentVersionSignatureConnection) (int, error)
}
type EvidenceResolver interface {
File(ctx context.Context, obj *types.Evidence) (*types.File, error)
@@ -4468,6 +4473,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
}
return e.complexity.DocumentVersionSignatureConnection.PageInfo(childComplexity), true
case "DocumentVersionSignatureConnection.totalCount":
if e.complexity.DocumentVersionSignatureConnection.TotalCount == nil {
break
}
return e.complexity.DocumentVersionSignatureConnection.TotalCount(childComplexity), true
case "DocumentVersionSignatureEdge.cursor":
if e.complexity.DocumentVersionSignatureEdge.Cursor == nil {
@@ -15028,9 +15039,13 @@ type DocumentVersion implements Node {
permission(action: String!): Boolean! @goField(forceResolver: true)
}
type DocumentVersionSignatureConnection {
type DocumentVersionSignatureConnection
@goModel(
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.DocumentVersionSignatureConnection"
) {
edges: [DocumentVersionSignatureEdge!]!
pageInfo: PageInfo!
totalCount: Int! @goField(forceResolver: true)
}
type DocumentVersionSignatureEdge {
@@ -15045,6 +15060,7 @@ input DocumentVersionSignatureOrder {
input DocumentVersionSignatureFilter {
states: [DocumentVersionSignatureState!]
activeContract: Boolean
}
enum DocumentVersionSignatureState
@@ -29457,6 +29473,8 @@ func (ec *executionContext) fieldContext_DocumentVersion_signatures(ctx context.
return ec.fieldContext_DocumentVersionSignatureConnection_edges(ctx, field)
case "pageInfo":
return ec.fieldContext_DocumentVersionSignatureConnection_pageInfo(ctx, field)
case "totalCount":
return ec.fieldContext_DocumentVersionSignatureConnection_totalCount(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type DocumentVersionSignatureConnection", field.Name)
},
@@ -30199,7 +30217,7 @@ func (ec *executionContext) _DocumentVersionSignatureConnection_pageInfo(ctx con
return obj.PageInfo, nil
},
nil,
ec.marshalNPageInfo2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐPageInfo,
ec.marshalNPageInfo2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐPageInfo,
true,
true,
)
@@ -30228,6 +30246,35 @@ func (ec *executionContext) fieldContext_DocumentVersionSignatureConnection_page
return fc, nil
}
func (ec *executionContext) _DocumentVersionSignatureConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *types.DocumentVersionSignatureConnection) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
ec.OperationContext,
field,
ec.fieldContext_DocumentVersionSignatureConnection_totalCount,
func(ctx context.Context) (any, error) {
return ec.resolvers.DocumentVersionSignatureConnection().TotalCount(ctx, obj)
},
nil,
ec.marshalNInt2int,
true,
true,
)
}
func (ec *executionContext) fieldContext_DocumentVersionSignatureConnection_totalCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "DocumentVersionSignatureConnection",
Field: field,
IsMethod: true,
IsResolver: true,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type Int does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _DocumentVersionSignatureEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *types.DocumentVersionSignatureEdge) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
@@ -64805,7 +64852,7 @@ func (ec *executionContext) unmarshalInputDocumentVersionSignatureFilter(ctx con
asMap[k] = v
}
fieldsInOrder := [...]string{"states"}
fieldsInOrder := [...]string{"states", "activeContract"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
@@ -64819,6 +64866,13 @@ func (ec *executionContext) unmarshalInputDocumentVersionSignatureFilter(ctx con
return it, err
}
it.States = data
case "activeContract":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("activeContract"))
data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v)
if err != nil {
return it, err
}
it.ActiveContract = data
}
}
@@ -76206,13 +76260,49 @@ func (ec *executionContext) _DocumentVersionSignatureConnection(ctx context.Cont
case "edges":
out.Values[i] = ec._DocumentVersionSignatureConnection_edges(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
atomic.AddUint32(&out.Invalids, 1)
}
case "pageInfo":
out.Values[i] = ec._DocumentVersionSignatureConnection_pageInfo(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
atomic.AddUint32(&out.Invalids, 1)
}
case "totalCount":
field := field
innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._DocumentVersionSignatureConnection_totalCount(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&fs.Invalids, 1)
}
return res
}
if field.Deferrable != nil {
dfs, ok := deferred[field.Deferrable.Label]
di := 0
if ok {
dfs.AddField(field)
di = len(dfs.Values) - 1
} else {
dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
deferred[field.Deferrable.Label] = dfs
}
dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
return innerFunc(ctx, dfs)
})
// don't run the out.Concurrently() call below
out.Values[i] = graphql.Null
continue
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
default:
panic("unknown field " + strconv.Quote(field.Name))
}

View File

@@ -16,14 +16,30 @@ package types
import (
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/page"
)
type (
DocumentVersionSignatureOrderBy OrderBy[coredata.DocumentVersionSignatureOrderField]
DocumentVersionSignatureConnection struct {
TotalCount int
Edges []*DocumentVersionSignatureEdge
PageInfo PageInfo
Resolver any
ParentID gid.GID
Filters *coredata.DocumentVersionSignatureFilter
}
)
func NewDocumentVersionSignatureConnection(page *page.Page[*coredata.DocumentVersionSignature, coredata.DocumentVersionSignatureOrderField]) *DocumentVersionSignatureConnection {
func NewDocumentVersionSignatureConnection(
page *page.Page[*coredata.DocumentVersionSignature, coredata.DocumentVersionSignatureOrderField],
parentType any,
parentID gid.GID,
filter *coredata.DocumentVersionSignatureFilter,
) *DocumentVersionSignatureConnection {
edges := make([]*DocumentVersionSignatureEdge, len(page.Data))
for i, documentVersionSignature := range page.Data {
edges[i] = NewDocumentVersionSignatureEdge(documentVersionSignature, page.Cursor.OrderBy.Field)
@@ -31,7 +47,11 @@ func NewDocumentVersionSignatureConnection(page *page.Page[*coredata.DocumentVer
return &DocumentVersionSignatureConnection{
Edges: edges,
PageInfo: NewPageInfo(page),
PageInfo: *NewPageInfo(page),
Resolver: parentType,
ParentID: parentID,
Filters: filter,
}
}

View File

@@ -1201,18 +1201,14 @@ type DocumentVersionSignature struct {
func (DocumentVersionSignature) IsNode() {}
func (this DocumentVersionSignature) GetID() gid.GID { return this.ID }
type DocumentVersionSignatureConnection struct {
Edges []*DocumentVersionSignatureEdge `json:"edges"`
PageInfo *PageInfo `json:"pageInfo"`
}
type DocumentVersionSignatureEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *DocumentVersionSignature `json:"node"`
}
type DocumentVersionSignatureFilter struct {
States []coredata.DocumentVersionSignatureState `json:"states,omitempty"`
States []coredata.DocumentVersionSignatureState `json:"states,omitempty"`
ActiveContract *bool `json:"activeContract,omitempty"`
}
type DocumentVersionSignatureOrder struct {

View File

@@ -1080,10 +1080,16 @@ func (r *documentVersionResolver) Signatures(ctx context.Context, obj *types.Doc
}
var signatureStates []coredata.DocumentVersionSignatureState
if filter != nil && filter.States != nil {
signatureStates = filter.States
var activeContract *bool
if filter != nil {
if filter.States != nil {
signatureStates = filter.States
}
if filter.ActiveContract != nil {
activeContract = filter.ActiveContract
}
}
signatureFilter := coredata.NewDocumentVersionSignatureFilter(signatureStates)
signatureFilter := coredata.NewDocumentVersionSignatureFilter(signatureStates, activeContract)
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
@@ -1093,7 +1099,7 @@ func (r *documentVersionResolver) Signatures(ctx context.Context, obj *types.Doc
panic(fmt.Errorf("cannot list document version signatures: %w", err))
}
return types.NewDocumentVersionSignatureConnection(page), nil
return types.NewDocumentVersionSignatureConnection(page, r, obj.ID, signatureFilter), nil
}
// Signed is the resolver for the signed field.
@@ -1122,7 +1128,7 @@ func (r *documentVersionResolver) Permission(ctx context.Context, obj *types.Doc
// TotalCount is the resolver for the totalCount field.
func (r *documentVersionConnectionResolver) TotalCount(ctx context.Context, obj *types.DocumentVersionConnection) (int, error) {
if err := r.authorize(ctx, obj.ParentID, probo.ActionEvidenceList); err != nil {
if err := r.authorize(ctx, obj.ParentID, probo.ActionDocumentVersionList); err != nil {
return 0, err
}
@@ -1137,7 +1143,7 @@ func (r *documentVersionConnectionResolver) TotalCount(ctx context.Context, obj
count, err := prb.Documents.CountVersionsForDocumentID(ctx, obj.ParentID, filter)
if err != nil {
// TODO no panic use gqlutils.InternalError
panic(fmt.Errorf("cannot count tasks: %w", err))
panic(fmt.Errorf("cannot count document versions: %w", err))
}
return count, nil
}
@@ -1189,6 +1195,32 @@ func (r *documentVersionSignatureResolver) Permission(ctx context.Context, obj *
return r.Resolver.Permission(ctx, obj, action)
}
// TotalCount is the resolver for the totalCount field.
func (r *documentVersionSignatureConnectionResolver) TotalCount(ctx context.Context, obj *types.DocumentVersionSignatureConnection) (int, error) {
if err := r.authorize(ctx, obj.ParentID, probo.ActionDocumentVersionSignatureList); err != nil {
return 0, err
}
prb := r.ProboService(ctx, obj.ParentID.TenantID())
switch obj.Resolver.(type) {
case *documentVersionResolver:
filter := &coredata.DocumentVersionSignatureFilter{}
if obj.Filters != nil {
filter = obj.Filters
}
count, err := prb.Documents.CountSignaturesForVersionID(ctx, obj.ParentID, filter)
if err != nil {
// TODO no panic use gqlutils.InternalError
panic(fmt.Errorf("cannot count signatures: %w", err))
}
return count, nil
}
// TODO no panic use gqlutils.InternalError
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
}
// File is the resolver for the file field.
func (r *evidenceResolver) File(ctx context.Context, obj *types.Evidence) (*types.File, error) {
if err := r.authorize(ctx, obj.ID, probo.ActionFileGet); err != nil {
@@ -1277,14 +1309,14 @@ func (r *evidenceConnectionResolver) TotalCount(ctx context.Context, obj *types.
count, err := prb.Evidences.CountForMeasureID(ctx, obj.ParentID)
if err != nil {
// TODO no panic use gqlutils.InternalError
panic(fmt.Errorf("cannot count tasks: %w", err))
panic(fmt.Errorf("cannot count measure evidence: %w", err))
}
return count, nil
case *taskResolver:
count, err := prb.Evidences.CountForTaskID(ctx, obj.ParentID)
if err != nil {
// TODO no panic use gqlutils.InternalError
panic(fmt.Errorf("cannot count tasks: %w", err))
panic(fmt.Errorf("cannot count task evidence: %w", err))
}
return count, nil
}
@@ -8558,6 +8590,11 @@ func (r *Resolver) DocumentVersionSignature() schema.DocumentVersionSignatureRes
return &documentVersionSignatureResolver{r}
}
// DocumentVersionSignatureConnection returns schema.DocumentVersionSignatureConnectionResolver implementation.
func (r *Resolver) DocumentVersionSignatureConnection() schema.DocumentVersionSignatureConnectionResolver {
return &documentVersionSignatureConnectionResolver{r}
}
// Evidence returns schema.EvidenceResolver implementation.
func (r *Resolver) Evidence() schema.EvidenceResolver { return &evidenceResolver{r} }
@@ -8787,6 +8824,7 @@ type documentConnectionResolver struct{ *Resolver }
type documentVersionResolver struct{ *Resolver }
type documentVersionConnectionResolver struct{ *Resolver }
type documentVersionSignatureResolver struct{ *Resolver }
type documentVersionSignatureConnectionResolver struct{ *Resolver }
type evidenceResolver struct{ *Resolver }
type evidenceConnectionResolver struct{ *Resolver }
type fileResolver struct{ *Resolver }

View File

@@ -1717,12 +1717,17 @@ func (r *Resolver) ListDocumentVersionSignaturesTool(ctx context.Context, req *m
cursor := types.NewCursor(input.Size, input.Cursor, pageOrderBy)
var signatureFilter *coredata.DocumentVersionSignatureFilter
if input.Filter != nil && input.Filter.States != nil && len(input.Filter.States) > 0 {
signatureFilter = coredata.NewDocumentVersionSignatureFilter(input.Filter.States)
} else {
signatureFilter = coredata.NewDocumentVersionSignatureFilter(nil)
var signatureStates []coredata.DocumentVersionSignatureState
var activeContract *bool
if input.Filter != nil {
if input.Filter.States != nil {
signatureStates = input.Filter.States
}
if input.Filter.ActiveContract != nil {
activeContract = input.Filter.ActiveContract
}
}
signatureFilter := coredata.NewDocumentVersionSignatureFilter(signatureStates, activeContract)
page, err := prb.Documents.ListSignatures(ctx, input.DocumentVersionID, cursor, signatureFilter)
if err != nil {

View File

@@ -3860,6 +3860,9 @@ components:
items:
$ref: "#/components/schemas/DocumentVersionSignatureState"
description: Signature states
active_contract:
type: boolean
description: Signatory contract status
ListDocumentVersionSignaturesOutput:
type: object

View File

@@ -101,7 +101,7 @@ var (
ListControlsToolOutputSchema = mcp.MustUnmarshalSchema(`{"type":"object","required":["controls"],"properties":{"controls":{"type":"array","items":{"type":"object","required":["id","organization_id","framework_id","section_title","name","status","created_at","updated_at"],"properties":{"created_at":{"type":"string","description":"Creation timestamp","format":"date-time"},"description":{"description":"Control description"},"exclusion_justification":{"description":"Exclusion justification"},"framework_id":{"type":"string","format":"string"},"id":{"type":"string","format":"string"},"name":{"type":"string","description":"Control name"},"organization_id":{"type":"string","format":"string"},"section_title":{"type":"string","description":"Section title"},"status":{"type":"string","enum":["INCLUDED","EXCLUDED"]},"updated_at":{"type":"string","description":"Update timestamp","format":"date-time"}}}},"next_cursor":{"type":"string","format":"string"}}}`)
ListDataToolInputSchema = mcp.MustUnmarshalSchema(`{"type":"object","required":["organization_id"],"properties":{"cursor":{"type":"string","format":"string"},"filter":{"type":"object","properties":{"snapshot_id":{"type":"string","format":"string"}}},"order_by":{"type":"object","required":["field","direction"],"properties":{"direction":{"type":"string","enum":["ASC","DESC"]},"field":{"type":"string","enum":["CREATED_AT","NAME","DATA_CLASSIFICATION"]}}},"organization_id":{"type":"string","format":"string"},"size":{"type":"integer","description":"Page size"}}}`)
ListDataToolOutputSchema = mcp.MustUnmarshalSchema(`{"type":"object","required":["data"],"properties":{"data":{"type":"array","items":{"type":"object","required":["id","organization_id","name","data_classification","owner_id","created_at","updated_at"],"properties":{"created_at":{"type":"string","description":"Creation timestamp","format":"date-time"},"data_classification":{"type":"string","enum":["PUBLIC","INTERNAL","CONFIDENTIAL","SECRET"]},"id":{"type":"string","format":"string"},"name":{"type":"string","description":"Datum name"},"organization_id":{"type":"string","format":"string"},"owner_id":{"type":"string","format":"string"},"snapshot_id":{"description":"Snapshot ID","anyOf":[{"type":"string","format":"string"},{"type":"null","description":"No snapshot"}]},"updated_at":{"type":"string","description":"Update timestamp","format":"date-time"}}}},"next_cursor":{"type":"string","format":"string"}}}`)
ListDocumentVersionSignaturesToolInputSchema = mcp.MustUnmarshalSchema(`{"type":"object","required":["document_version_id"],"properties":{"cursor":{"type":"string","format":"string"},"document_version_id":{"type":"string","format":"string"},"filter":{"type":"object","properties":{"states":{"type":"array","description":"Signature states","items":{"type":"string","enum":["REQUESTED","SIGNED"]}}}},"order_by":{"type":"object","required":["field","direction"],"properties":{"direction":{"type":"string","enum":["ASC","DESC"]},"field":{"type":"string","enum":["CREATED_AT","SIGNED_AT"]}}},"size":{"type":"integer","description":"Page size"}}}`)
ListDocumentVersionSignaturesToolInputSchema = mcp.MustUnmarshalSchema(`{"type":"object","required":["document_version_id"],"properties":{"cursor":{"type":"string","format":"string"},"document_version_id":{"type":"string","format":"string"},"filter":{"type":"object","properties":{"active_contract":{"type":"boolean","description":"Signatory contract status"},"states":{"type":"array","description":"Signature states","items":{"type":"string","enum":["REQUESTED","SIGNED"]}}}},"order_by":{"type":"object","required":["field","direction"],"properties":{"direction":{"type":"string","enum":["ASC","DESC"]},"field":{"type":"string","enum":["CREATED_AT","SIGNED_AT"]}}},"size":{"type":"integer","description":"Page size"}}}`)
ListDocumentVersionSignaturesToolOutputSchema = mcp.MustUnmarshalSchema(`{"type":"object","required":["document_version_signatures"],"properties":{"document_version_signatures":{"type":"array","items":{"type":"object","required":["id","organization_id","document_version_id","state","signed_by","requested_at","created_at","updated_at"],"properties":{"created_at":{"type":"string","description":"Creation timestamp","format":"date-time"},"document_version_id":{"type":"string","format":"string"},"id":{"type":"string","format":"string"},"organization_id":{"type":"string","format":"string"},"requested_at":{"type":"string","description":"Requested timestamp","format":"date-time"},"signed_at":{"description":"Signed timestamp","format":"date-time"},"signed_by":{"type":"string","format":"string"},"state":{"type":"string","enum":["REQUESTED","SIGNED"]},"updated_at":{"type":"string","description":"Update timestamp","format":"date-time"}}}},"next_cursor":{"type":"string","format":"string"}}}`)
ListDocumentVersionsToolInputSchema = mcp.MustUnmarshalSchema(`{"type":"object","required":["document_id"],"properties":{"cursor":{"type":"string","format":"string"},"document_id":{"type":"string","format":"string"},"order_by":{"type":"object","required":["field","direction"],"properties":{"direction":{"type":"string","enum":["ASC","DESC"]},"field":{"type":"string","enum":["CREATED_AT","VERSION"]}}},"size":{"type":"integer","description":"Page size"}}}`)
ListDocumentVersionsToolOutputSchema = mcp.MustUnmarshalSchema(`{"type":"object","required":["document_versions"],"properties":{"document_versions":{"type":"array","items":{"type":"object","required":["id","organization_id","document_id","title","owner_id","version_number","classification","content","changelog","status","created_at","updated_at"],"properties":{"changelog":{"type":"string","description":"Changelog"},"classification":{"type":"string","enum":["PUBLIC","INTERNAL","CONFIDENTIAL","SECRET"]},"content":{"type":"string","description":"Document content"},"created_at":{"type":"string","description":"Creation timestamp","format":"date-time"},"document_id":{"type":"string","format":"string"},"id":{"type":"string","format":"string"},"organization_id":{"type":"string","format":"string"},"owner_id":{"type":"string","format":"string"},"published_at":{"description":"Published timestamp","format":"date-time"},"status":{"type":"string","enum":["DRAFT","PUBLISHED"]},"title":{"type":"string","description":"Document version title"},"updated_at":{"type":"string","description":"Update timestamp","format":"date-time"},"version_number":{"type":"integer","description":"Version number"}}}},"next_cursor":{"type":"string","format":"string"}}}`)
@@ -2173,6 +2173,8 @@ type ListDataInputFilter struct {
// ListDocumentVersionSignaturesInputFilter represents the schema
type ListDocumentVersionSignaturesInputFilter struct {
// Signatory contract status
ActiveContract *bool `json:"active_contract,omitempty"`
// Signature states
States []coredata.DocumentVersionSignatureState `json:"states,omitempty"`
}