Skip to content

Commit

Permalink
When someone tries to map identities with an incorretcly formatted OR…
Browse files Browse the repository at this point in the history
…CID, reformat it for them before giving up.

Also improved the error message when a username is not found in LDAP.

Closes #651
  • Loading branch information
laurenwalker committed Jun 14, 2018
1 parent ba36f2c commit 7b3e02e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
42 changes: 31 additions & 11 deletions metacatui/src/main/webapp/js/models/UserModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion metacatui/src/main/webapp/js/views/UserView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down Expand Up @@ -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");
}
};
Expand Down

0 comments on commit 7b3e02e

Please sign in to comment.