From 7f108881513f707fbc6d2367199c22c0375b1f43 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Tue, 2 Aug 2016 19:03:21 -0400 Subject: [PATCH] Rank schema changes --- .../java/net/frozenorb/apiv3/model/Rank.java | 17 ++++++++++++----- .../java/net/frozenorb/apiv3/model/User.java | 2 +- .../apiv3/route/grants/POSTGrants.java | 2 +- .../frozenorb/apiv3/route/ranks/POSTRanks.java | 9 ++++++--- .../frozenorb/apiv3/route/users/GETStaff.java | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/model/Rank.java b/src/main/java/net/frozenorb/apiv3/model/Rank.java index a679b97..69d9063 100644 --- a/src/main/java/net/frozenorb/apiv3/model/Rank.java +++ b/src/main/java/net/frozenorb/apiv3/model/Rank.java @@ -27,13 +27,16 @@ public final class Rank { @Getter @Id private String id; @Getter private String inheritsFromId; - @Getter private int weight; + @Getter private int generalWeight; + @Getter private int displayWeight; @Getter private String displayName; @Getter private String gamePrefix; @Getter private String gameColor; @Getter private String websiteColor; @Getter private boolean staffRank; - @Getter private boolean higherStaffRank; + @Getter private boolean grantRequiresTotp; + @Getter private String queueMessage; + @Getter private boolean queueInstantJoin; public static List findAll() { return ImmutableList.copyOf(rankCache); @@ -67,16 +70,20 @@ public final class Rank { private Rank() {} // For Jackson - public Rank(String id, String inheritsFromId, int weight, String displayName, String gamePrefix, String gameColor, String websiteColor, boolean staffRank, boolean higherStaffRank) { + public Rank(String id, String inheritsFromId, int generalWeight, int displayWeight, String displayName, String gamePrefix, String gameColor, + String websiteColor, boolean staffRank, boolean grantRequiresTotp, String queueMessage, boolean queueInstantJoin) { this.id = id; this.inheritsFromId = inheritsFromId; - this.weight = weight; + this.generalWeight = generalWeight; + this.displayWeight = displayWeight; this.displayName = displayName; this.gamePrefix = gamePrefix; this.gameColor = gameColor; this.websiteColor = websiteColor; this.staffRank = staffRank; - this.higherStaffRank = higherStaffRank; + this.grantRequiresTotp = grantRequiresTotp; + this.queueMessage = queueMessage; + this.queueInstantJoin = queueInstantJoin; } public void insert(SingleResultCallback callback) { diff --git a/src/main/java/net/frozenorb/apiv3/model/User.java b/src/main/java/net/frozenorb/apiv3/model/User.java index 57c6da7..08f84c1 100644 --- a/src/main/java/net/frozenorb/apiv3/model/User.java +++ b/src/main/java/net/frozenorb/apiv3/model/User.java @@ -651,7 +651,7 @@ public final class User { } List grantedRanksList = new ArrayList<>(grantedRanks); - grantedRanksList.sort((a, b) -> Ints.compare(b.getWeight(), a.getWeight())); + grantedRanksList.sort((a, b) -> Ints.compare(b.getGeneralWeight(), a.getGeneralWeight())); return ImmutableList.copyOf(grantedRanksList); } diff --git a/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java b/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java index 49baccf..7cd4558 100644 --- a/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java +++ b/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java @@ -85,7 +85,7 @@ public final class POSTGrants implements Handler { return; } - if (rank.isHigherStaffRank()) { + if (rank.isGrantRequiresTotp()) { int code = requestBody.getInteger("totpCode"); TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> addedBy.checkTotpAuthorization(code, null, v)); diff --git a/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java b/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java index fa40d59..3ef63e4 100644 --- a/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java +++ b/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java @@ -18,15 +18,18 @@ public final class POSTRanks implements Handler { JsonObject requestBody = ctx.getBodyAsJson(); String id = requestBody.getString("id"); String inheritsFromId = requestBody.getString("inheritsFromId"); - int weight = requestBody.getInteger("weight"); + int generalWeight = requestBody.getInteger("generalWeight"); + int displayWeight = requestBody.getInteger("displayWeight"); String displayName = requestBody.getString("displayName"); String gamePrefix = requestBody.getString("gamePrefix"); String gameColor = requestBody.getString("gameColor"); String websiteColor = requestBody.getString("websiteColor"); boolean staffRank = requestBody.getBoolean("staffRank"); - boolean higherStaffRank = requestBody.getBoolean("higherStaffRank"); + boolean grantRequiresTotp = requestBody.getBoolean("grantRequiresTotp"); + String queueMessage = requestBody.getString("queueMessage"); + boolean queueInstantJoin = requestBody.getBoolean("queueInstantJoin"); - Rank rank = new Rank(id, inheritsFromId, weight, displayName, gamePrefix, gameColor, websiteColor, staffRank, higherStaffRank); + Rank rank = new Rank(id, inheritsFromId, generalWeight, displayWeight, displayName, gamePrefix, gameColor, websiteColor, staffRank, grantRequiresTotp, queueMessage, queueInstantJoin); SyncUtils.runBlocking(v -> rank.insert(v)); if (requestBody.containsKey("addedBy")) { diff --git a/src/main/java/net/frozenorb/apiv3/route/users/GETStaff.java b/src/main/java/net/frozenorb/apiv3/route/users/GETStaff.java index 034d982..68e907e 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/GETStaff.java +++ b/src/main/java/net/frozenorb/apiv3/route/users/GETStaff.java @@ -25,7 +25,7 @@ public final class GETStaff implements Handler { Rank firstRank = staffRanks.get(first); Rank secondRank = staffRanks.get(second); - return Integer.compare(firstRank.getWeight(), secondRank.getWeight()); + return Integer.compare(firstRank.getGeneralWeight(), secondRank.getGeneralWeight()); }); List staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v));