From 24a73f72cfacec125cd5644158edad0faf59f125 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Wed, 13 Jul 2016 19:35:35 -0400 Subject: [PATCH] Add the ability to rollback created punishments via the audit log --- .../apiv3/auditLog/AuditLogActionType.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/frozenorb/apiv3/auditLog/AuditLogActionType.java b/src/main/java/net/frozenorb/apiv3/auditLog/AuditLogActionType.java index 8a19032..f6023d1 100644 --- a/src/main/java/net/frozenorb/apiv3/auditLog/AuditLogActionType.java +++ b/src/main/java/net/frozenorb/apiv3/auditLog/AuditLogActionType.java @@ -3,6 +3,9 @@ package net.frozenorb.apiv3.auditLog; import com.mongodb.async.SingleResultCallback; import lombok.Getter; import net.frozenorb.apiv3.model.AuditLogEntry; +import net.frozenorb.apiv3.model.Punishment; + +import java.time.Instant; public enum AuditLogActionType { @@ -26,7 +29,28 @@ public enum AuditLogActionType { NOTIFICATION_TEMPLATE_CREATE(false), NOTIFICATION_TEMPLATE_UPDATE(false), NOTIFICATION_TEMPLATE_DELETE(false), - PUNISHMENT_CREATE(false), + PUNISHMENT_CREATE(true) { + + @Override + public void reverse(AuditLogEntry entry, SingleResultCallback callback) { + String punishmentId = (String) entry.getMetadata().get("punishmentId"); + + Punishment.findById(punishmentId, (punishment, error) -> { + if (error != null) { + callback.onResult(null, error); + return; + } + + if (punishment == null || !punishment.isActive()) { + callback.onResult(null, null); + return; + } + + punishment.delete(null, "Removed via audit log reversal at " + Instant.now().toString() + ".", callback); + }); + } + + }, PUNISHMENT_UPDATE(false), PUNISHMENT_DELETE(false), RANK_CREATE(false),