(ctx context.Context, ddocName string, viewName string, options map[string]interface{})
| 241 | } |
| 242 | |
| 243 | func (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 |
| 282 | func filterViewResult(input sgbucket.ViewResult, user auth.User, applyChannelFiltering bool) (result sgbucket.ViewResult, err error) { |
no test coverage detected