Add rank id conversion and properly update rank cache

This commit is contained in:
Colin McDonald 2016-05-13 23:58:25 -04:00
parent 846a7210bd
commit 199072b5fb
2 changed files with 13 additions and 2 deletions

View File

@ -323,16 +323,26 @@ public final class APIv3 {
public void apply(Document grant) {
UUID target = mongoIdToUUID.get(((DBRef) grant.get("target")).getId());
if (target == null || grant.getString("role").equalsIgnoreCase("unban") || grant.getString("role").equalsIgnoreCase("pass")) {
if (target == null) {
return;
}
String rank = grant.getString("role");
if (rank.equalsIgnoreCase("unban") || rank.equalsIgnoreCase("pass") || rank.equalsIgnoreCase("pink") || rank.equalsIgnoreCase("jrdev")) {
return;
} else if (rank.equalsIgnoreCase("high_roller")) {
rank = "high-roller";
} else if (rank.equalsIgnoreCase("dev")) {
rank = "developer";
}
Grant created = new Grant(
new ObjectId().toString(),
target,
grant.containsKey("comment") ? grant.getString("comment") : "",
grant.containsKey("scope") ? ImmutableSet.copyOf((Collection<String>) grant.get("scope")) : ImmutableSet.of(),
grant.getString("role"),
rank,
grant.getDate("expires"),
grant.containsKey("addedBy") ? mongoIdToUUID.get(((DBRef) grant.get("addedBy")).getId()) : null,
grant.containsKey("created") ? grant.getDate("created") : new Date(),

View File

@ -31,6 +31,7 @@ public final class Rank {
}
public static List<Rank> values() {
updateCacheIfNeeded();
return ImmutableList.copyOf(rankCache.values());
}