Add default permissions

This commit is contained in:
Colin McDonald 2016-07-11 18:39:07 -04:00
parent b9c9a3f9bc
commit d2dcd8c3e1
4 changed files with 16 additions and 16 deletions

View File

@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit;
@Entity @Entity
public final class ServerGroup { public final class ServerGroup {
public static final String DEFAULT_GROUP_ID = "default";
private static final MongoCollection<ServerGroup> serverGroupsCollection = APIv3.getDatabase().getCollection("serverGroups", ServerGroup.class); private static final MongoCollection<ServerGroup> serverGroupsCollection = APIv3.getDatabase().getCollection("serverGroups", ServerGroup.class);
private static Map<String, ServerGroup> serverGroupIdCache = null; private static Map<String, ServerGroup> serverGroupIdCache = null;
@ -38,6 +39,10 @@ public final class ServerGroup {
return serverGroupIdCache.get(id); return serverGroupIdCache.get(id);
} }
public static ServerGroup findDefault() {
return findById(DEFAULT_GROUP_ID);
}
static { static {
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache()); APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
} }
@ -67,7 +72,7 @@ public final class ServerGroup {
this.image = image; this.image = image;
} }
public Map<String, Boolean> calculateScopedPermissions(Rank rank) { public Map<String, Boolean> calculatePermissions(Rank rank) {
return PermissionUtils.mergeUpTo(permissions, rank); return PermissionUtils.mergeUpTo(permissions, rank);
} }

View File

@ -535,25 +535,25 @@ public final class User {
if (error != null) { if (error != null) {
callback.onResult(null, error); callback.onResult(null, error);
} else { } else {
Map<String, Boolean> globalPermissions = new HashMap<>(); Map<String, Boolean> compoundedPermissions = new HashMap<>();
for (Rank globalRank : getRanksScoped(null, grants)) { for (Rank globalRank : getRanksScoped(null, grants)) {
globalPermissions = PermissionUtils.mergePermissions( compoundedPermissions = PermissionUtils.mergePermissions(
globalPermissions, compoundedPermissions,
PermissionUtils.getDefaultPermissions(globalRank) ServerGroup.findDefault().calculatePermissions(globalRank)
); );
} }
for (ServerGroup serverGroup : ServerGroup.findAll()) { for (ServerGroup serverGroup : ServerGroup.findAll()) {
for (Rank scopedRank : getRanksScoped(serverGroup, grants)) { for (Rank scopedRank : getRanksScoped(serverGroup, grants)) {
globalPermissions = PermissionUtils.mergePermissions( compoundedPermissions = PermissionUtils.mergePermissions(
globalPermissions, compoundedPermissions,
serverGroup.calculateScopedPermissions(scopedRank) serverGroup.calculatePermissions(scopedRank)
); );
} }
} }
callback.onResult(ImmutableMap.copyOf(globalPermissions), null); callback.onResult(ImmutableMap.copyOf(compoundedPermissions), null);
} }
}); });
} }

View File

@ -133,8 +133,8 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
for (Rank rank : Rank.findAll()) { for (Rank rank : Rank.findAll()) {
Map<String, Boolean> scopedPermissions = PermissionUtils.mergePermissions( Map<String, Boolean> scopedPermissions = PermissionUtils.mergePermissions(
PermissionUtils.getDefaultPermissions(rank), ServerGroup.findDefault().calculatePermissions(rank),
serverGroup.calculateScopedPermissions(rank) serverGroup.calculatePermissions(rank)
); );
permissionsResponse.put(rank.getId(), PermissionUtils.convertToList(scopedPermissions)); permissionsResponse.put(rank.getId(), PermissionUtils.convertToList(scopedPermissions));

View File

@ -43,11 +43,6 @@ public class PermissionUtils {
return result; return result;
} }
// TODO: Fix this
public static Map<String, Boolean> getDefaultPermissions(Rank rank) {
return ImmutableMap.of();
}
private static Map<String, Boolean> convertFromList(List<String> permissionsList) { private static Map<String, Boolean> convertFromList(List<String> permissionsList) {
if (permissionsList == null) { if (permissionsList == null) {
return ImmutableMap.of(); return ImmutableMap.of();