-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature restrict submissions #1817 #1914
base: develop
Are you sure you want to change the base?
Changes from all commits
8ba4469
c43b2b4
8bcd6ef
bce99c6
cb18893
67ff3ce
6b3a195
ed68175
07249f4
7a12fb4
23ff2d7
1ab2947
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,9 @@ define(['jquery', 'underscore', 'backbone'], | |
hiddenMembers: [], | ||
currentMemberNode: MetacatUI.appModel.get("nodeId") || null, | ||
checked: false, | ||
error: false | ||
error: false, | ||
allowedSubmitters: [], | ||
nodeInfoFound: false /* the node might access the CN, but not be part of the network, so check if MN capabilites are included in the CN report */ | ||
}, | ||
|
||
initialize: function(){ | ||
|
@@ -23,7 +25,11 @@ define(['jquery', 'underscore', 'backbone'], | |
if(MetacatUI.appModel.get('nodeServiceUrl')){ | ||
//Get the node information from the CN | ||
this.getNodeInfo(); | ||
} | ||
} else if(MetacatUI.appModeel.get('getCapabilitiesServiceUrl')) { | ||
// If the CN node service URL is not defined, see if we can get getCapabilities | ||
// information from the node directly | ||
this.getCapabilities(); | ||
} | ||
}, | ||
|
||
getMember: function(memberInfo){ | ||
|
@@ -75,11 +81,16 @@ define(['jquery', 'underscore', 'backbone'], | |
url: MetacatUI.appModel.get('nodeServiceUrl'), | ||
dataType: "text", | ||
success: function(data, textStatus, xhr) { | ||
|
||
var xmlResponse = $.parseXML(data) || null; | ||
if(!xmlResponse) return; | ||
|
||
thisModel.saveNodeInfo(xmlResponse); | ||
// It is possible for MN to retrieve the CN node capabilties report, but not be registered with DataONE. | ||
// If the CN node report was successfully retrieved, but the calling MN was not in the report, then we | ||
// need to get the MN capabilities directly from the MN. | ||
if(!thisModel.get("nodeInfoFound")) { | ||
thisModel.getCapabilities(); | ||
} | ||
Comment on lines
+91
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice that the app never sets this attribute ( Even better, we could just use This does mean that the member node info doc needs to be synced with the CN for the changes in this PR to work. Right now I'm testing with dev.nceas and it hasn't synced with the CN, so everything has been working in my tests so far because the member node info doc is grabbed directly from dev.nceas. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea on using The MN config change (updating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
|
||
thisModel.set("checked", true); | ||
}, | ||
|
@@ -96,26 +107,66 @@ define(['jquery', 'underscore', 'backbone'], | |
}); | ||
} | ||
|
||
//Trigger an error on this model | ||
thisModel.set("error", true); | ||
thisModel.trigger("error"); | ||
|
||
thisModel.set("checked", true); | ||
// If the node capabilities service isn't available from the CN, try getting it from the current MN. | ||
// This is also intended to be used by standalone repositories, i.e. those that are not part of the DataONE network. | ||
thisModel.getCapabilities(); | ||
} | ||
}); | ||
}, | ||
|
||
getCapabilities: function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this method name is misleading because more than the node capabilities are retrieved and set on the model. If we are only setting the node capabilities, then let's keep this name. But if we are setting all of the node properties (which it appears we are based on like 127 ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also please add a method description using JSDoc? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I'll update the method call name and create the JSDoc entry. |
||
var thisModel = this; | ||
|
||
$.ajax({ | ||
url: MetacatUI.appModel.get('getCapabilitiesServiceUrl'), | ||
dataType: "text", | ||
success: function(data, textStatus, xhr) { | ||
|
||
var xmlResponse = $.parseXML(data) || null; | ||
if(!xmlResponse) return; | ||
thisModel.saveNodeInfo(xmlResponse); | ||
thisModel.set("checked", true); | ||
}, | ||
error: function(xhr, textStatus, errorThrown){ | ||
|
||
//Log the error to the console | ||
console.error("Couldn't get the DataONE node capabilities document: ", textStatus, errorThrown); | ||
|
||
//Send this exception to Google Analytics | ||
if(MetacatUI.appModel.get("googleAnalyticsKey") && (typeof ga !== "undefined")){ | ||
ga("send", "exception", { | ||
"exDescription": "Couldn't get the DataONE node capabilties document: " + textStatus + ", " + errorThrown + " | v. " + MetacatUI.metacatUIVersion, | ||
"exFatal": false | ||
}); | ||
} | ||
|
||
//Trigger an error on this model | ||
thisModel.set("error", true); | ||
thisModel.trigger("error"); | ||
thisModel.set("checked", true); | ||
} | ||
}); | ||
}, | ||
|
||
// end new | ||
|
||
saveNodeInfo: function(xml){ | ||
var thisModel = this, | ||
memberList = this.get('members'), | ||
coordList = this.get('coordinators'), | ||
children = xml.children || xml.childNodes; | ||
|
||
|
||
//Traverse the XML response to get the MN info | ||
_.each(children, function(d1NodeList){ | ||
|
||
var d1NodeListChildren = d1NodeList.children || d1NodeList.childNodes; | ||
// If the capabbilities reeport was obtained directly from the MN | ||
// then there will be a single <node> entry as the root elemeent. If it was obtained | ||
// from the CN 'listNodes' then the root element will be <nodeList> | ||
if (d1NodeList.localName == "node") { | ||
var d1NodeListChildren = $(d1NodeList).toArray(); | ||
} else { | ||
var d1NodeListChildren = d1NodeList.children || d1NodeList.childNodes; | ||
} | ||
|
||
//The first (and only) child should be the d1NodeList | ||
_.each(d1NodeListChildren, function(thisNode){ | ||
|
@@ -124,7 +175,7 @@ define(['jquery', 'underscore', 'backbone'], | |
if(!thisNode.attributes) return; | ||
|
||
//'node' will be a single node | ||
var node = {}, | ||
var node = {} , | ||
nodeProperties = thisNode.children || thisNode.childNodes; | ||
|
||
//Grab information about this node from XML nodes | ||
|
@@ -135,11 +186,30 @@ define(['jquery', 'underscore', 'backbone'], | |
else | ||
node[nodeProperty.nodeName] = nodeProperty.textContent; | ||
|
||
var submitters = []; | ||
//Check if this member node has v2 read capabilities - important for the Package service | ||
if((nodeProperty.nodeName == "services") && nodeProperty.childNodes.length){ | ||
var v2 = $(nodeProperty).find("service[name='MNRead'][version='v2'][available='true']").length; | ||
node["readv2"] = v2; | ||
// Get the service restrictions for the current member node | ||
if( MetacatUI.nodeModel.get("currentMemberNode") == $(thisNode).find("identifier").text()) { | ||
var storageProperty = $(nodeProperty).find("service[name='MNStorage'][version='v2'][available='true']"); | ||
if (storageProperty.children().length) { | ||
var restrictionProperty = $(storageProperty).find("restriction[methodName='create']"); | ||
if (restrictionProperty.length && restrictionProperty.children().length) { | ||
_.each(restrictionProperty.children(), function(subject) { | ||
if(subject.nodeName == "subject") { | ||
submitters.push(subject.textContent); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
if(submitters.length) { | ||
var currentSubmitters = thisModel.get("allowedSubmitters"); | ||
thisModel.set("allowedSubmitters", submitters.concat(currentSubmitters)); | ||
} | ||
}); | ||
|
||
//Grab information about this node from XLM attributes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="alert.plain"> | ||
<p><%=messageText%></p> | ||
<i class="icon-warning-sign">Editing is not allowed.></i> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as the AppModel.nodeServiceUrl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see that the nodeServiceUrl is for the CN and getCapabilitiesServiceUrl is for the MN.