Returns user information for all users (ID, disabled, email)
(ctx context.Context, limit int)
| 1262 | |
| 1263 | // Returns user information for all users (ID, disabled, email) |
| 1264 | func (db *DatabaseContext) GetUsers(ctx context.Context, limit int) (users []auth.PrincipalConfig, err error) { |
| 1265 | |
| 1266 | if db.Options.UseViews { |
| 1267 | return nil, errors.New("GetUsers not supported when running with useViews=true") |
| 1268 | } |
| 1269 | |
| 1270 | // While using SyncDocs index, must set startKey to the user prefix to avoid unwanted interaction between |
| 1271 | // limit handling and startKey (non-user _sync: prefixed documents being included in the query limit evaluation). |
| 1272 | // This doesn't happen for AllPrincipalIDs, I believe because the role check forces query to not assume |
| 1273 | // a contiguous set of results |
| 1274 | dbUserKeyPrefix := db.MetadataKeys.UserKeyPrefix() |
| 1275 | userRe, err := regexp.Compile(`^` + dbUserKeyPrefix + `[^:]*$`) |
| 1276 | if err != nil { |
| 1277 | return nil, err |
| 1278 | } |
| 1279 | startKey := dbUserKeyPrefix |
| 1280 | paginationLimit := db.Options.QueryPaginationLimit |
| 1281 | if paginationLimit == 0 { |
| 1282 | paginationLimit = DefaultQueryPaginationLimit |
| 1283 | } |
| 1284 | |
| 1285 | // If the requested limit is lower than the pagination limit, use requested limit as pagination limit |
| 1286 | if limit > 0 && limit < paginationLimit { |
| 1287 | paginationLimit = limit |
| 1288 | } |
| 1289 | |
| 1290 | users = []auth.PrincipalConfig{} |
| 1291 | |
| 1292 | totalCount := 0 |
| 1293 | |
| 1294 | outerLoop: |
| 1295 | for { |
| 1296 | results, err := db.QueryUsers(ctx, startKey, paginationLimit) |
| 1297 | if err != nil { |
| 1298 | return nil, err |
| 1299 | } |
| 1300 | |
| 1301 | resultCount := 0 |
| 1302 | for { |
| 1303 | // startKey is inclusive, so need to skip first result if using non-empty startKey, as this results in an overlapping result |
| 1304 | var skipAddition bool |
| 1305 | if resultCount == 0 && startKey != dbUserKeyPrefix { |
| 1306 | skipAddition = true |
| 1307 | } |
| 1308 | |
| 1309 | var queryRow QueryUsersRow |
| 1310 | found := results.Next(ctx, &queryRow) |
| 1311 | if !found { |
| 1312 | break |
| 1313 | } |
| 1314 | if !strings.HasPrefix(queryRow.ID, dbUserKeyPrefix) { |
| 1315 | break |
| 1316 | } |
| 1317 | |
| 1318 | startKey = queryRow.ID |
| 1319 | resultCount++ |
| 1320 | if !userRe.MatchString(queryRow.ID) { |
| 1321 | continue |