Skip to content

Commit c4c0e61

Browse files
authored
chore: fix wildcard subject agreement in datastore LR (#2831)
1 parent 9f73d87 commit c4c0e61

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

pkg/query/datastore.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,28 +144,8 @@ func (r *RelationIterator) checkWildcardImpl(ctx *Context, resources []Object, s
144144
if err != nil {
145145
return nil, err
146146
}
147-
148-
// Transform the wildcard relationships to use the concrete subject
149-
return func(yield func(Path, error) bool) {
150-
for rel, err := range relIter {
151-
if err != nil {
152-
if !yield(Path{}, err) {
153-
return
154-
}
155-
continue
156-
}
157-
158-
// Replace the wildcard subject with the concrete subject
159-
concreteRel := rel
160-
concreteRel.Subject = subject
161-
162-
// Convert to Path
163-
path := FromRelationship(concreteRel)
164-
if !yield(path, nil) {
165-
return
166-
}
167-
}
168-
}, nil
147+
// We rewrite the subject to the concrete subject before returning the paths
148+
return RewriteSubject(convertRelationSeqToPathSeq(iter.Seq2[tuple.Relationship, error](relIter)), subject), nil
169149
}
170150

171151
func (r *RelationIterator) IterSubjectsImpl(ctx *Context, resource Object) (PathSeq, error) {
@@ -276,7 +256,8 @@ func (r *RelationIterator) iterResourcesWildcardImpl(ctx *Context, subject Objec
276256
return nil, err
277257
}
278258

279-
return convertRelationSeqToPathSeq(iter.Seq2[tuple.Relationship, error](relIter)), nil
259+
// We rewrite the subject to the concrete subject before returning the paths
260+
return RewriteSubject(convertRelationSeqToPathSeq(iter.Seq2[tuple.Relationship, error](relIter)), subject), nil
280261
}
281262

282263
func (r *RelationIterator) Clone() Iterator {

pkg/query/path.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,24 @@ func DeduplicatePathSeq(seq PathSeq) PathSeq {
362362
}
363363
}
364364
}
365+
366+
func RewriteSubject(seq PathSeq, subject ObjectAndRelation) PathSeq {
367+
return func(yield func(Path, error) bool) {
368+
for path, err := range seq {
369+
if err != nil {
370+
if !yield(Path{}, err) {
371+
return
372+
}
373+
continue
374+
}
375+
376+
// Replace the wildcard subject with the concrete subject
377+
path.Subject = subject
378+
379+
// Convert to Path
380+
if !yield(path, nil) {
381+
return
382+
}
383+
}
384+
}
385+
}

0 commit comments

Comments
 (0)