Rank schema changes

This commit is contained in:
Colin McDonald 2016-08-02 19:03:21 -04:00
parent d9d87872cb
commit 7f10888151
5 changed files with 21 additions and 11 deletions

View File

@ -27,13 +27,16 @@ public final class Rank {
@Getter @Id private String id; @Getter @Id private String id;
@Getter private String inheritsFromId; @Getter private String inheritsFromId;
@Getter private int weight; @Getter private int generalWeight;
@Getter private int displayWeight;
@Getter private String displayName; @Getter private String displayName;
@Getter private String gamePrefix; @Getter private String gamePrefix;
@Getter private String gameColor; @Getter private String gameColor;
@Getter private String websiteColor; @Getter private String websiteColor;
@Getter private boolean staffRank; @Getter private boolean staffRank;
@Getter private boolean higherStaffRank; @Getter private boolean grantRequiresTotp;
@Getter private String queueMessage;
@Getter private boolean queueInstantJoin;
public static List<Rank> findAll() { public static List<Rank> findAll() {
return ImmutableList.copyOf(rankCache); return ImmutableList.copyOf(rankCache);
@ -67,16 +70,20 @@ public final class Rank {
private Rank() {} // For Jackson 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.id = id;
this.inheritsFromId = inheritsFromId; this.inheritsFromId = inheritsFromId;
this.weight = weight; this.generalWeight = generalWeight;
this.displayWeight = displayWeight;
this.displayName = displayName; this.displayName = displayName;
this.gamePrefix = gamePrefix; this.gamePrefix = gamePrefix;
this.gameColor = gameColor; this.gameColor = gameColor;
this.websiteColor = websiteColor; this.websiteColor = websiteColor;
this.staffRank = staffRank; this.staffRank = staffRank;
this.higherStaffRank = higherStaffRank; this.grantRequiresTotp = grantRequiresTotp;
this.queueMessage = queueMessage;
this.queueInstantJoin = queueInstantJoin;
} }
public void insert(SingleResultCallback<Void> callback) { public void insert(SingleResultCallback<Void> callback) {

View File

@ -651,7 +651,7 @@ public final class User {
} }
List<Rank> grantedRanksList = new ArrayList<>(grantedRanks); List<Rank> 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); return ImmutableList.copyOf(grantedRanksList);
} }

View File

@ -85,7 +85,7 @@ public final class POSTGrants implements Handler<RoutingContext> {
return; return;
} }
if (rank.isHigherStaffRank()) { if (rank.isGrantRequiresTotp()) {
int code = requestBody.getInteger("totpCode"); int code = requestBody.getInteger("totpCode");
TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> addedBy.checkTotpAuthorization(code, null, v)); TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> addedBy.checkTotpAuthorization(code, null, v));

View File

@ -18,15 +18,18 @@ public final class POSTRanks implements Handler<RoutingContext> {
JsonObject requestBody = ctx.getBodyAsJson(); JsonObject requestBody = ctx.getBodyAsJson();
String id = requestBody.getString("id"); String id = requestBody.getString("id");
String inheritsFromId = requestBody.getString("inheritsFromId"); 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 displayName = requestBody.getString("displayName");
String gamePrefix = requestBody.getString("gamePrefix"); String gamePrefix = requestBody.getString("gamePrefix");
String gameColor = requestBody.getString("gameColor"); String gameColor = requestBody.getString("gameColor");
String websiteColor = requestBody.getString("websiteColor"); String websiteColor = requestBody.getString("websiteColor");
boolean staffRank = requestBody.getBoolean("staffRank"); 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.<Void>runBlocking(v -> rank.insert(v)); SyncUtils.<Void>runBlocking(v -> rank.insert(v));
if (requestBody.containsKey("addedBy")) { if (requestBody.containsKey("addedBy")) {

View File

@ -25,7 +25,7 @@ public final class GETStaff implements Handler<RoutingContext> {
Rank firstRank = staffRanks.get(first); Rank firstRank = staffRanks.get(first);
Rank secondRank = staffRanks.get(second); Rank secondRank = staffRanks.get(second);
return Integer.compare(firstRank.getWeight(), secondRank.getWeight()); return Integer.compare(firstRank.getGeneralWeight(), secondRank.getGeneralWeight());
}); });
List<Grant> staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v)); List<Grant> staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v));