Skip to content

Commit

Permalink
Check changePermission on the resource map when the editor loads
Browse files Browse the repository at this point in the history
Relates to issue #682
  • Loading branch information
robyngit committed Dec 3, 2020
1 parent 2b2b430 commit db938f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/js/collections/DataPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ define(['jquery', 'underscore', 'backbone', 'rdflib', "uuid", "md5",

/*
* The DataPackage collection stores DataPackages and
* DataONEObjects, including Metadata nad Data objects.
* DataONEObjects, including Metadata and Data objects.
* Return the correct model based on the type
*/
model: function (attrs, options) {
Expand Down
33 changes: 32 additions & 1 deletion src/js/views/metadata/EML211EditorView.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,19 @@ define(['underscore',
},

renderDataPackage: function(){

var resourceMap = MetacatUI.rootDataPackage.packageModel;

if(resourceMap.get("isAuthorized_changePermission") == null){
// Re-start the rendering of this data package once we know the user is authorized to edit it.
this.listenToOnce(resourceMap, "change:isAuthorized_changePermission", this.renderDataPackage);
// Let a user know when they are not authorized to edit this data package
this.listenToOnce(resourceMap, "change:isAuthorized_changePermission", this.notAuthorized);
// Check the authority of this user
resourceMap.checkAuthority("changePermission");
return
}

var view = this;

// As the root collection is updated with models, render the UI
Expand Down Expand Up @@ -829,7 +842,25 @@ define(['underscore',
* Shows a message if the user is not authorized to edit this package
*/
notAuthorized: function(){
if(this.model.get("isAuthorized") || this.model.get("notFound")) return;

// Don't show the not authorized message if the metadata was not found
if(this.model.get("notFound")){
return
}

// Don't show the not authorized message if the user is authorized to edit the EML and the resource map
if(MetacatUI.rootDataPackage && MetacatUI.rootDataPackage.packageModel){
if(
MetacatUI.rootDataPackage.packageModel.get("isAuthorized_changePermission") &&
this.model.get("isAuthorized")
){
return
}
} else {
if(this.model.get("isAuthorized")){
return
}
}

this.$("#editor-body").empty();
MetacatUI.appView.showAlert("You are not authorized to edit this data set.",
Expand Down

0 comments on commit db938f3

Please sign in to comment.