Add the ability to rollback created punishments via the audit log

This commit is contained in:
Colin McDonald 2016-07-13 19:35:35 -04:00
parent 2502f4a1b2
commit 24a73f72cf

View File

@ -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<Void> 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),