Add scopeRanks field to user login info, which contains their best ranks on each scope

This commit is contained in:
Colin McDonald 2016-11-21 20:12:42 -05:00
parent b53ea83bb9
commit 74570ccbc0
1 changed files with 12 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package net.frozenorb.apiv3.model;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.base.Charsets;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@ -346,7 +347,16 @@ public final class User {
// db query, but we don't include the result because it's not used in
// Hydrogen at all (bnut probably will be later on)
// result.put("user", this);
result.put("ranks", ranks.stream().map(Rank::getId).collect(Collectors.toList()));
result.put("ranks", Collections2.transform(ranks, Rank::getId));
Map<String, List<String>> scopeRanks = new HashMap<>();
for (ServerGroup scope : ServerGroup.findAll()) {
List<Rank> ranksOnScope = getRanksScoped(scope, grants);
scopeRanks.put(scope.getId(), Collections2.transform(ranksOnScope, Rank::getId));
}
result.put("scopeRanks", scopeRanks);
if (activeMute != null) {
result.put("mute", activeMute);
@ -663,9 +673,7 @@ public final class User {
grantedRanks.add(grantedRank);
}
if (grantedRanks.isEmpty()) {
grantedRanks.add(Rank.findById("default"));
}
grantedRanks.add(Rank.findById("default"));
if (registeredAt != null) {
grantedRanks.add(Rank.findById("registered"));