This is an automated email from the ASF dual-hosted git repository.
ni3galave pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git
The following commit(s) were added to refs/heads/master by this push:
new 1aa4a4b RANGER-2509 : Add validation message for Importing non JSON
file on import action
1aa4a4b is described below
commit 1aa4a4b15f1474f6beee72fb6ba7ac178eddc34d
Author: Nitin Galave <[email protected]>
AuthorDate: Thu Jul 18 19:16:14 2019 +0530
RANGER-2509 : Add validation message for Importing non JSON file on import
action
---
.../webapp/scripts/views/UploadServicePolicy.js | 34 +++++++++++++---------
.../templates/common/uploadservicepolicy_tmpl.html | 3 +-
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git
a/security-admin/src/main/webapp/scripts/views/UploadServicePolicy.js
b/security-admin/src/main/webapp/scripts/views/UploadServicePolicy.js
index 7371c2b..060d2e2 100644
--- a/security-admin/src/main/webapp/scripts/views/UploadServicePolicy.js
+++ b/security-admin/src/main/webapp/scripts/views/UploadServicePolicy.js
@@ -278,7 +278,6 @@ define(function(require){
this.collection.add(new Backbone.Model());
},
onRender: function() {
- this.$el.find('.fileValidation').hide();
this.ui.selectFileValidationMsg.hide();
this.ui.selectZoneMapping.hide();
this.ui.selectServicesMapping.hide();
@@ -286,16 +285,25 @@ define(function(require){
importPolicy : function(e){
var that =this;
console.log("uploading....");
- this.$el.find('.selectFile').hide();
this.ui.selectFileValidationMsg.hide();
- this.$el.find('.fileValidation').hide();
- this.selectedFileValidation(e)
- this.targetFileObj = e.target.files[0];
+ if(e.target && e.target.files.length > 0){
+ this.targetFileObj = e.target.files[0];
+ } else {
+ return
+ }
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>').removeClass('text-color-red').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>');
+ //check if file name is proper json extension
or not
+ if(this.targetFileObj.type ===
"application/json" || (this.targetFileObj.name).match(".json$", "i")){
+ this.selectedFileValidation(e)
+ } else {
+ this.ui.selectFileValidationMsg.show();
+ this.fileNameClosebtn(false);
+ return
+ }
} else {
- this.$el.find('.selectFile').html("No file
chosen").show();
+ this.$el.find('.selectFile').text("No file
chosen");
}
},
selectedFileValidation : function(file){
@@ -402,11 +410,11 @@ define(function(require){
}
});
},
- fileNameClosebtn : function(){
- this.$el.find('.selectFile').hide()
- this.$el.find('.selectFile').html("No file
chosen").removeClass('text-color-red').show()
- this.$el.find('.fileValidation').hide();
- this.ui.selectFileValidationMsg.hide();
+ fileNameClosebtn : function(fileSelected){
+ if(fileSelected &&
fileSelected.hasOwnProperty('currentTarget')){
+ this.$el.find('.selectFile').text("No file
chosen");
+ this.ui.selectFileValidationMsg.hide();
+ }
this.targetFileObj = undefined;
this.ui.importFilePolicy.val('');
this.ui.selectServicesMapping.hide();
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 1e4621a..bf89303 100644
---
a/security-admin/src/main/webapp/templates/common/uploadservicepolicy_tmpl.html
+++
b/security-admin/src/main/webapp/templates/common/uploadservicepolicy_tmpl.html
@@ -21,12 +21,11 @@ language governing permissions and limitations under the
License. --}}
data-id="uploadPolicyFile" style="display: none;"
accept=" .json " />
</label>
- <span class="text-color-red"
data-id="selectFileValidationMsg">Please select json file </span>
<label class="float-right" for="override">
Override Policy : <input id="override" type="checkbox"
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>
+ <div class="fileValidation text-color-red margin-left6"
data-id="selectFileValidationMsg">Please Select Json file format</div>
<div data-id="selectZoneMapping">
<hr>
<div class="alert alert-warning show"
data-id="policyInfoAlert"><i class="icon-info-sign searchInfo m-r-xs"></i>