From 68f6f5ea7912ea3dcdcd51dff342f918da62552d Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Thu, 4 Aug 2016 17:34:33 -0400 Subject: [PATCH] Readd permission checks respecting * --- .../java/net/frozenorb/apiv3/model/User.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/frozenorb/apiv3/model/User.java b/src/main/java/net/frozenorb/apiv3/model/User.java index 08f84c1..70414d2 100644 --- a/src/main/java/net/frozenorb/apiv3/model/User.java +++ b/src/main/java/net/frozenorb/apiv3/model/User.java @@ -574,12 +574,27 @@ public final class User { if (error != null) { callback.onResult(null, error); } else { - boolean hasPermission = permissions.containsKey(permission) && permissions.get(permission); + boolean hasPermission = hasPermission(permission, permissions); callback.onResult(hasPermission, null); } }); } + private boolean hasPermission(String permission, Map permissions) { + if (permissions.containsKey(permission) && permissions.get(permission)) { + return true; + } + + int lastDot = permission.lastIndexOf("."); + + if (lastDot == -1) { + return false; + } + + String modifiedPermission = permission.substring(0, lastDot) + ".*"; + return permissions.containsKey(modifiedPermission) && permissions.get(modifiedPermission); + } + public void getCompoundedPermissions(SingleResultCallback> callback) { Grant.findByUser(this, (grants, error) -> { if (error != null) {