Query to compute the set of roles granted to the specified user via the Sync Function
(ctx context.Context, username string)
| 458 | |
| 459 | // Query to compute the set of roles granted to the specified user via the Sync Function |
| 460 | func (c *DatabaseCollection) QueryRoleAccess(ctx context.Context, username string) (sgbucket.QueryResultIterator, error) { |
| 461 | |
| 462 | // View Query |
| 463 | if c.useViews() { |
| 464 | opts := map[string]interface{}{"stale": false, "key": username} |
| 465 | return c.dbCtx.ViewQueryWithStats(ctx, c.dataStore, DesignDocSyncGateway(), ViewRoleAccess, opts) |
| 466 | } |
| 467 | |
| 468 | // N1QL Query |
| 469 | if username == "" { |
| 470 | base.WarnfCtx(ctx, "QueryRoleAccess called with empty username") |
| 471 | return &EmptyResultIterator{}, nil |
| 472 | } |
| 473 | |
| 474 | accessQueryStatement := c.buildRoleAccessQuery(username) |
| 475 | params := make(map[string]interface{}, 0) |
| 476 | params[QueryParamUserName] = username |
| 477 | return N1QLQueryWithStats(ctx, c.dataStore, QueryTypeRoleAccess, accessQueryStatement, params, base.RequestPlus, QueryRoleAccess.adhoc, c.dbStats(), c.slowQueryWarningThreshold()) |
| 478 | } |
| 479 | |
| 480 | // Builds the query statement for a roleAccess N1QL query. |
| 481 | func (c *DatabaseCollection) buildRoleAccessQuery(username string) string { |