Allow specifying the user to search for in GET /auditLog, /punishments, /grants, and /ipBans
This commit is contained in:
parent
2eeabf7ef8
commit
c00b424fe8
@ -38,8 +38,8 @@ public final class Grant {
|
|||||||
@Getter private Instant removedAt;
|
@Getter private Instant removedAt;
|
||||||
@Getter private String removalReason;
|
@Getter private String removalReason;
|
||||||
|
|
||||||
public static List<Grant> findAllSync() {
|
public static void findAll(SingleResultCallback<List<Grant>> callback) {
|
||||||
return SyncUtils.blockMulti(grantsCollection.find().sort(new Document("addedAt", -1)));
|
grantsCollection.find().sort(new Document("addedAt", -1)).into(new LinkedList<>(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Grant> findByRankSync(Collection<Rank> ranks) {
|
public static List<Grant> findByRankSync(Collection<Rank> ranks) {
|
||||||
@ -59,8 +59,8 @@ public final class Grant {
|
|||||||
return SyncUtils.blockMulti(grantsCollection.find(new Document("user", user)));
|
return SyncUtils.blockMulti(grantsCollection.find(new Document("user", user)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findAllPaginated(int skip, int pageSize, SingleResultCallback<List<Grant>> callback) {
|
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<Grant>> callback) {
|
||||||
grantsCollection.find().sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new ArrayList<>(), callback);
|
grantsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<Grant> callback) {
|
public static void findById(String id, SingleResultCallback<Grant> callback) {
|
||||||
@ -72,18 +72,18 @@ public final class Grant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUser(UUID user, SingleResultCallback<List<Grant>> callback) {
|
public static void findByUser(UUID user, SingleResultCallback<List<Grant>> callback) {
|
||||||
grantsCollection.find(new Document("user", user)).into(new ArrayList<>(), callback);
|
grantsCollection.find(new Document("user", user)).into(new LinkedList<>(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Grant>>> callback) {
|
public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Grant>>> callback) {
|
||||||
grantsCollection.find(new Document("user", new Document("$in", users))).into(new ArrayList<>(), (grants, error) -> {
|
grantsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), (grants, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
} else {
|
} else {
|
||||||
Map<UUID, List<Grant>> result = new HashMap<>();
|
Map<UUID, List<Grant>> result = new HashMap<>();
|
||||||
|
|
||||||
for (UUID user : users) {
|
for (UUID user : users) {
|
||||||
result.put(user, new ArrayList<>());
|
result.put(user, new LinkedList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Grant grant : grants) {
|
for (Grant grant : grants) {
|
||||||
|
@ -43,8 +43,8 @@ public final class IpBan {
|
|||||||
return SyncUtils.blockOne(ipBansCollection.find(new Document("_id", id)));
|
return SyncUtils.blockOne(ipBansCollection.find(new Document("_id", id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findAllPaginated(int skip, int pageSize, SingleResultCallback<List<IpBan>> callback) {
|
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<IpBan>> callback) {
|
||||||
ipBansCollection.find().sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new ArrayList<>(), callback);
|
ipBansCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<IpBan> callback) {
|
public static void findById(String id, SingleResultCallback<IpBan> callback) {
|
||||||
@ -52,18 +52,18 @@ public final class IpBan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void findByIp(String userIp, SingleResultCallback<List<IpBan>> callback) {
|
public static void findByIp(String userIp, SingleResultCallback<List<IpBan>> callback) {
|
||||||
ipBansCollection.find(new Document("userIp", userIp)).into(new ArrayList<>(), callback);
|
ipBansCollection.find(new Document("userIp", userIp)).into(new LinkedList<>(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByIpGrouped(Iterable<String> userIps, SingleResultCallback<Map<String, List<IpBan>>> callback) {
|
public static void findByIpGrouped(Iterable<String> userIps, SingleResultCallback<Map<String, List<IpBan>>> callback) {
|
||||||
ipBansCollection.find(new Document("userIp", new Document("$in", userIps))).into(new ArrayList<>(), (ipBans, error) -> {
|
ipBansCollection.find(new Document("userIp", new Document("$in", userIps))).into(new LinkedList<>(), (ipBans, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
} else {
|
} else {
|
||||||
Map<String, List<IpBan>> result = new HashMap<>();
|
Map<String, List<IpBan>> result = new HashMap<>();
|
||||||
|
|
||||||
for (String userIp : userIps) {
|
for (String userIp : userIps) {
|
||||||
result.put(userIp, new ArrayList<>());
|
result.put(userIp, new LinkedList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IpBan ipBan : ipBans) {
|
for (IpBan ipBan : ipBans) {
|
||||||
|
@ -43,9 +43,9 @@ public final class Punishment {
|
|||||||
@Getter private Instant removedAt;
|
@Getter private Instant removedAt;
|
||||||
@Getter private String removalReason;
|
@Getter private String removalReason;
|
||||||
|
|
||||||
public static List<Punishment> findByTypeSync(Collection<PunishmentType> types) {
|
public static void findByType(Collection<PunishmentType> types, SingleResultCallback<List<Punishment>> callback) {
|
||||||
Collection<String> convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList());
|
Collection<String> convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList());
|
||||||
return SyncUtils.blockMulti(punishmentsCollection.find(new Document("type", new Document("$in", convertedTypes))));
|
punishmentsCollection.find(new Document("type", new Document("$in", convertedTypes))).into(new LinkedList<>(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Punishment findByIdSync(String id) {
|
public static Punishment findByIdSync(String id) {
|
||||||
@ -69,8 +69,8 @@ public final class Punishment {
|
|||||||
return SyncUtils.blockMulti(punishmentsCollection.find(new Document("user", user).append("type", new Document("$in", convertedTypes))));
|
return SyncUtils.blockMulti(punishmentsCollection.find(new Document("user", user).append("type", new Document("$in", convertedTypes))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findAllPaginated(int skip, int pageSize, SingleResultCallback<List<Punishment>> callback) {
|
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<Punishment>> callback) {
|
||||||
punishmentsCollection.find().sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new ArrayList<>(), callback);
|
punishmentsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<Punishment> callback) {
|
public static void findById(String id, SingleResultCallback<Punishment> callback) {
|
||||||
@ -86,18 +86,18 @@ public final class Punishment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUser(UUID user, SingleResultCallback<List<Punishment>> callback) {
|
public static void findByUser(UUID user, SingleResultCallback<List<Punishment>> callback) {
|
||||||
punishmentsCollection.find(new Document("user", user)).into(new ArrayList<>(), callback);
|
punishmentsCollection.find(new Document("user", user)).into(new LinkedList<>(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Punishment>>> callback) {
|
public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Punishment>>> callback) {
|
||||||
punishmentsCollection.find(new Document("user", new Document("$in", users))).into(new ArrayList<>(), (punishments, error) -> {
|
punishmentsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), (punishments, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
} else {
|
} else {
|
||||||
Map<UUID, List<Punishment>> result = new HashMap<>();
|
Map<UUID, List<Punishment>> result = new HashMap<>();
|
||||||
|
|
||||||
for (UUID user : users) {
|
for (UUID user : users) {
|
||||||
result.put(user, new ArrayList<>());
|
result.put(user, new LinkedList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Punishment punishment : punishments) {
|
for (Punishment punishment : punishments) {
|
||||||
@ -115,7 +115,7 @@ public final class Punishment {
|
|||||||
|
|
||||||
public static void findByUserAndType(UUID user, Collection<PunishmentType> types, SingleResultCallback<List<Punishment>> callback) {
|
public static void findByUserAndType(UUID user, Collection<PunishmentType> types, SingleResultCallback<List<Punishment>> callback) {
|
||||||
Collection<String> convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList());
|
Collection<String> convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList());
|
||||||
punishmentsCollection.find(new Document("user", user).append("type", new Document("$in", convertedTypes))).into(new ArrayList<>(), callback);
|
punishmentsCollection.find(new Document("user", user).append("type", new Document("$in", convertedTypes))).into(new LinkedList<>(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Punishment() {} // For Jackson
|
public Punishment() {} // For Jackson
|
||||||
|
@ -14,7 +14,8 @@ public final class GETAuditLog implements Handler<RoutingContext> {
|
|||||||
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
||||||
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
||||||
|
|
||||||
AuditLogEntry.findPaginated(new Document(), skip, pageSize, (auditLog, error) -> {
|
// TODO: DO THIS BETTER (SAME FOR PUNISHMENTS, IP BANS, AND GRANTS
|
||||||
|
AuditLogEntry.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (auditLog, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -5,6 +5,7 @@ import io.vertx.ext.web.RoutingContext;
|
|||||||
import net.frozenorb.apiv3.APIv3;
|
import net.frozenorb.apiv3.APIv3;
|
||||||
import net.frozenorb.apiv3.model.Grant;
|
import net.frozenorb.apiv3.model.Grant;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
public final class GETGrants implements Handler<RoutingContext> {
|
public final class GETGrants implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ public final class GETGrants implements Handler<RoutingContext> {
|
|||||||
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
||||||
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
||||||
|
|
||||||
Grant.findAllPaginated(skip, pageSize, (grants, error) -> {
|
Grant.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (grants, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -5,6 +5,7 @@ import io.vertx.ext.web.RoutingContext;
|
|||||||
import net.frozenorb.apiv3.APIv3;
|
import net.frozenorb.apiv3.APIv3;
|
||||||
import net.frozenorb.apiv3.model.IpBan;
|
import net.frozenorb.apiv3.model.IpBan;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
public final class GETIpBans implements Handler<RoutingContext> {
|
public final class GETIpBans implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ public final class GETIpBans implements Handler<RoutingContext> {
|
|||||||
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
||||||
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
||||||
|
|
||||||
IpBan.findAllPaginated(skip, pageSize, (grants, error) -> {
|
IpBan.findPaginated(ctx.request().getParam("userIp") == null ? new Document() : new Document("userIp", ctx.request().getParam("userIp")), skip, pageSize, (grants, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -5,16 +5,16 @@ import io.vertx.ext.web.RoutingContext;
|
|||||||
import net.frozenorb.apiv3.APIv3;
|
import net.frozenorb.apiv3.APIv3;
|
||||||
import net.frozenorb.apiv3.model.Punishment;
|
import net.frozenorb.apiv3.model.Punishment;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
public final class GETPunishments implements Handler<RoutingContext> {
|
public final class GETPunishments implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
// USER PARAM
|
|
||||||
try {
|
try {
|
||||||
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
||||||
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
||||||
|
|
||||||
Punishment.findAllPaginated(skip, pageSize, (grants, error) -> {
|
Punishment.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (grants, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user