+ private boolean alreadyHasPermission(String selected) {
+ return permList.getPermissions().get(selected) != null;
+ }
+
+ private void addUserPermission(final String userDisplayName, final boolean readValue, final boolean writeValue) {
+ if (!EmailValidator.test(userDisplayName)) {
+ app.displayWarning("Username must be a valid email address");
+ return;
+ }
+
+ // Now get the userID
+ final String userID = app.getUserIDForDisplayName(userDisplayName);
+ if(userID != null) {
+ // Check if already have the permission
+ if(!alreadyHasPermission(userID)) {
+ permList.addPermission(userID, readValue, writeValue);
+ }
+ }
+ else {
+ // Must call server to obtain userID
+ new GetUserCatalogs(app, null, Helpers.toList(userDisplayName)) {
+ @Override
+ public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) {
+ app.getUserCatalogs().updateFrom(userCatalogs);
+ final String userID = app.getUserIDForDisplayName(userDisplayName);
+ if(userID == null) {
+ app.displayWarning("Unknown user " + userDisplayName);
+ }
+ else if(!alreadyHasPermission(userID)) {
+ permList.addPermission(userID, readValue, writeValue);
+ }
+ }
+ }.scheduleDeferred();
+ }
+ }
+