Skip to content

Commit

Permalink
Make revCacheLoaderForDocument work for winning revision channels not…
Browse files Browse the repository at this point in the history
… in history
  • Loading branch information
bbrks committed Sep 13, 2023
1 parent 0b4b1ae commit 9530995
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 1 addition & 6 deletions db/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions db/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion db/revision_cache_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 9530995

Please sign in to comment.