diff --git a/src/main/java/net/frozenorb/apiv3/models/AuditLogEntry.java b/src/main/java/net/frozenorb/apiv3/models/AuditLogEntry.java index a80cbae..93989cc 100644 --- a/src/main/java/net/frozenorb/apiv3/models/AuditLogEntry.java +++ b/src/main/java/net/frozenorb/apiv3/models/AuditLogEntry.java @@ -23,20 +23,20 @@ public final class AuditLogEntry { @Getter @Indexed private Date performedAt; @Getter private String actorName; @Getter private ActorType actorType; - @Getter private AuditLogActionType actionType; - @Getter private Map actionData; + @Getter private AuditLogActionType type; + @Getter private Map metadata; public AuditLogEntry() {} // For Morphia - public AuditLogEntry(User user, String userIp, Actor actor, AuditLogActionType actionType, Map actionData) { + public AuditLogEntry(User user, String userIp, Actor actor, AuditLogActionType type, Map metadata) { this.id = new ObjectId().toString(); this.user = user.getId(); this.userIp = userIp; this.performedAt = new Date(); this.actorName = actor.getName(); this.actorType = actor.getType(); - this.actionType = actionType; - this.actionData = ImmutableMap.copyOf(actionData); + this.type = type; + this.metadata = ImmutableMap.copyOf(metadata); } } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/models/Grant.java b/src/main/java/net/frozenorb/apiv3/models/Grant.java index 89a6f20..c93e767 100644 --- a/src/main/java/net/frozenorb/apiv3/models/Grant.java +++ b/src/main/java/net/frozenorb/apiv3/models/Grant.java @@ -17,7 +17,7 @@ import java.util.UUID; public final class Grant { @Getter @Id private String id; - @Getter @Indexed private UUID user + @Getter @Indexed private UUID user; @Getter private String reason; @Getter private Set scopes = new HashSet<>(); // So on things w/o scopes we still load properly (Morphia drops empty sets) @Getter @Indexed private String rank; diff --git a/src/main/java/net/frozenorb/apiv3/models/IPLogEntry.java b/src/main/java/net/frozenorb/apiv3/models/IPLogEntry.java index 60a1515..1bdeeb2 100644 --- a/src/main/java/net/frozenorb/apiv3/models/IPLogEntry.java +++ b/src/main/java/net/frozenorb/apiv3/models/IPLogEntry.java @@ -17,8 +17,8 @@ public final class IPLogEntry { @Getter @Id private String id; @Getter @ExcludeFromReplies @Indexed private UUID user; @Getter @Indexed private String userIp; - @Getter private Date firstSeen; - @Getter private Date lastSeen; + @Getter private Date firstSeenAt; + @Getter private Date lastSeenAt; @Getter private int uses; public IPLogEntry() {} // For Morphia @@ -27,13 +27,13 @@ public final class IPLogEntry { this.id = new ObjectId().toString(); this.user = user.getId(); this.userIp = userIp; - this.firstSeen = new Date(); - this.lastSeen = new Date(); + this.firstSeenAt = new Date(); + this.lastSeenAt = new Date(); this.uses = 0; } public void used() { - this.lastSeen = new Date(); + this.lastSeenAt = new Date(); this.uses++; APIv3.getDatastore().save(this); diff --git a/src/main/java/net/frozenorb/apiv3/models/Punishment.java b/src/main/java/net/frozenorb/apiv3/models/Punishment.java index 99da36d..30c375c 100644 --- a/src/main/java/net/frozenorb/apiv3/models/Punishment.java +++ b/src/main/java/net/frozenorb/apiv3/models/Punishment.java @@ -22,7 +22,7 @@ public final class Punishment { @Getter private String reason; @Getter @Indexed private PunishmentType type; // Type is indexed for the rank dump @Getter private Date expiresAt; - @Getter private Map meta; + @Getter private Map metadata; @Getter private UUID addedBy; @Getter @Indexed private Date addedAt; @@ -39,7 +39,7 @@ public final class Punishment { public Punishment() {} // For Morphia - public Punishment(User user, String reason, PunishmentType type, Date expiresAt, User addedBy, Actor actor, Map meta) { + public Punishment(User user, String reason, PunishmentType type, Date expiresAt, User addedBy, Actor actor, Map metadata) { this.id = new ObjectId().toString(); this.user = user.getId(); this.reason = reason; @@ -49,7 +49,7 @@ public final class Punishment { this.addedAt = new Date(); this.actorName = actor.getName(); this.actorType = actor.getType(); - this.meta = meta; + this.metadata = metadata; } public void delete(User removedBy, String reason) { diff --git a/src/main/java/net/frozenorb/apiv3/models/Server.java b/src/main/java/net/frozenorb/apiv3/models/Server.java index 3d5f843..131836c 100644 --- a/src/main/java/net/frozenorb/apiv3/models/Server.java +++ b/src/main/java/net/frozenorb/apiv3/models/Server.java @@ -17,9 +17,9 @@ public final class Server { @Getter private String bungeeId; @Getter private String displayName; @Getter @ExcludeFromReplies String apiKey; - @Getter @Indexed private String group; + @Getter @Indexed private String serverGroup; @Getter private String serverIp; - @Getter @Setter private Date lastUpdate; + @Getter @Setter private Date lastUpdatedAt; @Getter @Setter private double lastTps; @Getter @Setter @ExcludeFromReplies private Set players; @@ -33,14 +33,14 @@ public final class Server { public Server() {} // For Morphia - public Server(String id, String bungeeId, String displayName, String apiKey, ServerGroup group, String serverIp) { + public Server(String id, String bungeeId, String displayName, String apiKey, ServerGroup serverGroup, String serverIp) { this.id = id; this.bungeeId = bungeeId; this.displayName = displayName; this.apiKey = apiKey; - this.group = group.getId(); + this.serverGroup = serverGroup.getId(); this.serverIp = serverIp; - this.lastUpdate = new Date(); + this.lastUpdatedAt = new Date(); this.lastTps = 0; this.players = new HashSet<>(); } diff --git a/src/main/java/net/frozenorb/apiv3/models/ServerGroup.java b/src/main/java/net/frozenorb/apiv3/models/ServerGroup.java index 1badc0f..4afeb78 100644 --- a/src/main/java/net/frozenorb/apiv3/models/ServerGroup.java +++ b/src/main/java/net/frozenorb/apiv3/models/ServerGroup.java @@ -1,5 +1,6 @@ package net.frozenorb.apiv3.models; +import com.google.gson.annotations.SerializedName; import lombok.Getter; import lombok.Setter; import net.frozenorb.apiv3.APIv3; @@ -16,11 +17,11 @@ public final class ServerGroup { @Getter @Id private String id; // We rename this to public, we just can't name it that because it's a Java identifier. - @Getter @Property("public") private boolean isPublic; + @Getter @Property("public") @SerializedName("public") private boolean isPublic; // We define these HashSets up here because, in the event they're // empty, Morphia will load them as null, not empty sets. @Getter @Setter @ExcludeFromReplies private Set announcements = new HashSet<>(); - @Getter @ExcludeFromReplies private Map> permissions = new HashMap<>(); + @Getter @ExcludeFromReplies private Map> permissions = new HashMap<>(); public static ServerGroup byId(String id) { return APIv3.getDatastore().createQuery(ServerGroup.class).field("id").equal(id).get(); diff --git a/src/main/java/net/frozenorb/apiv3/models/User.java b/src/main/java/net/frozenorb/apiv3/models/User.java index f874a32..53fa0fa 100644 --- a/src/main/java/net/frozenorb/apiv3/models/User.java +++ b/src/main/java/net/frozenorb/apiv3/models/User.java @@ -24,7 +24,7 @@ public final class User { @Getter @ExcludeFromReplies private Map aliases; @Getter @Setter @ExcludeFromReplies private String totpSecret; @Getter @Indexed @ExcludeFromReplies @Setter private String emailToken; - @Getter @ExcludeFromReplies @Setter private Date emailTokenSet; + @Getter @ExcludeFromReplies @Setter private Date emailTokenSetAt; @Getter @ExcludeFromReplies private String password; @Getter @Setter private String email; @Getter private String phoneNumber; @@ -249,7 +249,7 @@ public final class User { } } - ServerGroup actorGroup = ServerGroup.byId(server.getGroup()); + ServerGroup actorGroup = ServerGroup.byId(server.getServerGroup()); Rank highestRank = getHighestRank(actorGroup); // Generics are weird, yes we have to do this. diff --git a/src/main/java/net/frozenorb/apiv3/routes/announcements/GETAnnouncements.java b/src/main/java/net/frozenorb/apiv3/routes/announcements/GETAnnouncements.java index 9e9d13b..2be906a 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/announcements/GETAnnouncements.java +++ b/src/main/java/net/frozenorb/apiv3/routes/announcements/GETAnnouncements.java @@ -20,7 +20,7 @@ public final class GETAnnouncements implements Route { } Server sender = ((ServerActor) req.attribute("actor")).getServer(); - ServerGroup senderGroup = ServerGroup.byId(sender.getGroup()); + ServerGroup senderGroup = ServerGroup.byId(sender.getServerGroup()); return senderGroup.getAnnouncements(); } diff --git a/src/main/java/net/frozenorb/apiv3/routes/servers/POSTServerHeartbeat.java b/src/main/java/net/frozenorb/apiv3/routes/servers/POSTServerHeartbeat.java index 128780b..32691c5 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/servers/POSTServerHeartbeat.java +++ b/src/main/java/net/frozenorb/apiv3/routes/servers/POSTServerHeartbeat.java @@ -30,7 +30,7 @@ public final class POSTServerHeartbeat implements Route { } Server actorServer = Server.byId(actor.getName()); - ServerGroup actorServerGroup = ServerGroup.byId(actorServer.getGroup()); + ServerGroup actorServerGroup = ServerGroup.byId(actorServer.getServerGroup()); Document reqJson = Document.parse(req.body()); Set onlinePlayers = new HashSet<>(); Map playersResponse = new HashMap<>(); @@ -81,7 +81,7 @@ public final class POSTServerHeartbeat implements Route { actorServer.setPlayers(onlinePlayers); actorServer.setLastTps(reqJson.getDouble("lastTps")); - actorServer.setLastUpdate(new Date()); + actorServer.setLastUpdatedAt(new Date()); APIv3.getDatastore().save(actorServer); return ImmutableMap.of( diff --git a/src/main/java/net/frozenorb/apiv3/routes/users/POSTUserConfirmRegister.java b/src/main/java/net/frozenorb/apiv3/routes/users/POSTUserConfirmRegister.java index 099187b..fcaddef 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/users/POSTUserConfirmRegister.java +++ b/src/main/java/net/frozenorb/apiv3/routes/users/POSTUserConfirmRegister.java @@ -35,7 +35,7 @@ public final class POSTUserConfirmRegister implements Route { return ErrorUtils.error("User provided already has email set."); } - if ((System.currentTimeMillis() - user.getEmailTokenSet().getTime()) > TimeUnit.DAYS.toMillis(2)) { + if ((System.currentTimeMillis() - user.getEmailTokenSetAt().getTime()) > TimeUnit.DAYS.toMillis(2)) { return ErrorUtils.error("Email token is expired"); } diff --git a/src/main/java/net/frozenorb/apiv3/routes/users/POSTUserRegister.java b/src/main/java/net/frozenorb/apiv3/routes/users/POSTUserRegister.java index 24927d9..185fa74 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/users/POSTUserRegister.java +++ b/src/main/java/net/frozenorb/apiv3/routes/users/POSTUserRegister.java @@ -41,13 +41,13 @@ public final class POSTUserRegister implements Route { return ErrorUtils.error(email + " is not a valid email."); } - if (user.getEmailToken() != null && (System.currentTimeMillis() - user.getEmailTokenSet().getTime()) < TimeUnit.DAYS.toMillis(2)) { + if (user.getEmailToken() != null && (System.currentTimeMillis() - user.getEmailTokenSetAt().getTime()) < TimeUnit.DAYS.toMillis(2)) { return ErrorUtils.error("We just recently sent you a confirmation email. Please wait before trying to register again."); } user.setEmail(email); user.setEmailToken(new BigInteger(130, new Random()).toString(32)); - user.setEmailTokenSet(new Date()); + user.setEmailTokenSetAt(new Date()); APIv3.getDatastore().save(user); Map replacements = ImmutableMap.of( diff --git a/src/main/java/net/frozenorb/apiv3/utils/PermissionUtils.java b/src/main/java/net/frozenorb/apiv3/utils/PermissionUtils.java index 95e2bea..bd70f6d 100644 --- a/src/main/java/net/frozenorb/apiv3/utils/PermissionUtils.java +++ b/src/main/java/net/frozenorb/apiv3/utils/PermissionUtils.java @@ -5,7 +5,6 @@ import lombok.experimental.UtilityClass; import net.frozenorb.apiv3.models.Rank; import java.util.HashMap; -import java.util.List; import java.util.Map; @UtilityClass @@ -19,15 +18,14 @@ public class PermissionUtils { return result; } - public static Map mergeUpTo(Map> unconverted, Rank upTo) { + public static Map mergeUpTo(Map> unmerged, Rank upTo) { Map result = new HashMap<>(); for (Rank rank : Rank.values()) { - List unconvertedPermissions = unconverted.get(rank.getId()); + Map rankPermissions = unmerged.get(rank.getId()); // If there's no permissions defined for this rank just skip it. - if (unconvertedPermissions != null) { - Map rankPermissions = convertToMap(unconvertedPermissions); + if (rankPermissions != null) { result = mergePermissions(result, rankPermissions); } @@ -44,20 +42,4 @@ public class PermissionUtils { return ImmutableMap.of(); } - private static Map convertToMap(List unconvered) { - Map result = new HashMap<>(); - - for (String permission : unconvered) { - boolean negate = permission.startsWith("-"); - - if (negate) { - result.put(permission.substring(1), false); - } else { - result.put(permission, true); - } - } - - return result; - } - } \ No newline at end of file