MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / handleGetUserDocAccessSpan

Method handleGetUserDocAccessSpan

rest/diagnostic_api.go:222–326  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

220}
221
222func (h *handler) handleGetUserDocAccessSpan() error {
223 h.assertAdminOnly()
224 user, err := h.db.Authenticator(h.ctx()).GetUser(internalUserName(mux.Vars(h.rq)["name"]))
225 if err != nil {
226 return fmt.Errorf("could not get user %s: %w", user.Name(), err)
227 }
228 if user == nil {
229 return kNotFoundError
230 }
231 ks := h.PathVar("keyspace")
232
233 docids := h.getQuery("docids")
234 docidsList := strings.Split(docids, ",")
235 var docList []*db.Document
236
237 var scope, coll string
238 parts := strings.Split(ks, base.ScopeCollectionSeparator)
239 switch len(parts) {
240 case 1:
241 // if default collection, some calls using {{.keyspace}} will call /db/
242 scope = "_default"
243 coll = "_default"
244 case 3:
245 scope = parts[1]
246 coll = parts[2]
247 default:
248 return fmt.Errorf("unable to get scope and collection from keyspace")
249 }
250
251 if err != nil {
252 return err
253 }
254
255 keyspace := scope + "." + coll
256
257 for _, docID := range docidsList {
258 if docID == "" {
259 return base.HTTPErrorf(http.StatusBadRequest, "empty doc id given in request")
260 }
261 doc, err := h.collection.GetDocument(h.ctx(), docID, db.DocUnmarshalSync)
262 if doc == nil {
263 return base.HTTPErrorf(http.StatusNotFound, "doc %s not found", docID)
264 }
265 if err != nil {
266 return err
267 }
268 docList = append(docList, doc)
269 }
270
271 resp := make(map[string]map[string]channelHistory)
272 for _, doc := range docList {
273 docChannelToSeqs := populateDocChannelInfo(*doc)
274 userChannels, err := h.getAllUserChannelsResponse(user)
275 if err != nil {
276 return err
277 }
278
279 // Only keep current keyspace

Callers

nothing calls this directly

Calls 15

assertAdminOnlyMethod · 0.95
ctxMethod · 0.95
PathVarMethod · 0.95
getQueryMethod · 0.95
writeRawJSONMethod · 0.95
HTTPErrorfFunction · 0.92
JSONMarshalFunction · 0.92
internalUserNameFunction · 0.85
populateDocChannelInfoFunction · 0.85
GetUserMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected