Add /dumps/rankUsers?rank=<rank> to get all Users with a certain rank
This commit is contained in:
parent
0ca0dea102
commit
d90981bdec
@ -153,6 +153,23 @@ public final class User {
|
||||
usersCollection.find(new Document("lastUsernameLower", lastUsernameLower.toLowerCase())).first(SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
public static void findByIdGrouped(Set<UUID> search, SingleResultCallback<Map<UUID, User>> callback) {
|
||||
usersCollection.find(new Document("_id", new Document("$in", search))).into(new LinkedList<>(), SyncUtils.vertxWrap((users, error) -> {
|
||||
if (error != null) {
|
||||
callback.onResult(null, error);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<UUID, User> result = new HashMap<>();
|
||||
|
||||
for (User user : users) {
|
||||
result.put(user.getId(), user);
|
||||
}
|
||||
|
||||
callback.onResult(result, null);
|
||||
}));
|
||||
}
|
||||
|
||||
public static void findOrCreateByIdGrouped(Map<UUID, String> search, SingleResultCallback<Map<UUID, User>> callback) {
|
||||
usersCollection.find(new Document("_id", new Document("$in", search.keySet()))).into(new LinkedList<>(), SyncUtils.vertxWrap((users, error) -> {
|
||||
if (error != null) {
|
||||
|
@ -179,6 +179,37 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
||||
|
||||
APIv3.respondJson(ctx, 200, grantCache.get(serverGroup.toLowerCase()));
|
||||
return;
|
||||
case "rankusers":
|
||||
Rank rank = Rank.findById(ctx.request().getParam("rank"));
|
||||
|
||||
if (rank == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "Rank", ctx.request().getParam("rank"));
|
||||
return;
|
||||
}
|
||||
|
||||
Grant.findByRank(ImmutableSet.of(rank), (grants, grantError) -> {
|
||||
if (grantError != null) {
|
||||
ErrorUtils.respondInternalError(ctx, grantError);
|
||||
return;
|
||||
}
|
||||
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
|
||||
for (Grant grant : grants) {
|
||||
if (grant.isActive()) {
|
||||
uuids.add(grant.getUser());
|
||||
}
|
||||
}
|
||||
|
||||
User.findByIdGrouped(uuids, (users, userError) -> {
|
||||
if (userError != null) {
|
||||
ErrorUtils.respondInternalError(ctx, userError);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, 200, users.values());
|
||||
}
|
||||
});
|
||||
});
|
||||
return;
|
||||
case "ipintel":
|
||||
APIv3.respondJson(ctx, 200, ipIntelCache.values());
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user