Commit some old changes
This commit is contained in:
parent
816b214993
commit
c3efe78ce4
25
src/main/java/net/frozenorb/apiv3/auditLog/AuditLog.java
Normal file
25
src/main/java/net/frozenorb/apiv3/auditLog/AuditLog.java
Normal file
@ -0,0 +1,25 @@
|
||||
package net.frozenorb.apiv3.auditLog;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.actors.Actor;
|
||||
import net.frozenorb.apiv3.auditLog.actions.CreatePunishmentAction;
|
||||
import net.frozenorb.apiv3.models.AuditLogEntry;
|
||||
import net.frozenorb.apiv3.models.User;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class AuditLog {
|
||||
|
||||
public static void log(User performedBy, String performedByIp, Actor actor, AuditLogActionType actionType) {
|
||||
log(performedBy, performedByIp, actor, actionType, new Document());
|
||||
}
|
||||
|
||||
public static void log(User performedBy, String performedByIp, Actor actor, AuditLogActionType actionType, Document actionData) {
|
||||
APIv3.getDatastore().save(new AuditLogEntry(performedBy, performedByIp, actor, actionType, actionData));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package net.frozenorb.apiv3.auditLog;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.frozenorb.apiv3.models.AuditLogEntry;
|
||||
|
||||
public enum AuditLogActionType {
|
||||
|
||||
CREATE_PUNISHMENT {
|
||||
|
||||
@Override
|
||||
public void revert(AuditLogEntry entry) {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public void revert(AuditLogEntry entry) {}
|
||||
|
||||
}
|
@ -1,33 +1,41 @@
|
||||
package net.frozenorb.apiv3.models;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import lombok.Getter;
|
||||
import net.frozenorb.apiv3.actors.Actor;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.mongodb.morphia.annotations.Entity;
|
||||
import org.mongodb.morphia.annotations.Id;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity(value = "auditLog", noClassnameStored = true)
|
||||
public final class AuditLogEntry {
|
||||
|
||||
@Getter @Id private ObjectId id;
|
||||
@Getter @Id private String id;
|
||||
@Getter private UUID performedBy;
|
||||
@Getter private String performedByIp;
|
||||
@Getter private Date performedAt;
|
||||
@Getter private String actorName;
|
||||
@Getter private String actionType;
|
||||
@Getter private Document actionData;
|
||||
@Getter private Actor.Type actorType;
|
||||
@Getter private AuditLogActionType actionType;
|
||||
@Getter private Map<String, Object> actionData;
|
||||
|
||||
public AuditLogEntry() {} // For Morphia
|
||||
|
||||
public AuditLogEntry(User performedBy, Actor actor, String actionType, Document actionData) {
|
||||
public AuditLogEntry(User performedBy, String performedByIp, Actor actor, AuditLogActionType actionType, Map<String, Object> actionData) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.performedBy = performedBy.getId();
|
||||
this.performedByIp = performedByIp;
|
||||
this.performedAt = new Date();
|
||||
this.actorName = actor.getName();
|
||||
this.actorType = actor.getType();
|
||||
this.actionType = actionType;
|
||||
this.actionData = new Document(actionData);
|
||||
this.actionData = ImmutableMap.copyOf(actionData);
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ import java.util.UUID;
|
||||
@Entity(value = "grants", noClassnameStored = true)
|
||||
public final class Grant {
|
||||
|
||||
@Getter @Id private ObjectId id;
|
||||
@Getter @Id private String id;
|
||||
@Getter private UUID target;
|
||||
@Getter private String reason;
|
||||
@Getter private Set<String> scopes;
|
||||
@ -30,12 +30,13 @@ public final class Grant {
|
||||
@Getter private String removalReason;
|
||||
|
||||
public static Grant byId(String id) {
|
||||
return APIv3.getDatastore().createQuery(Grant.class).field("id").equal(new ObjectId(id)).get();
|
||||
return APIv3.getDatastore().createQuery(Grant.class).field("id").equal(id).get();
|
||||
}
|
||||
|
||||
public Grant() {} // For Morphia
|
||||
|
||||
public Grant(User target, String reason, Set<ServerGroup> scopes, Rank rank, Date expiresAt, User addedBy) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.target = target.getId();
|
||||
this.reason = reason;
|
||||
this.scopes = new HashSet<>(Collections2.transform(scopes, ServerGroup::getId));
|
||||
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||
@Entity(value = "ipLog", noClassnameStored = true)
|
||||
public final class IPLogEntry {
|
||||
|
||||
@Getter @Id private ObjectId id;
|
||||
@Getter @Id private String id;
|
||||
@Getter private UUID user;
|
||||
@Getter private String ip;
|
||||
@Getter private Date firstSeen;
|
||||
@ -22,6 +22,7 @@ public final class IPLogEntry {
|
||||
public IPLogEntry() {} // For Morphia
|
||||
|
||||
public IPLogEntry(User user, String ip) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.user = user.getId();
|
||||
this.ip = ip;
|
||||
this.firstSeen = new Date();
|
||||
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||
@Entity(value = "punishments", noClassnameStored = true)
|
||||
public final class Punishment {
|
||||
|
||||
@Getter @Id private ObjectId id;
|
||||
@Getter @Id private String id;
|
||||
@Getter private UUID target;
|
||||
@Getter private String reason;
|
||||
@Getter private PunishmentType type;
|
||||
@ -27,12 +27,13 @@ public final class Punishment {
|
||||
@Getter private String removalReason;
|
||||
|
||||
public static Punishment byId(String id) {
|
||||
return APIv3.getDatastore().createQuery(Punishment.class).field("id").equal(new ObjectId(id)).get();
|
||||
return APIv3.getDatastore().createQuery(Punishment.class).field("id").equal(id).get();
|
||||
}
|
||||
|
||||
public Punishment() {} // For Morphia
|
||||
|
||||
public Punishment(User target, String reason, PunishmentType type, Date expiresAt, User addedBy, Server addedOn) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.target = target.getId();
|
||||
this.reason = reason;
|
||||
this.type = type;
|
||||
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
||||
@Entity(value = "userMeta", noClassnameStored = true)
|
||||
public final class UserMetaEntry {
|
||||
|
||||
@Getter @Id private ObjectId id;
|
||||
@Getter @Id private String id;
|
||||
@Getter private UUID user;
|
||||
@Getter private String serverGroup;
|
||||
@Getter @Setter private Document data;
|
||||
@ -21,6 +21,7 @@ public final class UserMetaEntry {
|
||||
public UserMetaEntry() {} // For Morphia
|
||||
|
||||
public UserMetaEntry(User user, ServerGroup serverGroup, Document data) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.user = user.getId();
|
||||
this.serverGroup = serverGroup.getId();
|
||||
this.data = new Document(data);
|
||||
|
@ -2,7 +2,7 @@ package net.frozenorb.apiv3.routes.grants;
|
||||
|
||||
import net.frozenorb.apiv3.models.Grant;
|
||||
import net.frozenorb.apiv3.models.User;
|
||||
import net.frozenorb.apiv3.unsorted.AuditLog;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLog;
|
||||
import net.frozenorb.apiv3.unsorted.Permissions;
|
||||
import net.frozenorb.apiv3.utils.ErrorUtils;
|
||||
import org.bson.Document;
|
||||
|
@ -2,7 +2,7 @@ package net.frozenorb.apiv3.routes.punishments;
|
||||
|
||||
import net.frozenorb.apiv3.models.Punishment;
|
||||
import net.frozenorb.apiv3.models.User;
|
||||
import net.frozenorb.apiv3.unsorted.AuditLog;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLog;
|
||||
import net.frozenorb.apiv3.unsorted.Permissions;
|
||||
import net.frozenorb.apiv3.utils.ErrorUtils;
|
||||
import org.bson.Document;
|
||||
|
@ -1,23 +0,0 @@
|
||||
package net.frozenorb.apiv3.unsorted;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.actors.Actor;
|
||||
import net.frozenorb.apiv3.models.AuditLogEntry;
|
||||
import net.frozenorb.apiv3.models.User;
|
||||
import org.bson.Document;
|
||||
|
||||
@UtilityClass
|
||||
public class AuditLog {
|
||||
|
||||
// TODO: Store user IPs
|
||||
|
||||
public static void log(User performedBy, Actor actor, String actionType) {
|
||||
log(performedBy, actor, actionType, new Document());
|
||||
}
|
||||
|
||||
public static void log(User performedBy, Actor actor, String actionType, Document actionData) {
|
||||
APIv3.getDatastore().save(new AuditLogEntry(performedBy, actor, actionType, actionData));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user