RANGER-2509 : Add validation message for Importing non JSON file on import action.
diff --git a/security-admin/src/main/webapp/scripts/views/UploadServicePolicy.js b/security-admin/src/main/webapp/scripts/views/UploadServicePolicy.js
index 62a1fcf..70f8ee7 100644
--- a/security-admin/src/main/webapp/scripts/views/UploadServicePolicy.js
+++ b/security-admin/src/main/webapp/scripts/views/UploadServicePolicy.js
@@ -135,6 +135,10 @@
}
return modal.preventClose();
}
+ if(this.targetFileObj.type != "application/json" || !(this.targetFileObj.name).match(".json$", "i")) {
+ this.$el.find('.selectFileValidationMsg').show();
+ return modal.preventClose();
+ }
var that = this, serviceMapping = {}, fileObj = this.targetFileObj, preventModal = false , url ="";
if(this.$el.find('input[data-name="override"]').is(':checked')){
url = "service/plugins/policies/importPoliciesFromFile?isOverride=true";
@@ -222,8 +226,7 @@
this.collection.add(new Backbone.Model());
},
onRender: function() {
- this.$el.find('.fileValidation').hide();
- this.$el.find('.selectFileValidationMsg').hide();
+ this.$el.find('.selectFileValidationMsg').hide();
if(this.serviceType==undefined){
this.$el.find('.seviceFiled').show();
this.renderComponentSelect();
@@ -270,20 +273,17 @@
importPolicy : function(e){
var that =this;
console.log("uploading....");
- this.$el.find('.selectFile').hide();
this.$el.find('.selectFileValidationMsg').hide();
- this.$el.find('.fileValidation').hide();
this.targetFileObj = e.target.files[0];
if(!_.isUndefined(this.targetFileObj)){
- this.$el.find('.selectFile').html('<i>'+this.targetFileObj.name+'</i><label class="icon icon-remove icon-1x icon-remove-btn" data-id="fileNameClosebtn"></label>').show()
+ this.$el.find('.selectFile').text(this.targetFileObj.name);
+ this.$el.find('.selectFile').append('<i></i><label class="icon icon-remove icon-1x icon-remove-btn" data-id="fileNameClosebtn"></label>');
}else{
- this.$el.find('.selectFile').html("No file chosen").show();
+ this.$el.find('.selectFile').text("No file chosen");
}
},
fileNameClosebtn : function(){
- this.$el.find('.selectFile').hide()
- this.$el.find('.selectFile').html("No file chosen").show()
- this.$el.find('.fileValidation').hide();
+ this.$el.find('.selectFile').text("No file chosen");
this.$el.find('.selectFileValidationMsg').hide();
this.targetFileObj = undefined;
this.ui.importFilePolicy.val('');
diff --git a/security-admin/src/main/webapp/templates/common/uploadservicepolicy_tmpl.html b/security-admin/src/main/webapp/templates/common/uploadservicepolicy_tmpl.html
index 150a885..3e8caec 100644
--- a/security-admin/src/main/webapp/templates/common/uploadservicepolicy_tmpl.html
+++ b/security-admin/src/main/webapp/templates/common/uploadservicepolicy_tmpl.html
@@ -33,8 +33,6 @@
data-id="source" data-name="override" class="margin-left12">
</label>
<div class="selectFile margin-left6">No file chosen</div>
- <div class="fileValidation text-color-red margin-left6">Please
- Select Json file format</div>
<hr>
<div class="uploadSet">
<span><b>Specify Service Mapping : </b></span>