@@ -300,6 +300,7 @@ func (p *Peoples) CountByOrganizationID(
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
filter *PeopleFilter,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
@@ -309,12 +310,14 @@ FROM
|
||||
WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, filter.SQLArguments())
|
||||
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
@@ -333,6 +336,7 @@ func (p *Peoples) LoadByOrganizationID(
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[PeopleOrderField],
|
||||
filter *PeopleFilter,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
@@ -354,13 +358,15 @@ WHERE
|
||||
%s
|
||||
AND organization_id = @organization_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{"organization_id": organizationID}
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, filter.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
|
||||
53
pkg/coredata/people_filter.go
Normal file
53
pkg/coredata/people_filter.go
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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 (
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type (
|
||||
PeopleFilter struct {
|
||||
excludeContractEnded *bool
|
||||
currentDate time.Time
|
||||
}
|
||||
)
|
||||
|
||||
func NewPeopleFilter(excludeContractEnded *bool) *PeopleFilter {
|
||||
return &PeopleFilter{
|
||||
excludeContractEnded: excludeContractEnded,
|
||||
currentDate: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
func (f *PeopleFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||
return pgx.StrictNamedArgs{
|
||||
"exclude_contract_ended": f.excludeContractEnded,
|
||||
"current_date": f.currentDate,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *PeopleFilter) SQLFragment() string {
|
||||
return `
|
||||
(
|
||||
CASE
|
||||
WHEN @exclude_contract_ended::boolean IS NOT NULL AND @exclude_contract_ended::boolean = true THEN
|
||||
(contract_end_date IS NULL OR contract_end_date >= @current_date::date)
|
||||
ELSE TRUE
|
||||
END
|
||||
)`
|
||||
}
|
||||
@@ -98,6 +98,7 @@ func (s PeopleService) GetByUserID(
|
||||
func (s PeopleService) CountForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
filter *coredata.PeopleFilter,
|
||||
) (int, error) {
|
||||
var count int
|
||||
|
||||
@@ -105,7 +106,7 @@ func (s PeopleService) CountForOrganizationID(
|
||||
ctx,
|
||||
func(conn pg.Conn) (err error) {
|
||||
peoples := coredata.Peoples{}
|
||||
count, err = peoples.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
|
||||
count, err = peoples.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID, filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot count peoples: %w", err)
|
||||
}
|
||||
@@ -125,6 +126,7 @@ func (s PeopleService) ListForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[coredata.PeopleOrderField],
|
||||
filter *coredata.PeopleFilter,
|
||||
) (*page.Page[*coredata.People, coredata.PeopleOrderField], error) {
|
||||
var peoples coredata.Peoples
|
||||
|
||||
@@ -137,6 +139,7 @@ func (s PeopleService) ListForOrganizationID(
|
||||
s.svc.scope,
|
||||
organizationID,
|
||||
cursor,
|
||||
filter,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -718,6 +718,10 @@ input RiskFilter {
|
||||
query: String
|
||||
}
|
||||
|
||||
input PeopleFilter {
|
||||
excludeContractEnded: Boolean
|
||||
}
|
||||
|
||||
input OrganizationFilter {
|
||||
trustCenterSlug: String
|
||||
}
|
||||
@@ -796,6 +800,7 @@ type Organization implements Node {
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: PeopleOrder
|
||||
filter: PeopleFilter
|
||||
): PeopleConnection! @goField(forceResolver: true)
|
||||
|
||||
documents(
|
||||
|
||||
@@ -665,7 +665,7 @@ type ComplexityRoot struct {
|
||||
LogoURL func(childComplexity int) int
|
||||
Measures func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MeasureOrderBy, filter *types.MeasureFilter) int
|
||||
Name func(childComplexity int) int
|
||||
Peoples func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PeopleOrderBy) int
|
||||
Peoples func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PeopleOrderBy, filter *types.PeopleFilter) int
|
||||
Risks func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.RiskOrderBy, filter *types.RiskFilter) int
|
||||
Tasks func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.TaskOrderBy) int
|
||||
TrustCenter func(childComplexity int) int
|
||||
@@ -1212,7 +1212,7 @@ type OrganizationResolver interface {
|
||||
Frameworks(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.FrameworkOrderBy) (*types.FrameworkConnection, error)
|
||||
Controls(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ControlOrderBy, filter *types.ControlFilter) (*types.ControlConnection, error)
|
||||
Vendors(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.VendorOrderBy) (*types.VendorConnection, error)
|
||||
Peoples(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PeopleOrderBy) (*types.PeopleConnection, error)
|
||||
Peoples(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PeopleOrderBy, filter *types.PeopleFilter) (*types.PeopleConnection, error)
|
||||
Documents(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DocumentOrderBy, filter *types.DocumentFilter) (*types.DocumentConnection, error)
|
||||
Measures(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MeasureOrderBy, filter *types.MeasureFilter) (*types.MeasureConnection, error)
|
||||
Risks(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.RiskOrderBy, filter *types.RiskFilter) (*types.RiskConnection, error)
|
||||
@@ -4009,7 +4009,7 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Organization.Peoples(childComplexity, args["first"].(*int), args["after"].(*page.CursorKey), args["last"].(*int), args["before"].(*page.CursorKey), args["orderBy"].(*types.PeopleOrderBy)), true
|
||||
return e.complexity.Organization.Peoples(childComplexity, args["first"].(*int), args["after"].(*page.CursorKey), args["last"].(*int), args["before"].(*page.CursorKey), args["orderBy"].(*types.PeopleOrderBy), args["filter"].(*types.PeopleFilter)), true
|
||||
|
||||
case "Organization.risks":
|
||||
if e.complexity.Organization.Risks == nil {
|
||||
@@ -5551,6 +5551,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||
ec.unmarshalInputMeasureOrder,
|
||||
ec.unmarshalInputOrganizationFilter,
|
||||
ec.unmarshalInputOrganizationOrder,
|
||||
ec.unmarshalInputPeopleFilter,
|
||||
ec.unmarshalInputPeopleOrder,
|
||||
ec.unmarshalInputPublishDocumentVersionInput,
|
||||
ec.unmarshalInputRemoveUserInput,
|
||||
@@ -6402,6 +6403,10 @@ input RiskFilter {
|
||||
query: String
|
||||
}
|
||||
|
||||
input PeopleFilter {
|
||||
excludeContractEnded: Boolean
|
||||
}
|
||||
|
||||
input OrganizationFilter {
|
||||
trustCenterSlug: String
|
||||
}
|
||||
@@ -6480,6 +6485,7 @@ type Organization implements Node {
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: PeopleOrder
|
||||
filter: PeopleFilter
|
||||
): PeopleConnection! @goField(forceResolver: true)
|
||||
|
||||
documents(
|
||||
@@ -12229,6 +12235,11 @@ func (ec *executionContext) field_Organization_peoples_args(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
args["orderBy"] = arg4
|
||||
arg5, err := ec.field_Organization_peoples_argsFilter(ctx, rawArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args["filter"] = arg5
|
||||
return args, nil
|
||||
}
|
||||
func (ec *executionContext) field_Organization_peoples_argsFirst(
|
||||
@@ -12296,6 +12307,19 @@ func (ec *executionContext) field_Organization_peoples_argsOrderBy(
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Organization_peoples_argsFilter(
|
||||
ctx context.Context,
|
||||
rawArgs map[string]any,
|
||||
) (*types.PeopleFilter, error) {
|
||||
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("filter"))
|
||||
if tmp, ok := rawArgs["filter"]; ok {
|
||||
return ec.unmarshalOPeopleFilter2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐPeopleFilter(ctx, tmp)
|
||||
}
|
||||
|
||||
var zeroVal *types.PeopleFilter
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Organization_risks_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
|
||||
var err error
|
||||
args := map[string]any{}
|
||||
@@ -30201,7 +30225,7 @@ func (ec *executionContext) _Organization_peoples(ctx context.Context, field gra
|
||||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Organization().Peoples(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*page.CursorKey), fc.Args["last"].(*int), fc.Args["before"].(*page.CursorKey), fc.Args["orderBy"].(*types.PeopleOrderBy))
|
||||
return ec.resolvers.Organization().Peoples(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*page.CursorKey), fc.Args["last"].(*int), fc.Args["before"].(*page.CursorKey), fc.Args["orderBy"].(*types.PeopleOrderBy), fc.Args["filter"].(*types.PeopleFilter))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
@@ -45554,6 +45578,33 @@ func (ec *executionContext) unmarshalInputOrganizationOrder(ctx context.Context,
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputPeopleFilter(ctx context.Context, obj any) (types.PeopleFilter, error) {
|
||||
var it types.PeopleFilter
|
||||
asMap := map[string]any{}
|
||||
for k, v := range obj.(map[string]any) {
|
||||
asMap[k] = v
|
||||
}
|
||||
|
||||
fieldsInOrder := [...]string{"excludeContractEnded"}
|
||||
for _, k := range fieldsInOrder {
|
||||
v, ok := asMap[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch k {
|
||||
case "excludeContractEnded":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("excludeContractEnded"))
|
||||
data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
it.ExcludeContractEnded = data
|
||||
}
|
||||
}
|
||||
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputPeopleOrder(ctx context.Context, obj any) (types.PeopleOrderBy, error) {
|
||||
var it types.PeopleOrderBy
|
||||
asMap := map[string]any{}
|
||||
@@ -63240,6 +63291,14 @@ func (ec *executionContext) marshalOPeople2ᚖgithubᚗcomᚋgetproboᚋproboᚋ
|
||||
return ec._People(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalOPeopleFilter2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐPeopleFilter(ctx context.Context, v any) (*types.PeopleFilter, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
}
|
||||
res, err := ec.unmarshalInputPeopleFilter(ctx, v)
|
||||
return &res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalOPeopleKind2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋcoredataᚐPeopleKind(ctx context.Context, v any) (*coredata.PeopleKind, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -30,6 +30,7 @@ type (
|
||||
|
||||
Resolver any
|
||||
ParentID gid.GID
|
||||
Filters *coredata.PeopleFilter
|
||||
}
|
||||
)
|
||||
|
||||
@@ -37,6 +38,7 @@ func NewPeopleConnection(
|
||||
p *page.Page[*coredata.People, coredata.PeopleOrderField],
|
||||
parentType any,
|
||||
parentID gid.GID,
|
||||
filters *coredata.PeopleFilter,
|
||||
) *PeopleConnection {
|
||||
var edges = make([]*PeopleEdge, len(p.Data))
|
||||
|
||||
@@ -50,6 +52,7 @@ func NewPeopleConnection(
|
||||
|
||||
Resolver: parentType,
|
||||
ParentID: parentID,
|
||||
Filters: filters,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -907,6 +907,10 @@ type PeopleEdge struct {
|
||||
Node *People `json:"node"`
|
||||
}
|
||||
|
||||
type PeopleFilter struct {
|
||||
ExcludeContractEnded *bool `json:"excludeContractEnded,omitempty"`
|
||||
}
|
||||
|
||||
type PublishDocumentVersionInput struct {
|
||||
DocumentID gid.GID `json:"documentId"`
|
||||
Changelog *string `json:"changelog,omitempty"`
|
||||
|
||||
@@ -2587,7 +2587,7 @@ func (r *organizationResolver) Vendors(ctx context.Context, obj *types.Organizat
|
||||
}
|
||||
|
||||
// Peoples is the resolver for the peoples field.
|
||||
func (r *organizationResolver) Peoples(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PeopleOrderBy) (*types.PeopleConnection, error) {
|
||||
func (r *organizationResolver) Peoples(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PeopleOrderBy, filter *types.PeopleFilter) (*types.PeopleConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.PeopleOrderField]{
|
||||
@@ -2603,12 +2603,17 @@ func (r *organizationResolver) Peoples(ctx context.Context, obj *types.Organizat
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := prb.Peoples.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
var peopleFilter = coredata.NewPeopleFilter(nil)
|
||||
if filter != nil {
|
||||
peopleFilter = coredata.NewPeopleFilter(filter.ExcludeContractEnded)
|
||||
}
|
||||
|
||||
page, err := prb.Peoples.ListForOrganizationID(ctx, obj.ID, cursor, peopleFilter)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list organization peoples: %w", err))
|
||||
}
|
||||
|
||||
return types.NewPeopleConnection(page, r, obj.ID), nil
|
||||
return types.NewPeopleConnection(page, r, obj.ID, peopleFilter), nil
|
||||
}
|
||||
|
||||
// Documents is the resolver for the documents field.
|
||||
@@ -2819,7 +2824,7 @@ func (r *peopleConnectionResolver) TotalCount(ctx context.Context, obj *types.Pe
|
||||
|
||||
switch obj.Resolver.(type) {
|
||||
case *organizationResolver:
|
||||
count, err := prb.Peoples.CountForOrganizationID(ctx, obj.ParentID)
|
||||
count, err := prb.Peoples.CountForOrganizationID(ctx, obj.ParentID, obj.Filters)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count peoples: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user