Determine whether the specified revision was a channel removal, based on doc.Channels. If so, construct the standard document body for a removal notification (_removed=true) Set of channels returned from IsChannelRemoval are "Active" channels and NOT "Removed".
(ctx context.Context, revID string)
| 1086 | // removal notification (_removed=true) |
| 1087 | // Set of channels returned from IsChannelRemoval are "Active" channels and NOT "Removed". |
| 1088 | func (doc *Document) IsChannelRemoval(ctx context.Context, revID string) (bodyBytes []byte, history Revisions, channels base.Set, isRemoval bool, isDelete bool, err error) { |
| 1089 | |
| 1090 | removedChannels := make(base.Set) |
| 1091 | |
| 1092 | // Iterate over the document's channel history, looking for channels that were removed at revID. If found, also identify whether the removal was a tombstone. |
| 1093 | for channel, removal := range doc.Channels { |
| 1094 | if removal != nil && removal.Rev.RevTreeID == revID { |
| 1095 | removedChannels[channel] = struct{}{} |
| 1096 | if removal.Deleted == true { |
| 1097 | isDelete = true |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | // If no matches found, return isRemoval=false |
| 1102 | if len(removedChannels) == 0 { |
| 1103 | return nil, nil, nil, false, false, nil |
| 1104 | } |
| 1105 | |
| 1106 | activeChannels, ok := doc.channelsForRevTreeID(revID) |
| 1107 | if !ok { |
| 1108 | // can't find rev (it was either an unknown rev, or an old non-leaf revision that we can't determine channels for) |
| 1109 | return nil, nil, nil, false, false, nil |
| 1110 | } |
| 1111 | |
| 1112 | // Build revision history for revID |
| 1113 | revHistory, err := doc.History.getHistory(revID) |
| 1114 | if err != nil { |
| 1115 | return nil, nil, nil, false, false, err |
| 1116 | } |
| 1117 | |
| 1118 | // If there's no history (because the revision has been pruned from the rev tree), treat revision history as only the specified rev id. |
| 1119 | if len(revHistory) == 0 { |
| 1120 | revHistory = []string{revID} |
| 1121 | } |
| 1122 | history = encodeRevisions(ctx, doc.ID, revHistory) |
| 1123 | |
| 1124 | // Construct removal body |
| 1125 | // doc ID and rev ID aren't required to be inserted here, as both of those are available in the request. |
| 1126 | bodyBytes = []byte(RemovedRedactedDocument) |
| 1127 | |
| 1128 | return bodyBytes, history, activeChannels, true, isDelete, nil |
| 1129 | } |
| 1130 | |
| 1131 | // Updates a document's channel/role UserAccessMap with new access settings from an AccessMap. |
| 1132 | // Returns an array of the user/role names whose access has changed as a result. |
no test coverage detected