Filter consent records by version number

Replace the opaque cookieBannerVersionId filter with an
integer version filter. The SQL filter now resolves the
version number via a subquery against cookie_banner_versions.

Also fix the CookieBannerVersion resolver on consent records
to load the full version from the database instead of
returning a stub with only the ID set (which caused the
version to always display as 0).

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-27 15:09:21 +04:00
parent 4147239fbc
commit 84632fe795
6 changed files with 75 additions and 38 deletions

View File

@@ -13,7 +13,6 @@ import (
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/cookiebanner"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/page"
"go.probo.inc/probo/pkg/probo"
"go.probo.inc/probo/pkg/server/api/console/v1/schema"
@@ -144,17 +143,17 @@ func (r *cookieBannerResolver) ConsentRecords(ctx context.Context, obj *types.Co
scope := coredata.NewScopeFromObjectID(obj.ID)
var (
action *coredata.CookieConsentAction
visitorID *string
cookieBannerVersionID *gid.GID
action *coredata.CookieConsentAction
visitorID *string
version *int
)
if filter != nil {
action = filter.Action
visitorID = filter.VisitorID
cookieBannerVersionID = filter.CookieBannerVersionID
version = filter.Version
}
coredataFilter := coredata.NewCookieConsentRecordFilter(action, visitorID, cookieBannerVersionID)
coredataFilter := coredata.NewCookieConsentRecordFilter(action, visitorID, version)
records, err := r.cookieBanner.ListCookieConsentRecordsForBanner(ctx, scope, obj.ID, cursor, coredataFilter)
if err != nil {

View File

@@ -7,8 +7,10 @@ package console_v1
import (
"context"
"errors"
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/cookiebanner"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/probo"
"go.probo.inc/probo/pkg/server/api/console/v1/schema"
@@ -23,7 +25,32 @@ func (r *cookieConsentRecordResolver) CookieBanner(ctx context.Context, obj *typ
// CookieBannerVersion is the resolver for the cookieBannerVersion field.
func (r *cookieConsentRecordResolver) CookieBannerVersion(ctx context.Context, obj *types.CookieConsentRecord) (*types.CookieBannerVersion, error) {
return obj.CookieBannerVersion, nil
if obj.CookieBannerVersion == nil {
return nil, nil
}
if err := r.authorize(ctx, obj.CookieBannerVersion.ID, probo.ActionCookieBannerVersionGet); err != nil {
return nil, err
}
scope := coredata.NewScopeFromObjectID(obj.CookieBannerVersion.ID)
version, err := r.cookieBanner.GetCookieBannerVersion(ctx, scope, obj.CookieBannerVersion.ID)
if err != nil {
if errors.Is(err, cookiebanner.ErrVersionNotFound) {
return nil, nil
}
r.logger.ErrorCtx(ctx, "cannot get cookie banner version", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
return &types.CookieBannerVersion{
ID: version.ID,
Version: version.Version,
State: string(version.State),
CreatedAt: version.CreatedAt,
UpdatedAt: version.UpdatedAt,
}, nil
}
// TotalCount is the resolver for the totalCount field.

View File

@@ -53,7 +53,7 @@ input CookieConsentRecordOrder
input CookieConsentRecordFilter {
action: CookieConsentAction
visitorId: String
cookieBannerVersionId: ID
version: Int
}
type CookieConsentRecord implements Node {