diff --git a/src/main/java/net/frozenorb/apiv3/model/Grant.java b/src/main/java/net/frozenorb/apiv3/model/Grant.java index 8985aab..0051328 100644 --- a/src/main/java/net/frozenorb/apiv3/model/Grant.java +++ b/src/main/java/net/frozenorb/apiv3/model/Grant.java @@ -113,7 +113,7 @@ public final class Grant { } public boolean isRemoved() { - return removedBy != null; + return removedAt != null; } public boolean appliesOn(ServerGroup serverGroup) { @@ -129,7 +129,7 @@ public final class Grant { } public void delete(User removedBy, String reason, SingleResultCallback callback) { - this.removedBy = removedBy.getId(); + this.removedBy = removedBy == null ? null : removedBy.getId(); this.removedAt = Instant.now(); this.removalReason = reason; diff --git a/src/main/java/net/frozenorb/apiv3/model/IpBan.java b/src/main/java/net/frozenorb/apiv3/model/IpBan.java index 7055df1..079c707 100644 --- a/src/main/java/net/frozenorb/apiv3/model/IpBan.java +++ b/src/main/java/net/frozenorb/apiv3/model/IpBan.java @@ -103,7 +103,7 @@ public final class IpBan { } public boolean isRemoved() { - return removedBy != null; + return removedAt != null; } public void getAccessDenialReason(SingleResultCallback callback) { @@ -150,7 +150,7 @@ public final class IpBan { } public void delete(User removedBy, String reason, SingleResultCallback callback) { - this.removedBy = removedBy.getId(); + this.removedBy = removedBy == null ? null : removedBy.getId(); this.removedAt = Instant.now(); this.removalReason = reason; diff --git a/src/main/java/net/frozenorb/apiv3/model/Punishment.java b/src/main/java/net/frozenorb/apiv3/model/Punishment.java index ed89bda..9ec0089 100644 --- a/src/main/java/net/frozenorb/apiv3/model/Punishment.java +++ b/src/main/java/net/frozenorb/apiv3/model/Punishment.java @@ -122,7 +122,7 @@ public final class Punishment { } public boolean isRemoved() { - return removedBy != null; + return removedAt != null; } public String getAccessDenialReason() { @@ -153,7 +153,7 @@ public final class Punishment { } public void delete(User removedBy, String reason, SingleResultCallback callback) { - this.removedBy = removedBy.getId(); + this.removedBy = removedBy == null ? null : removedBy.getId(); this.removedAt = Instant.now(); this.removalReason = reason; diff --git a/src/main/java/net/frozenorb/apiv3/route/grants/DELETEGrantsId.java b/src/main/java/net/frozenorb/apiv3/route/grants/DELETEGrantsId.java index 5c3aa3c..3e62b63 100644 --- a/src/main/java/net/frozenorb/apiv3/route/grants/DELETEGrantsId.java +++ b/src/main/java/net/frozenorb/apiv3/route/grants/DELETEGrantsId.java @@ -26,13 +26,8 @@ public final class DELETEGrantsId implements Handler { } JsonObject requestBody = ctx.getBodyAsJson(); + // We purposely don't do a null check, grant removals don't have to have a user/ip. User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v)); - - if (removedBy == null) { - ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("removedBy")); - return; - } - String reason = requestBody.getString("reason"); if (reason == null || reason.trim().isEmpty()) { @@ -42,13 +37,17 @@ public final class DELETEGrantsId implements Handler { SyncUtils.runBlocking(v -> grant.delete(removedBy, reason, v)); - AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.GRANT_DELETE, ImmutableMap.of("grantId", grant.getId()), (ignored, error) -> { - if (error != null) { - ErrorUtils.respondInternalError(ctx, error); - } else { - APIv3.respondJson(ctx, 200, grant); - } - }); + if (removedBy != null) { + AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.GRANT_DELETE, ImmutableMap.of("grantId", grant.getId()), (ignored, error) -> { + if (error != null) { + ErrorUtils.respondInternalError(ctx, error); + } else { + APIv3.respondJson(ctx, 200, grant); + } + }); + } else { + APIv3.respondJson(ctx, 200, grant); + } } } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/route/ipBans/DELETEIpBansId.java b/src/main/java/net/frozenorb/apiv3/route/ipBans/DELETEIpBansId.java index cd4af8a..04c7bb4 100644 --- a/src/main/java/net/frozenorb/apiv3/route/ipBans/DELETEIpBansId.java +++ b/src/main/java/net/frozenorb/apiv3/route/ipBans/DELETEIpBansId.java @@ -26,13 +26,8 @@ public final class DELETEIpBansId implements Handler { } JsonObject requestBody = ctx.getBodyAsJson(); + // We purposely don't do a null check, ip ban removals don't have to have a user/ip. User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v)); - - if (removedBy == null) { - ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("removedBy")); - return; - } - String reason = requestBody.getString("reason"); if (reason == null || reason.trim().isEmpty()) { @@ -42,13 +37,17 @@ public final class DELETEIpBansId implements Handler { SyncUtils.runBlocking(v -> ipBan.delete(removedBy, reason, v)); - AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.IP_BAN_DELETE, ImmutableMap.of("punishmentId", ipBan.getId()), (ignored, error) -> { - if (error != null) { - ErrorUtils.respondInternalError(ctx, error); - } else { - APIv3.respondJson(ctx, 200, ipBan); - } - }); + if (removedBy != null) { + AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.IP_BAN_DELETE, ImmutableMap.of("punishmentId", ipBan.getId()), (ignored, error) -> { + if (error != null) { + ErrorUtils.respondInternalError(ctx, error); + } else { + APIv3.respondJson(ctx, 200, ipBan); + } + }); + } else { + APIv3.respondJson(ctx, 200, ipBan); + } } } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/route/punishments/DELETEPunishmentsId.java b/src/main/java/net/frozenorb/apiv3/route/punishments/DELETEPunishmentsId.java index 2db9398..17a1661 100644 --- a/src/main/java/net/frozenorb/apiv3/route/punishments/DELETEPunishmentsId.java +++ b/src/main/java/net/frozenorb/apiv3/route/punishments/DELETEPunishmentsId.java @@ -26,13 +26,8 @@ public final class DELETEPunishmentsId implements Handler { } JsonObject requestBody = ctx.getBodyAsJson(); + // We purposely don't do a null check, punishment removals don't have to have a user/ip. User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v)); - - if (removedBy == null) { - ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("removedBy")); - return; - } - String reason = requestBody.getString("reason"); if (reason == null || reason.trim().isEmpty()) { @@ -42,13 +37,17 @@ public final class DELETEPunishmentsId implements Handler { SyncUtils.runBlocking(v -> punishment.delete(removedBy, reason, v)); - AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", punishment.getId()), (ignored, error) -> { - if (error != null) { - ErrorUtils.respondInternalError(ctx, error); - } else { - APIv3.respondJson(ctx, 200, punishment); - } - }); + if (removedBy != null) { + AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", punishment.getId()), (ignored, error) -> { + if (error != null) { + ErrorUtils.respondInternalError(ctx, error); + } else { + APIv3.respondJson(ctx, 200, punishment); + } + }); + } else { + APIv3.respondJson(ctx, 200, punishment); + } } } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/route/punishments/DELETEUsersIdActivePunishment.java b/src/main/java/net/frozenorb/apiv3/route/punishments/DELETEUsersIdActivePunishment.java index 7a204d2..b705702 100644 --- a/src/main/java/net/frozenorb/apiv3/route/punishments/DELETEUsersIdActivePunishment.java +++ b/src/main/java/net/frozenorb/apiv3/route/punishments/DELETEUsersIdActivePunishment.java @@ -27,13 +27,8 @@ public final class DELETEUsersIdActivePunishment implements Handler User.findById(requestBody.getString("removedBy"), v)); - - if (removedBy == null) { - ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("removedBy")); - return; - } - String reason = requestBody.getString("reason"); if (reason == null || reason.trim().isEmpty()) { @@ -59,13 +54,17 @@ public final class DELETEUsersIdActivePunishment implements HandlerrunBlocking(v -> finalActivePunishment.delete(removedBy, reason, v)); - AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", activePunishment.getId()), (ignored, error) -> { - if (error != null) { - ErrorUtils.respondInternalError(ctx, error); - } else { - APIv3.respondJson(ctx, 200, finalActivePunishment); - } - }); + if (removedBy != null) { + AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", activePunishment.getId()), (ignored, error) -> { + if (error != null) { + ErrorUtils.respondInternalError(ctx, error); + } else { + APIv3.respondJson(ctx, 200, finalActivePunishment); + } + }); + } else { + APIv3.respondJson(ctx, 200, finalActivePunishment); + } } } \ No newline at end of file