From 7b3e02ef2aca7bcde9d3cf699a201ade002a99bd Mon Sep 17 00:00:00 2001 From: laurenwalker Date: Thu, 14 Jun 2018 14:18:35 -0400 Subject: [PATCH] When someone tries to map identities with an incorretcly formatted ORCID, reformat it for them before giving up. Also improved the error message when a username is not found in LDAP. Closes #651 --- .../src/main/webapp/js/models/UserModel.js | 42 ++++++++++++++----- .../src/main/webapp/js/views/UserView.js | 8 +++- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/metacatui/src/main/webapp/js/models/UserModel.js b/metacatui/src/main/webapp/js/models/UserModel.js index d6397665c..a2127900a 100644 --- a/metacatui/src/main/webapp/js/models/UserModel.js +++ b/metacatui/src/main/webapp/js/models/UserModel.js @@ -378,8 +378,7 @@ define(['jquery', 'underscore', 'backbone', 'jws', 'models/Search', "collections if((typeof orcid == "undefined") && (username == this.get("orcid"))) return true; //Checks for ORCIDs using the orcid base URL as a prefix - if(username.indexOf("http://orcid.org/") == 0){ - this.set("orcid", username); + if(username.indexOf("orcid.org/") > -1){ return true; } @@ -808,31 +807,52 @@ define(['jquery', 'underscore', 'backbone', 'jws', 'models/Search', "collections success: function(data, textStatus, xhr) { if(typeof onSuccess == "function") onSuccess(data, textStatus, xhr); - + model.getInfo(); }, error: function(xhr, textStatus, error) { - if(typeof onError == "function") - onError(xhr, textStatus, error); + + //Check if the username might have been spelled or formatted incorrectly + //ORCIDs, in particular, have different formats that we should account for + if(xhr.responseText.indexOf("LDAP: error code 32 - No Such Object") > -1 && model.isOrcid(otherUsername)){ + if(otherUsername.length == 19) + model.addMap("http://orcid.org/" + otherUsername, onSuccess, onError); + else if(otherUsername.indexOf("https://orcid.org") == 0) + model.addMap(otherUsername.replace("https", "http"), onSuccess, onError); + else if(otherUsername.indexOf("orcid.org") == 0) + model.addMap("http://" + otherUsername, onSuccess, onError); + else if(otherUsername.indexOf("www.orcid.org") == 0) + model.addMap(otherUsername.replace("www.", "http://"), onSuccess, onError); + else if(otherUsername.indexOf("http://www.orcid.org") == 0) + model.addMap(otherUsername.replace("www.", ""), onSuccess, onError); + else if(otherUsername.indexOf("https://www.orcid.org") == 0) + model.addMap(otherUsername.replace("https://www.", "http://"), onSuccess, onError); + else if(typeof onError == "function") + onError(xhr, textStatus, error); + } + else{ + if(typeof onError == "function") + onError(xhr, textStatus, error); + } } } - $.ajax(_.extend(requestSettings, appUserModel.createAjaxSettings())); + $.ajax(_.extend(requestSettings, appUserModel.createAjaxSettings())); }, - + removeMap: function(otherUsername, onSuccess, onError){ if(!otherUsername) return; - + var mapUrl = appModel.get("accountsMapsUrl") + encodeURIComponent(otherUsername), model = this; - + // ajax call to remove mapping var requestSettings = { type: "DELETE", url: mapUrl, - success: function(data, textStatus, xhr) { + success: function(data, textStatus, xhr) { if(typeof onSuccess == "function") onSuccess(data, textStatus, xhr); - + model.getInfo(); }, error: function(xhr, textStatus, error) { diff --git a/metacatui/src/main/webapp/js/views/UserView.js b/metacatui/src/main/webapp/js/views/UserView.js index ee7e549a3..9d997acf5 100644 --- a/metacatui/src/main/webapp/js/views/UserView.js +++ b/metacatui/src/main/webapp/js/views/UserView.js @@ -456,7 +456,7 @@ define(['jquery', 'underscore', 'backbone', 'clipboard', 'collections/UserGroup' // Creates an HTML element to display in front of the user identity/subject. // Only used for the ORCID logo right now createIdPrefix: function(){ - if(this.model.get("orcid") || this.model.isOrcid()) + if(this.model.isOrcid()) return $(document.createElement("img")).attr("src", "./img/orcid_64x64.png").addClass("orcid-logo"); else return ""; @@ -836,6 +836,12 @@ define(['jquery', 'underscore', 'backbone', 'clipboard', 'collections/UserGroup' 'alert-warning', "#request-alert-container"); } else{ + + //Make a more understandable error message when the account isn't found + if(xhr.responseText.indexOf("LDAP: error code 32 - No Such Object") > -1){ + xhr.responseText = "The username " + equivalentIdentity + " does not exist in our system." + } + viewRef.showAlert(xhr.responseText, 'alert-error', "#request-alert-container"); } };