Don't require removedBy field when deleting grants, ip bans, and punishments
This commit is contained in:
parent
e48a0c1736
commit
254d5336bf
@ -113,7 +113,7 @@ public final class Grant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoved() {
|
public boolean isRemoved() {
|
||||||
return removedBy != null;
|
return removedAt != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean appliesOn(ServerGroup serverGroup) {
|
public boolean appliesOn(ServerGroup serverGroup) {
|
||||||
@ -129,7 +129,7 @@ public final class Grant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
||||||
this.removedBy = removedBy.getId();
|
this.removedBy = removedBy == null ? null : removedBy.getId();
|
||||||
this.removedAt = Instant.now();
|
this.removedAt = Instant.now();
|
||||||
this.removalReason = reason;
|
this.removalReason = reason;
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public final class IpBan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoved() {
|
public boolean isRemoved() {
|
||||||
return removedBy != null;
|
return removedAt != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getAccessDenialReason(SingleResultCallback<String> callback) {
|
public void getAccessDenialReason(SingleResultCallback<String> callback) {
|
||||||
@ -150,7 +150,7 @@ public final class IpBan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
||||||
this.removedBy = removedBy.getId();
|
this.removedBy = removedBy == null ? null : removedBy.getId();
|
||||||
this.removedAt = Instant.now();
|
this.removedAt = Instant.now();
|
||||||
this.removalReason = reason;
|
this.removalReason = reason;
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ public final class Punishment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoved() {
|
public boolean isRemoved() {
|
||||||
return removedBy != null;
|
return removedAt != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAccessDenialReason() {
|
public String getAccessDenialReason() {
|
||||||
@ -153,7 +153,7 @@ public final class Punishment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
||||||
this.removedBy = removedBy.getId();
|
this.removedBy = removedBy == null ? null : removedBy.getId();
|
||||||
this.removedAt = Instant.now();
|
this.removedAt = Instant.now();
|
||||||
this.removalReason = reason;
|
this.removalReason = reason;
|
||||||
|
|
||||||
|
@ -26,13 +26,8 @@ public final class DELETEGrantsId implements Handler<RoutingContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
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));
|
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");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
@ -42,13 +37,17 @@ public final class DELETEGrantsId implements Handler<RoutingContext> {
|
|||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> grant.delete(removedBy, reason, v));
|
SyncUtils.<Void>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 (removedBy != null) {
|
||||||
if (error != null) {
|
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.GRANT_DELETE, ImmutableMap.of("grantId", grant.getId()), (ignored, error) -> {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
if (error != null) {
|
||||||
} else {
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
APIv3.respondJson(ctx, 200, grant);
|
} else {
|
||||||
}
|
APIv3.respondJson(ctx, 200, grant);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
APIv3.respondJson(ctx, 200, grant);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -26,13 +26,8 @@ public final class DELETEIpBansId implements Handler<RoutingContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
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));
|
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");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
@ -42,13 +37,17 @@ public final class DELETEIpBansId implements Handler<RoutingContext> {
|
|||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> ipBan.delete(removedBy, reason, v));
|
SyncUtils.<Void>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 (removedBy != null) {
|
||||||
if (error != null) {
|
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.IP_BAN_DELETE, ImmutableMap.of("punishmentId", ipBan.getId()), (ignored, error) -> {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
if (error != null) {
|
||||||
} else {
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
APIv3.respondJson(ctx, 200, ipBan);
|
} else {
|
||||||
}
|
APIv3.respondJson(ctx, 200, ipBan);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
APIv3.respondJson(ctx, 200, ipBan);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -26,13 +26,8 @@ public final class DELETEPunishmentsId implements Handler<RoutingContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
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));
|
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");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
@ -42,13 +37,17 @@ public final class DELETEPunishmentsId implements Handler<RoutingContext> {
|
|||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> punishment.delete(removedBy, reason, v));
|
SyncUtils.<Void>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 (removedBy != null) {
|
||||||
if (error != null) {
|
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", punishment.getId()), (ignored, error) -> {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
if (error != null) {
|
||||||
} else {
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
APIv3.respondJson(ctx, 200, punishment);
|
} else {
|
||||||
}
|
APIv3.respondJson(ctx, 200, punishment);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
APIv3.respondJson(ctx, 200, punishment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -27,13 +27,8 @@ public final class DELETEUsersIdActivePunishment implements Handler<RoutingConte
|
|||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
Punishment.PunishmentType type = Punishment.PunishmentType.valueOf(requestBody.getString("type").toUpperCase());
|
Punishment.PunishmentType type = Punishment.PunishmentType.valueOf(requestBody.getString("type").toUpperCase());
|
||||||
|
// 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));
|
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");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
@ -59,13 +54,17 @@ public final class DELETEUsersIdActivePunishment implements Handler<RoutingConte
|
|||||||
Punishment finalActivePunishment = activePunishment;
|
Punishment finalActivePunishment = activePunishment;
|
||||||
SyncUtils.<Void>runBlocking(v -> finalActivePunishment.delete(removedBy, reason, v));
|
SyncUtils.<Void>runBlocking(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 (removedBy != null) {
|
||||||
if (error != null) {
|
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", activePunishment.getId()), (ignored, error) -> {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
if (error != null) {
|
||||||
} else {
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
APIv3.respondJson(ctx, 200, finalActivePunishment);
|
} else {
|
||||||
}
|
APIv3.respondJson(ctx, 200, finalActivePunishment);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
APIv3.respondJson(ctx, 200, finalActivePunishment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user