Add people signature filtering
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -203,6 +203,7 @@ func (pvss *DocumentVersionSignatures) LoadByDocumentVersionID(
|
||||
scope Scoper,
|
||||
documentVersionID gid.GID,
|
||||
cursor *page.Cursor[DocumentVersionSignatureOrderField],
|
||||
filter *DocumentVersionSignatureFilter,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
@@ -220,13 +221,15 @@ WHERE
|
||||
%s
|
||||
AND document_version_id = @document_version_id
|
||||
AND %s
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"document_version_id": documentVersionID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
maps.Copy(args, filter.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
|
||||
48
pkg/coredata/document_version_signature_filter.go
Normal file
48
pkg/coredata/document_version_signature_filter.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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 (
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type (
|
||||
DocumentVersionSignatureFilter struct {
|
||||
states DocumentVersionSignatureStates
|
||||
}
|
||||
)
|
||||
|
||||
func NewDocumentVersionSignatureFilter(states []DocumentVersionSignatureState) *DocumentVersionSignatureFilter {
|
||||
return &DocumentVersionSignatureFilter{
|
||||
states: DocumentVersionSignatureStates(states),
|
||||
}
|
||||
}
|
||||
|
||||
func (f *DocumentVersionSignatureFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||
return pgx.StrictNamedArgs{
|
||||
"states": f.states,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *DocumentVersionSignatureFilter) SQLFragment() string {
|
||||
return `
|
||||
(
|
||||
CASE
|
||||
WHEN @states::policy_version_signature_state[] IS NOT NULL THEN
|
||||
state = ANY(@states::policy_version_signature_state[])
|
||||
ELSE TRUE
|
||||
END
|
||||
)`
|
||||
}
|
||||
@@ -17,10 +17,12 @@ package coredata
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
DocumentVersionSignatureState string
|
||||
DocumentVersionSignatureState string
|
||||
DocumentVersionSignatureStates []DocumentVersionSignatureState
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -74,3 +76,16 @@ func (pvs *DocumentVersionSignatureState) Scan(value any) error {
|
||||
func (pvs DocumentVersionSignatureState) Value() (driver.Value, error) {
|
||||
return pvs.String(), nil
|
||||
}
|
||||
|
||||
func (states DocumentVersionSignatureStates) Value() (driver.Value, error) {
|
||||
var result strings.Builder
|
||||
result.WriteString("{")
|
||||
for i, state := range states {
|
||||
if i > 0 {
|
||||
result.WriteString(",")
|
||||
}
|
||||
result.WriteString(fmt.Sprintf("%q", state.String()))
|
||||
}
|
||||
result.WriteString("}")
|
||||
return result.String(), nil
|
||||
}
|
||||
|
||||
@@ -715,13 +715,14 @@ func (s *DocumentService) ListSignatures(
|
||||
ctx context.Context,
|
||||
documentVersionID gid.GID,
|
||||
cursor *page.Cursor[coredata.DocumentVersionSignatureOrderField],
|
||||
filter *coredata.DocumentVersionSignatureFilter,
|
||||
) (*page.Page[*coredata.DocumentVersionSignature, coredata.DocumentVersionSignatureOrderField], error) {
|
||||
var documentVersionSignatures coredata.DocumentVersionSignatures
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return documentVersionSignatures.LoadByDocumentVersionID(ctx, conn, s.svc.scope, documentVersionID, cursor)
|
||||
return documentVersionSignatures.LoadByDocumentVersionID(ctx, conn, s.svc.scope, documentVersionID, cursor, filter)
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -4182,6 +4182,7 @@ type DocumentVersion implements Node {
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: DocumentVersionSignatureOrder
|
||||
filter: DocumentVersionSignatureFilter
|
||||
): DocumentVersionSignatureConnection! @goField(forceResolver: true)
|
||||
|
||||
publishedAt: Datetime
|
||||
@@ -4204,6 +4205,10 @@ input DocumentVersionSignatureOrder {
|
||||
direction: OrderDirection!
|
||||
}
|
||||
|
||||
input DocumentVersionSignatureFilter {
|
||||
states: [DocumentVersionSignatureState!]
|
||||
}
|
||||
|
||||
enum DocumentVersionSignatureState
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/coredata.DocumentVersionSignatureState"
|
||||
|
||||
@@ -640,7 +640,7 @@ type ComplexityRoot struct {
|
||||
ID func(childComplexity int) int
|
||||
Owner func(childComplexity int) int
|
||||
PublishedAt func(childComplexity int) int
|
||||
Signatures func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DocumentVersionSignatureOrder) int
|
||||
Signatures func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DocumentVersionSignatureOrder, filter *types.DocumentVersionSignatureFilter) int
|
||||
Status func(childComplexity int) int
|
||||
Title func(childComplexity int) int
|
||||
UpdatedAt func(childComplexity int) int
|
||||
@@ -1700,7 +1700,7 @@ type DocumentVersionResolver interface {
|
||||
Document(ctx context.Context, obj *types.DocumentVersion) (*types.Document, error)
|
||||
|
||||
Owner(ctx context.Context, obj *types.DocumentVersion) (*types.People, error)
|
||||
Signatures(ctx context.Context, obj *types.DocumentVersion, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DocumentVersionSignatureOrder) (*types.DocumentVersionSignatureConnection, error)
|
||||
Signatures(ctx context.Context, obj *types.DocumentVersion, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DocumentVersionSignatureOrder, filter *types.DocumentVersionSignatureFilter) (*types.DocumentVersionSignatureConnection, error)
|
||||
}
|
||||
type DocumentVersionSignatureResolver interface {
|
||||
DocumentVersion(ctx context.Context, obj *types.DocumentVersionSignature) (*types.DocumentVersion, error)
|
||||
@@ -3675,7 +3675,7 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.DocumentVersion.Signatures(childComplexity, args["first"].(*int), args["after"].(*page.CursorKey), args["last"].(*int), args["before"].(*page.CursorKey), args["orderBy"].(*types.DocumentVersionSignatureOrder)), true
|
||||
return e.complexity.DocumentVersion.Signatures(childComplexity, args["first"].(*int), args["after"].(*page.CursorKey), args["last"].(*int), args["before"].(*page.CursorKey), args["orderBy"].(*types.DocumentVersionSignatureOrder), args["filter"].(*types.DocumentVersionSignatureFilter)), true
|
||||
|
||||
case "DocumentVersion.status":
|
||||
if e.complexity.DocumentVersion.Status == nil {
|
||||
@@ -8876,6 +8876,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||
ec.unmarshalInputDocumentOrder,
|
||||
ec.unmarshalInputDocumentVersionFilter,
|
||||
ec.unmarshalInputDocumentVersionOrder,
|
||||
ec.unmarshalInputDocumentVersionSignatureFilter,
|
||||
ec.unmarshalInputDocumentVersionSignatureOrder,
|
||||
ec.unmarshalInputEvidenceOrder,
|
||||
ec.unmarshalInputExportDocumentVersionPDFInput,
|
||||
@@ -13232,6 +13233,7 @@ type DocumentVersion implements Node {
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: DocumentVersionSignatureOrder
|
||||
filter: DocumentVersionSignatureFilter
|
||||
): DocumentVersionSignatureConnection! @goField(forceResolver: true)
|
||||
|
||||
publishedAt: Datetime
|
||||
@@ -13254,6 +13256,10 @@ input DocumentVersionSignatureOrder {
|
||||
direction: OrderDirection!
|
||||
}
|
||||
|
||||
input DocumentVersionSignatureFilter {
|
||||
states: [DocumentVersionSignatureState!]
|
||||
}
|
||||
|
||||
enum DocumentVersionSignatureState
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/coredata.DocumentVersionSignatureState"
|
||||
@@ -14450,6 +14456,11 @@ func (ec *executionContext) field_DocumentVersion_signatures_args(ctx context.Co
|
||||
return nil, err
|
||||
}
|
||||
args["orderBy"] = arg4
|
||||
arg5, err := ec.field_DocumentVersion_signatures_argsFilter(ctx, rawArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args["filter"] = arg5
|
||||
return args, nil
|
||||
}
|
||||
func (ec *executionContext) field_DocumentVersion_signatures_argsFirst(
|
||||
@@ -14517,6 +14528,19 @@ func (ec *executionContext) field_DocumentVersion_signatures_argsOrderBy(
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_DocumentVersion_signatures_argsFilter(
|
||||
ctx context.Context,
|
||||
rawArgs map[string]any,
|
||||
) (*types.DocumentVersionSignatureFilter, error) {
|
||||
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("filter"))
|
||||
if tmp, ok := rawArgs["filter"]; ok {
|
||||
return ec.unmarshalODocumentVersionSignatureFilter2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐDocumentVersionSignatureFilter(ctx, tmp)
|
||||
}
|
||||
|
||||
var zeroVal *types.DocumentVersionSignatureFilter
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Document_controls_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
|
||||
var err error
|
||||
args := map[string]any{}
|
||||
@@ -33186,7 +33210,7 @@ func (ec *executionContext) _DocumentVersion_signatures(ctx context.Context, fie
|
||||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.DocumentVersion().Signatures(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*page.CursorKey), fc.Args["last"].(*int), fc.Args["before"].(*page.CursorKey), fc.Args["orderBy"].(*types.DocumentVersionSignatureOrder))
|
||||
return ec.resolvers.DocumentVersion().Signatures(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*page.CursorKey), fc.Args["last"].(*int), fc.Args["before"].(*page.CursorKey), fc.Args["orderBy"].(*types.DocumentVersionSignatureOrder), fc.Args["filter"].(*types.DocumentVersionSignatureFilter))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
@@ -71761,6 +71785,33 @@ func (ec *executionContext) unmarshalInputDocumentVersionOrder(ctx context.Conte
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputDocumentVersionSignatureFilter(ctx context.Context, obj any) (types.DocumentVersionSignatureFilter, error) {
|
||||
var it types.DocumentVersionSignatureFilter
|
||||
asMap := map[string]any{}
|
||||
for k, v := range obj.(map[string]any) {
|
||||
asMap[k] = v
|
||||
}
|
||||
|
||||
fieldsInOrder := [...]string{"states"}
|
||||
for _, k := range fieldsInOrder {
|
||||
v, ok := asMap[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch k {
|
||||
case "states":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("states"))
|
||||
data, err := ec.unmarshalODocumentVersionSignatureState2ᚕgithubᚗcomᚋgetproboᚋproboᚋpkgᚋcoredataᚐDocumentVersionSignatureStateᚄ(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
it.States = data
|
||||
}
|
||||
}
|
||||
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputDocumentVersionSignatureOrder(ctx context.Context, obj any) (types.DocumentVersionSignatureOrder, error) {
|
||||
var it types.DocumentVersionSignatureOrder
|
||||
asMap := map[string]any{}
|
||||
@@ -101215,6 +101266,14 @@ func (ec *executionContext) unmarshalODocumentVersionOrder2ᚖgithubᚗcomᚋget
|
||||
return &res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalODocumentVersionSignatureFilter2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐDocumentVersionSignatureFilter(ctx context.Context, v any) (*types.DocumentVersionSignatureFilter, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
}
|
||||
res, err := ec.unmarshalInputDocumentVersionSignatureFilter(ctx, v)
|
||||
return &res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalODocumentVersionSignatureOrder2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐDocumentVersionSignatureOrder(ctx context.Context, v any) (*types.DocumentVersionSignatureOrder, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
@@ -101223,6 +101282,82 @@ func (ec *executionContext) unmarshalODocumentVersionSignatureOrder2ᚖgithubᚗ
|
||||
return &res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalODocumentVersionSignatureState2ᚕgithubᚗcomᚋgetproboᚋproboᚋpkgᚋcoredataᚐDocumentVersionSignatureStateᚄ(ctx context.Context, v any) ([]coredata.DocumentVersionSignatureState, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
}
|
||||
var vSlice []any
|
||||
vSlice = graphql.CoerceList(v)
|
||||
var err error
|
||||
res := make([]coredata.DocumentVersionSignatureState, len(vSlice))
|
||||
for i := range vSlice {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i))
|
||||
res[i], err = ec.unmarshalNDocumentVersionSignatureState2githubᚗcomᚋgetproboᚋproboᚋpkgᚋcoredataᚐDocumentVersionSignatureState(ctx, vSlice[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalODocumentVersionSignatureState2ᚕgithubᚗcomᚋgetproboᚋproboᚋpkgᚋcoredataᚐDocumentVersionSignatureStateᚄ(ctx context.Context, sel ast.SelectionSet, v []coredata.DocumentVersionSignatureState) graphql.Marshaler {
|
||||
if v == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
ret := make(graphql.Array, len(v))
|
||||
var wg sync.WaitGroup
|
||||
isLen1 := len(v) == 1
|
||||
if !isLen1 {
|
||||
wg.Add(len(v))
|
||||
}
|
||||
for i := range v {
|
||||
i := i
|
||||
fc := &graphql.FieldContext{
|
||||
Index: &i,
|
||||
Result: &v[i],
|
||||
}
|
||||
ctx := graphql.WithFieldContext(ctx, fc)
|
||||
f := func(i int) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = nil
|
||||
}
|
||||
}()
|
||||
if !isLen1 {
|
||||
defer wg.Done()
|
||||
}
|
||||
ret[i] = ec.marshalNDocumentVersionSignatureState2githubᚗcomᚋgetproboᚋproboᚋpkgᚋcoredataᚐDocumentVersionSignatureState(ctx, sel, v[i])
|
||||
}
|
||||
if isLen1 {
|
||||
f(i)
|
||||
} else {
|
||||
go f(i)
|
||||
}
|
||||
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
for _, e := range ret {
|
||||
if e == graphql.Null {
|
||||
return graphql.Null
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
var (
|
||||
unmarshalODocumentVersionSignatureState2ᚕgithubᚗcomᚋgetproboᚋproboᚋpkgᚋcoredataᚐDocumentVersionSignatureStateᚄ = map[string]coredata.DocumentVersionSignatureState{
|
||||
"REQUESTED": coredata.DocumentVersionSignatureStateRequested,
|
||||
"SIGNED": coredata.DocumentVersionSignatureStateSigned,
|
||||
}
|
||||
marshalODocumentVersionSignatureState2ᚕgithubᚗcomᚋgetproboᚋproboᚋpkgᚋcoredataᚐDocumentVersionSignatureStateᚄ = map[coredata.DocumentVersionSignatureState]string{
|
||||
coredata.DocumentVersionSignatureStateRequested: "REQUESTED",
|
||||
coredata.DocumentVersionSignatureStateSigned: "SIGNED",
|
||||
}
|
||||
)
|
||||
|
||||
func (ec *executionContext) unmarshalODuration2ᚖtimeᚐDuration(ctx context.Context, v any) (*time.Duration, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -1088,6 +1088,10 @@ type DocumentVersionSignatureEdge struct {
|
||||
Node *DocumentVersionSignature `json:"node"`
|
||||
}
|
||||
|
||||
type DocumentVersionSignatureFilter struct {
|
||||
States []coredata.DocumentVersionSignatureState `json:"states,omitempty"`
|
||||
}
|
||||
|
||||
type DocumentVersionSignatureOrder struct {
|
||||
Field coredata.DocumentVersionSignatureOrderField `json:"field"`
|
||||
Direction page.OrderDirection `json:"direction"`
|
||||
|
||||
@@ -677,7 +677,7 @@ func (r *documentVersionResolver) Owner(ctx context.Context, obj *types.Document
|
||||
}
|
||||
|
||||
// Signatures is the resolver for the signatures field.
|
||||
func (r *documentVersionResolver) Signatures(ctx context.Context, obj *types.DocumentVersion, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DocumentVersionSignatureOrder) (*types.DocumentVersionSignatureConnection, error) {
|
||||
func (r *documentVersionResolver) Signatures(ctx context.Context, obj *types.DocumentVersion, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DocumentVersionSignatureOrder, filter *types.DocumentVersionSignatureFilter) (*types.DocumentVersionSignatureConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.DocumentVersionSignatureOrderField]{
|
||||
@@ -691,9 +691,15 @@ func (r *documentVersionResolver) Signatures(ctx context.Context, obj *types.Doc
|
||||
}
|
||||
}
|
||||
|
||||
var signatureStates []coredata.DocumentVersionSignatureState
|
||||
if filter != nil && filter.States != nil {
|
||||
signatureStates = filter.States
|
||||
}
|
||||
signatureFilter := coredata.NewDocumentVersionSignatureFilter(signatureStates)
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := prb.Documents.ListSignatures(ctx, obj.ID, cursor)
|
||||
page, err := prb.Documents.ListSignatures(ctx, obj.ID, cursor, signatureFilter)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list document version signatures: %w", err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user