Readd permission checks respecting *

This commit is contained in:
Colin McDonald 2016-08-04 17:34:33 -04:00
parent 23a6739eb1
commit 68f6f5ea79

View File

@ -574,12 +574,27 @@ public final class User {
if (error != null) { if (error != null) {
callback.onResult(null, error); callback.onResult(null, error);
} else { } else {
boolean hasPermission = permissions.containsKey(permission) && permissions.get(permission); boolean hasPermission = hasPermission(permission, permissions);
callback.onResult(hasPermission, null); callback.onResult(hasPermission, null);
} }
}); });
} }
private boolean hasPermission(String permission, Map<String, Boolean> 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<Map<String, Boolean>> callback) { public void getCompoundedPermissions(SingleResultCallback<Map<String, Boolean>> callback) {
Grant.findByUser(this, (grants, error) -> { Grant.findByUser(this, (grants, error) -> {
if (error != null) { if (error != null) {