Skip to content

Commit 9530995

Browse files
committed
Make revCacheLoaderForDocument work for winning revision channels not in history
1 parent 0b4b1ae commit 9530995

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

db/crud.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,7 @@ func (col *DatabaseCollectionWithUser) authorizeDoc(doc *Document, revid string)
552552
}
553553

554554
if revid == doc.CurrentRev {
555-
ch := base.SetOf()
556-
for channelName, channelRemoval := range doc.Channels {
557-
if channelRemoval == nil || channelRemoval.Seq == 0 {
558-
ch.Add(channelName)
559-
}
560-
}
555+
ch := doc.currentChannels()
561556
return col.user.AuthorizeAnyCollectionChannel(col.ScopeName, col.Name, ch)
562557
} else if rev := doc.History[revid]; rev != nil {
563558
// Authenticate against specific revision:

db/document.go

+11
Original file line numberDiff line numberDiff line change
@@ -1226,3 +1226,14 @@ func (doc *Document) MarshalWithXattr() (data []byte, xdata []byte, err error) {
12261226

12271227
return data, xdata, nil
12281228
}
1229+
1230+
// Returns a set of the current (winning revision's) channels for the document.
1231+
func (doc *Document) currentChannels() base.Set {
1232+
ch := base.SetOf()
1233+
for channelName, channelRemoval := range doc.Channels {
1234+
if channelRemoval == nil || channelRemoval.Seq == 0 {
1235+
ch.Add(channelName)
1236+
}
1237+
}
1238+
return ch
1239+
}

db/revision_cache_interface.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ func revCacheLoaderForDocument(ctx context.Context, backingStore RevisionCacheBa
283283
return bodyBytes, body, history, channels, removed, nil, deleted, nil, getHistoryErr
284284
}
285285
history = encodeRevisions(doc.ID, validatedHistory)
286-
channels = doc.History[revid].Channels
286+
if doc.CurrentRev == revid {
287+
channels = doc.currentChannels()
288+
} else {
289+
channels = doc.History[revid].Channels
290+
}
287291

288292
return bodyBytes, body, history, channels, removed, attachments, deleted, doc.Expiry, err
289293
}

0 commit comments

Comments
 (0)