From 95309955df2e38199d128c0bc115efecf61756e3 Mon Sep 17 00:00:00 2001 From: Ben Brooks Date: Wed, 13 Sep 2023 15:41:47 +0100 Subject: [PATCH] Make revCacheLoaderForDocument work for winning revision channels not in history --- db/crud.go | 7 +------ db/document.go | 11 +++++++++++ db/revision_cache_interface.go | 6 +++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/db/crud.go b/db/crud.go index 146970cba7..bdbbeb2e9f 100644 --- a/db/crud.go +++ b/db/crud.go @@ -552,12 +552,7 @@ func (col *DatabaseCollectionWithUser) authorizeDoc(doc *Document, revid string) } if revid == doc.CurrentRev { - ch := base.SetOf() - for channelName, channelRemoval := range doc.Channels { - if channelRemoval == nil || channelRemoval.Seq == 0 { - ch.Add(channelName) - } - } + ch := doc.currentChannels() return col.user.AuthorizeAnyCollectionChannel(col.ScopeName, col.Name, ch) } else if rev := doc.History[revid]; rev != nil { // Authenticate against specific revision: diff --git a/db/document.go b/db/document.go index 9e03d40fd5..86f4031264 100644 --- a/db/document.go +++ b/db/document.go @@ -1226,3 +1226,14 @@ func (doc *Document) MarshalWithXattr() (data []byte, xdata []byte, err error) { return data, xdata, nil } + +// Returns a set of the current (winning revision's) channels for the document. +func (doc *Document) currentChannels() base.Set { + ch := base.SetOf() + for channelName, channelRemoval := range doc.Channels { + if channelRemoval == nil || channelRemoval.Seq == 0 { + ch.Add(channelName) + } + } + return ch +} diff --git a/db/revision_cache_interface.go b/db/revision_cache_interface.go index abdc2faa9e..df03649edb 100644 --- a/db/revision_cache_interface.go +++ b/db/revision_cache_interface.go @@ -283,7 +283,11 @@ func revCacheLoaderForDocument(ctx context.Context, backingStore RevisionCacheBa return bodyBytes, body, history, channels, removed, nil, deleted, nil, getHistoryErr } history = encodeRevisions(doc.ID, validatedHistory) - channels = doc.History[revid].Channels + if doc.CurrentRev == revid { + channels = doc.currentChannels() + } else { + channels = doc.History[revid].Channels + } return bodyBytes, body, history, channels, removed, attachments, deleted, doc.Expiry, err }