From d2dcd8c3e1859227126abb25e693bd97700a7c3e Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Mon, 11 Jul 2016 18:39:07 -0400 Subject: [PATCH] Add default permissions --- .../net/frozenorb/apiv3/model/ServerGroup.java | 7 ++++++- .../java/net/frozenorb/apiv3/model/User.java | 16 ++++++++-------- .../route/servers/POSTServersHeartbeat.java | 4 ++-- .../frozenorb/apiv3/util/PermissionUtils.java | 5 ----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/model/ServerGroup.java b/src/main/java/net/frozenorb/apiv3/model/ServerGroup.java index d350bf2..d958594 100644 --- a/src/main/java/net/frozenorb/apiv3/model/ServerGroup.java +++ b/src/main/java/net/frozenorb/apiv3/model/ServerGroup.java @@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit; @Entity public final class ServerGroup { + public static final String DEFAULT_GROUP_ID = "default"; private static final MongoCollection serverGroupsCollection = APIv3.getDatabase().getCollection("serverGroups", ServerGroup.class); private static Map serverGroupIdCache = null; @@ -38,6 +39,10 @@ public final class ServerGroup { return serverGroupIdCache.get(id); } + public static ServerGroup findDefault() { + return findById(DEFAULT_GROUP_ID); + } + static { APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache()); } @@ -67,7 +72,7 @@ public final class ServerGroup { this.image = image; } - public Map calculateScopedPermissions(Rank rank) { + public Map calculatePermissions(Rank rank) { return PermissionUtils.mergeUpTo(permissions, rank); } diff --git a/src/main/java/net/frozenorb/apiv3/model/User.java b/src/main/java/net/frozenorb/apiv3/model/User.java index d33435a..b59e876 100644 --- a/src/main/java/net/frozenorb/apiv3/model/User.java +++ b/src/main/java/net/frozenorb/apiv3/model/User.java @@ -535,25 +535,25 @@ public final class User { if (error != null) { callback.onResult(null, error); } else { - Map globalPermissions = new HashMap<>(); + Map compoundedPermissions = new HashMap<>(); for (Rank globalRank : getRanksScoped(null, grants)) { - globalPermissions = PermissionUtils.mergePermissions( - globalPermissions, - PermissionUtils.getDefaultPermissions(globalRank) + compoundedPermissions = PermissionUtils.mergePermissions( + compoundedPermissions, + ServerGroup.findDefault().calculatePermissions(globalRank) ); } for (ServerGroup serverGroup : ServerGroup.findAll()) { for (Rank scopedRank : getRanksScoped(serverGroup, grants)) { - globalPermissions = PermissionUtils.mergePermissions( - globalPermissions, - serverGroup.calculateScopedPermissions(scopedRank) + compoundedPermissions = PermissionUtils.mergePermissions( + compoundedPermissions, + serverGroup.calculatePermissions(scopedRank) ); } } - callback.onResult(ImmutableMap.copyOf(globalPermissions), null); + callback.onResult(ImmutableMap.copyOf(compoundedPermissions), null); } }); } diff --git a/src/main/java/net/frozenorb/apiv3/route/servers/POSTServersHeartbeat.java b/src/main/java/net/frozenorb/apiv3/route/servers/POSTServersHeartbeat.java index 4a82d19..7f7b8dd 100644 --- a/src/main/java/net/frozenorb/apiv3/route/servers/POSTServersHeartbeat.java +++ b/src/main/java/net/frozenorb/apiv3/route/servers/POSTServersHeartbeat.java @@ -133,8 +133,8 @@ public final class POSTServersHeartbeat implements Handler { for (Rank rank : Rank.findAll()) { Map scopedPermissions = PermissionUtils.mergePermissions( - PermissionUtils.getDefaultPermissions(rank), - serverGroup.calculateScopedPermissions(rank) + ServerGroup.findDefault().calculatePermissions(rank), + serverGroup.calculatePermissions(rank) ); permissionsResponse.put(rank.getId(), PermissionUtils.convertToList(scopedPermissions)); diff --git a/src/main/java/net/frozenorb/apiv3/util/PermissionUtils.java b/src/main/java/net/frozenorb/apiv3/util/PermissionUtils.java index ed6a898..8ddc16b 100644 --- a/src/main/java/net/frozenorb/apiv3/util/PermissionUtils.java +++ b/src/main/java/net/frozenorb/apiv3/util/PermissionUtils.java @@ -43,11 +43,6 @@ public class PermissionUtils { return result; } - // TODO: Fix this - public static Map getDefaultPermissions(Rank rank) { - return ImmutableMap.of(); - } - private static Map convertFromList(List permissionsList) { if (permissionsList == null) { return ImmutableMap.of();