From db938f37631f58b122e4833dda183d938e13c716 Mon Sep 17 00:00:00 2001 From: Robyn Thiessen-Bock Date: Wed, 2 Dec 2020 20:04:12 -0500 Subject: [PATCH] Check changePermission on the resource map when the editor loads Relates to issue #682 --- src/js/collections/DataPackage.js | 2 +- src/js/views/metadata/EML211EditorView.js | 33 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/js/collections/DataPackage.js b/src/js/collections/DataPackage.js index 096ddc8af..76fc22bf5 100644 --- a/src/js/collections/DataPackage.js +++ b/src/js/collections/DataPackage.js @@ -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) { diff --git a/src/js/views/metadata/EML211EditorView.js b/src/js/views/metadata/EML211EditorView.js index 969f6b94f..c13cd5ba7 100644 --- a/src/js/views/metadata/EML211EditorView.js +++ b/src/js/views/metadata/EML211EditorView.js @@ -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 @@ -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.",