Add cookie pattern entity to group detected cookies
Introduce a cookie_patterns table that groups cookies sharing a common prefix (e.g. phc_*) into a single manageable row. Every cookie now belongs to a pattern (EXACT or PREFIX match type). Category, description, and display metadata move from cookies to patterns, making patterns the unit of management and display in the console and published snapshots. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -319,7 +319,7 @@ func (r *cookieCategoryResolver) Cookies(ctx context.Context, obj *types.CookieC
|
||||
|
||||
p := page.NewPage(cookies, cursor)
|
||||
|
||||
return types.NewCookieConnection(p, r, obj.ID), nil
|
||||
return types.NewCookieConnection(p, r, obj.ID, obj.ID), nil
|
||||
}
|
||||
|
||||
// Permission is the resolver for the permission field.
|
||||
@@ -759,7 +759,7 @@ func (r *mutationResolver) MoveCookieToCategory(ctx context.Context, input types
|
||||
}
|
||||
|
||||
return &types.MoveCookieToCategoryPayload{
|
||||
Cookie: types.NewCookie(result.Cookie),
|
||||
Cookie: types.NewCookie(result.Cookie, input.TargetCookieCategoryID),
|
||||
CookieBanner: types.NewCookieBanner(result.Banner),
|
||||
}, nil
|
||||
}
|
||||
@@ -804,7 +804,7 @@ func (r *mutationResolver) CreateCookie(ctx context.Context, input types.CreateC
|
||||
}
|
||||
|
||||
return &types.CreateCookiePayload{
|
||||
CookieEdge: types.NewCookieEdge(cookie, coredata.CookieOrderFieldCreatedAt),
|
||||
CookieEdge: types.NewCookieEdge(cookie, coredata.CookieOrderFieldCreatedAt, input.CookieCategoryID),
|
||||
CookieBanner: types.NewCookieBanner(banner),
|
||||
}, nil
|
||||
}
|
||||
@@ -841,6 +841,13 @@ func (r *mutationResolver) UpdateCookie(ctx context.Context, input types.UpdateC
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
patternScope := coredata.NewScopeFromObjectID(cookie.CookiePatternID)
|
||||
pattern, err := r.cookieBanner.GetCookiePattern(ctx, patternScope, cookie.CookiePatternID)
|
||||
if err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot get cookie pattern", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
bannerScope := coredata.NewScopeFromObjectID(cookie.CookieBannerID)
|
||||
banner, err := r.cookieBanner.GetCookieBanner(ctx, bannerScope, cookie.CookieBannerID)
|
||||
if err != nil {
|
||||
@@ -849,7 +856,7 @@ func (r *mutationResolver) UpdateCookie(ctx context.Context, input types.UpdateC
|
||||
}
|
||||
|
||||
return &types.UpdateCookiePayload{
|
||||
Cookie: types.NewCookie(cookie),
|
||||
Cookie: types.NewCookie(cookie, pattern.CookieCategoryID),
|
||||
CookieBanner: types.NewCookieBanner(banner),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -37,11 +37,12 @@ func NewCookieConnection(
|
||||
p *page.Page[*coredata.Cookie, coredata.CookieOrderField],
|
||||
parentType any,
|
||||
parentID gid.GID,
|
||||
cookieCategoryID gid.GID,
|
||||
) *CookieConnection {
|
||||
edges := make([]*CookieEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
edges[i] = NewCookieEdge(p.Data[i], p.Cursor.OrderBy.Field)
|
||||
edges[i] = NewCookieEdge(p.Data[i], p.Cursor.OrderBy.Field, cookieCategoryID)
|
||||
}
|
||||
|
||||
return &CookieConnection{
|
||||
@@ -53,27 +54,26 @@ func NewCookieConnection(
|
||||
}
|
||||
}
|
||||
|
||||
func NewCookieEdge(c *coredata.Cookie, orderBy coredata.CookieOrderField) *CookieEdge {
|
||||
func NewCookieEdge(c *coredata.Cookie, orderBy coredata.CookieOrderField, cookieCategoryID gid.GID) *CookieEdge {
|
||||
return &CookieEdge{
|
||||
Cursor: c.CursorKey(orderBy),
|
||||
Node: NewCookie(c),
|
||||
Node: NewCookie(c, cookieCategoryID),
|
||||
}
|
||||
}
|
||||
|
||||
func NewCookie(c *coredata.Cookie) *Cookie {
|
||||
func NewCookie(c *coredata.Cookie, cookieCategoryID gid.GID) *Cookie {
|
||||
return &Cookie{
|
||||
ID: c.ID,
|
||||
CookieCategory: &CookieCategory{
|
||||
ID: c.CookieCategoryID,
|
||||
ID: cookieCategoryID,
|
||||
CookieBanner: &CookieBanner{
|
||||
ID: c.CookieBannerID,
|
||||
},
|
||||
},
|
||||
Name: c.Name,
|
||||
Duration: c.Duration,
|
||||
Description: c.Description,
|
||||
Source: c.Source,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
Name: c.Name,
|
||||
Duration: c.Duration,
|
||||
Source: c.Source,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user