Modify DELETE /users/:id/activePunishment to remove all active punishments (instead of just the first one found) - this removes any possible confusion due to having to unban someone multiple times (due to the data importer creating duplicate punishments)
This commit is contained in:
parent
f9a423b457
commit
81a7806629
@ -8,11 +8,13 @@ import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLog;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
||||
import net.frozenorb.apiv3.model.AuditLogEntry;
|
||||
import net.frozenorb.apiv3.model.Punishment;
|
||||
import net.frozenorb.apiv3.model.User;
|
||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
import net.frozenorb.apiv3.util.SyncUtils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public final class DELETEUsersIdActivePunishment implements Handler<RoutingContext> {
|
||||
@ -37,33 +39,20 @@ public final class DELETEUsersIdActivePunishment implements Handler<RoutingConte
|
||||
}
|
||||
|
||||
List<Punishment> punishments = SyncUtils.runBlocking(v -> Punishment.findByUserAndType(target, ImmutableSet.of(type), v));
|
||||
Punishment activePunishment = null;
|
||||
List<Punishment> removedPunishments = new LinkedList<>();
|
||||
|
||||
for (Punishment punishment : punishments) {
|
||||
if (punishment.isActive()) {
|
||||
activePunishment = punishment;
|
||||
break;
|
||||
}
|
||||
if (!punishment.isActive()) continue;
|
||||
|
||||
SyncUtils.<Void>runBlocking(v -> punishment.delete(removedBy, reason, v));
|
||||
SyncUtils.<AuditLogEntry>runBlocking(v -> AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", punishment.getId()), v));
|
||||
removedPunishments.add(punishment);
|
||||
}
|
||||
|
||||
if (activePunishment == null) {
|
||||
if (!removedPunishments.isEmpty()) {
|
||||
APIv3.respondJson(ctx, 200, removedPunishments);
|
||||
} else {
|
||||
ErrorUtils.respondOther(ctx, 409, "User provided has no active punishments.", "noActivePunishments", ImmutableMap.of());
|
||||
return;
|
||||
}
|
||||
|
||||
Punishment finalActivePunishment = activePunishment;
|
||||
SyncUtils.<Void>runBlocking(v -> finalActivePunishment.delete(removedBy, reason, v));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user