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

Method QueryDesignDoc

db/design_doc.go:243–279  ·  view source on GitHub ↗
(ctx context.Context, ddocName string, viewName string, options map[string]interface{})

Source from the content-addressed store, hash-verified

241}
242
243func (db *Database) QueryDesignDoc(ctx context.Context, ddocName string, viewName string, options map[string]interface{}) (*sgbucket.ViewResult, error) {
244
245 // Regular users have limitations on what they can query
246 if db.user != nil {
247 // * Regular users can only query when user views are enabled
248 if !db.GetUserViewsEnabled() {
249 return nil, base.HTTPErrorf(http.StatusForbidden, "forbidden")
250 }
251 // * Admins can query any design doc including the internal ones
252 // * Regular users can query non-internal design docs
253 if isInternalDDoc(ddocName) {
254 return nil, base.HTTPErrorf(http.StatusForbidden, "forbidden")
255 }
256 }
257 vs, err := getViewStoreForDefaultCollection(db.DatabaseContext)
258 if err != nil {
259 return nil, err
260 }
261 result, err := vs.View(ctx, ddocName, viewName, options)
262 if err != nil {
263 return nil, err
264 }
265 if isInternalDDoc(ddocName) {
266 if options["include_docs"] == true {
267 for _, row := range result.Rows {
268 stripSyncProperty(row)
269 }
270 }
271 return &result, nil
272 }
273 applyChannelFiltering := options["reduce"] != true && db.GetUserViewsEnabled()
274 result, err = filterViewResult(result, db.user, applyChannelFiltering)
275 if err != nil {
276 return nil, err
277 }
278 return &result, nil
279}
280
281// Cleans up the Value property, and removes rows that aren't visible to the current user
282func filterViewResult(input sgbucket.ViewResult, user auth.User, applyChannelFiltering bool) (result sgbucket.ViewResult, err error) {

Callers 1

handleViewMethod · 0.80

Calls 7

HTTPErrorfFunction · 0.92
isInternalDDocFunction · 0.85
stripSyncPropertyFunction · 0.85
filterViewResultFunction · 0.85
GetUserViewsEnabledMethod · 0.80
ViewMethod · 0.45

Tested by

no test coverage detected