Repository: incubator-ranger
Updated Branches:
refs/heads/master 3a57aa3c3 -> a63bf0aaa
RANGER-203: UI fixes for the following:
1. Support to advance service config
2. Added users/group permissions and audit log validation to policy form
create/update as per earlier implementation
For example : In policy detail page if we select group for policy without
selecting any permissions on policy save it should show pop-up message "Please
add perms for selected group" like earlier functionality
3. Fixed Resource lookup issues
4. Other cleanup on UI side
Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/4dd69034
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/4dd69034
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/4dd69034
Branch: refs/heads/master
Commit: 4dd6903450bc8097562bfb143f65d6f45a44185b
Parents: 3a57aa3
Author: Gautam Borad <[email protected]>
Authored: Wed Feb 25 01:04:21 2015 -0800
Committer: Madhan Neethiraj <[email protected]>
Committed: Wed Feb 25 01:04:21 2015 -0800
----------------------------------------------------------------------
.../service-defs/ranger-servicedef-hbase.json | 2 +-
.../org/apache/ranger/biz/ServiceDBStore.java | 8 +-
.../scripts/models/BackboneFormDataType.js | 54 ++--
.../main/webapp/scripts/modules/XAOverrides.js | 260 +++++++++----------
.../scripts/views/policies/PermissionList.js | 51 ++--
.../views/policies/RangerPolicyCreate.js | 57 +++-
.../scripts/views/policies/RangerPolicyForm.js | 189 +++++++++-----
.../webapp/scripts/views/service/ServiceForm.js | 12 +-
security-admin/src/main/webapp/styles/xa.css | 17 +-
.../policies/RangerPolicyForm_tmpl.html | 1 -
.../templates/service/ServiceForm_tmpl.html | 1 +
11 files changed, 396 insertions(+), 256 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/agents-common/src/main/resources/service-defs/ranger-servicedef-hbase.json
----------------------------------------------------------------------
diff --git
a/agents-common/src/main/resources/service-defs/ranger-servicedef-hbase.json
b/agents-common/src/main/resources/service-defs/ranger-servicedef-hbase.json
index e04ee15..f65d896 100644
--- a/agents-common/src/main/resources/service-defs/ranger-servicedef-hbase.json
+++ b/agents-common/src/main/resources/service-defs/ranger-servicedef-hbase.json
@@ -35,7 +35,7 @@
[
{"name":"table", "type":"string","level":1,"parent":"",
"mandatory":true,"lookupSupported":true,
"recursiveSupported":false,"excludesSupported":true,"matcher":"org.apache.ranger.plugin.resourcematcher.RangerDefaultResourceMatcher","matcherOptions":"wildCard=true;ignoreCase=true","label":"HBase
Table","description":"HBase Table"},
{"name":"column-family","type":"string","level":2,"parent":"table",
"mandatory":true,"lookupSupported":true,
"recursiveSupported":false,"excludesSupported":true,"matcher":"org.apache.ranger.plugin.resourcematcher.RangerDefaultResourceMatcher","matcherOptions":"wildCard=true;ignoreCase=true","label":"HBase
Column-family","description":"HBase Column-family"},
- {"name":"column",
"type":"string","level":3,"parent":"column-family","mandatory":true,"lookupSupported":false,"recursiveSupported":false,"excludesSupported":true,"matcher":"org.apache.ranger.plugin.resourcematcher.RangerDefaultResourceMatcher","matcherOptions":"wildCard=true;ignoreCase=true","label":"HBase
Column","description":"HBase Column"}
+ {"name":"column",
"type":"string","level":3,"parent":"column-family","mandatory":true,"lookupSupported":true,"recursiveSupported":false,"excludesSupported":true,"matcher":"org.apache.ranger.plugin.resourcematcher.RangerDefaultResourceMatcher","matcherOptions":"wildCard=true;ignoreCase=true","label":"HBase
Column","description":"HBase Column"}
],
"accessTypes":
[
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
----------------------------------------------------------------------
diff --git
a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
index 292a9b9..0cb1707 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
@@ -880,8 +880,9 @@ public class ServiceDBStore implements ServiceStore {
}
Map<String, String> validConfigs = new HashMap<String,
String>();
for(Entry<String, String> config : configs.entrySet()) {
- String confKey = config.getKey();
- String confValue = config.getValue();
+ validConfigs.put(config.getKey(), config.getValue());
+ /*String confKey = ;
+ String confValue = ;
boolean found = false;
for(XXServiceConfigDef xConfDef : svcConfDefList) {
@@ -891,11 +892,10 @@ public class ServiceDBStore implements ServiceStore {
}
}
if(found) {
- validConfigs.put(confKey, confValue);
} else {
LOG.info("Ignoring this config parameter:" +
confKey
+ ", as its not valid conf
param for service");
- }
+ }*/
}
return validConfigs;
}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
----------------------------------------------------------------------
diff --git
a/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
b/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
index 464bf4c..4a2fc84 100644
--- a/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
+++ b/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
@@ -35,35 +35,37 @@ define(function(require) {
return;
}
if(v.excludesSupported
|| v.recursiveSupported || v.lookupSupported){
+ var
resourceOpts = {};
formObj.type =
'Resource';
-
if(!_.isUndefined(v.lookupSupported) && v.lookupSupported ){
- var
options = {'containerCssClass' : v.name,
-
lookupURL :
"service/plugins/services/lookupResource/"+form.rangerService.get('name')
-
};
-
formObj['select2Opts'] = form.getPlugginAttr(true, options);
- }
formObj['excludeSupport']= v.excludesSupported;
formObj['recursiveSupport'] = v.recursiveSupported;
formObj.name =
v.name;
- formObj.level =
v.level;
-
formObj.editorAttrs = {'data-placeholder': v.label };
+// formObj.level =
v.level;
+
//checkParentHideShow field
formObj.fieldAttrs = { 'data-name' : 'field-'+v.name, 'parent' : v.parent };
+
formObj['resourceOpts'] = {'data-placeholder': v.label };
-
- //check whether
resourceType drop down is created for same level or not
+
if(!_.isUndefined(v.lookupSupported) && v.lookupSupported ){
+ var
opts = {
+
'type' : v.name,
+
'lookupURL' :
"service/plugins/services/lookupResource/"+form.rangerService.get('name')
+
};
+
resourceOpts['select2Opts'] = form.getPlugginAttr(true, opts);
+
formObj['resourceOpts'] = resourceOpts;
+ }
+ //same level
resources check
var
optionsAttrs = _.filter(config,function(field){ if(field.level == v.level)
return field;})
if(optionsAttrs.length > 1){
-
formObj['resourcesAtSameLevel'] = true;
var
optionsTitle = _.map(optionsAttrs,function(field){ return field.name;});
formObj['sameLevelOpts'] = optionsTitle;
samelevelFieldCreated.push(v.level);
-
fieldName = 'sameLevel'+v.level;
-
formObj.title = '';
-
+
formObj['title'] = '';
+
formObj['resourcesAtSameLevel'] = true;
+
+ //
formView is used to listen form events
formObj['formView'] = form;
}
-
}else{
formObj.type =
'Text';
}
@@ -94,28 +96,24 @@ define(function(require) {
});
break;
case 'path' :
- /*formObj.type = 'Text';
-
form.initilializePathPlugin = true;
- form.pathFieldName =
v.name;*/
formObj.type =
'Resource';
+
formObj['excludeSupport']= v.excludesSupported;
+
formObj['recursiveSupport'] = v.recursiveSupported;
+ formObj['name'] =
v.name;
+ formObj['editorAttrs']
= {'data-placeholder': v.label };
if(!_.isUndefined(v.lookupSupported) && v.lookupSupported ){
- var options =
{'containerCssClass' : v.name,
-
lookupURL :
"service/plugins/services/lookupResource/"+form.rangerService.get('name')
+ var options = {
+
'containerCssClass' : v.name,
+
'lookupURL' :
"service/plugins/services/lookupResource/"+form.rangerService.get('name')
};
form.pathFieldName = v.name;
form.initilializePathPlugin = true;
}
-
formObj['excludeSupport']= v.excludesSupported;
-
formObj['recursiveSupport'] = v.recursiveSupported;
formObj['initilializePathPlugin'] = true;
- formObj.name = v.name;
- formObj.level = v.level;
- formObj.editorAttrs =
{'data-placeholder': v.label };
-
-
break;
case 'password':formObj.type =
'Password';break;
- default:formObj.type =
'Text';break;
+ default:formObj.type = 'Text';
+ break;
}
if(_.isUndefined(formObj.title)){
formObj.title = v.label ||
v.name;
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
b/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
index e2fcc8f..df728a3 100644
--- a/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
+++ b/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
@@ -347,73 +347,53 @@
*
*/
Form.editors.Resource = Form.editors.Base.extend({
- ui : {
+ ui : {
'resource' : '[data-js="resource"]',
'excludeSupport' : '[data-js="include"]',
'recursiveSupport' : '[data-js="recursive"]',
'resourceType' : '[data-js="resourceType"]',
- },
- events: {
- 'click': function(event) {
- },
+ },
+ events: {
+ 'click': function(event) {
},
-
- initialize: function(options) {
- Form.editors.Base.prototype.initialize.call(this,
options);
- _.extend(this,
_.pick(this.schema,'excludeSupport','recursiveSupport','select2Opts','resourcesAtSameLevel','sameLevelOpts','level',
- 'initilializePathPlugin',
'validators','name','formView'));
-
- this.template = this.getTemplate();
-// this.resourceObj = { 'level' : this.level};
- if(_.isUndefined(this.value) ||
_.isNull(this.value)){
+ },
+ initialize: function(options) {
+ Form.editors.Base.prototype.initialize.call(this, options);
+ //default options
+ this.excludeSupport = false;
+ this.recursiveSupport = false;
+ this.resourcesAtSameLevel = false;
+ this.initilializePathPlugin = false;
+ this.resourceOpts = {};
+ _.extend(this,
_.pick(this.schema,'excludeSupport','recursiveSupport','resourceOpts','resourcesAtSameLevel','sameLevelOpts',
+
'initilializePathPlugin', 'validators','name','formView'));
+ this.template = this.getTemplate();
+ },
+ initializeElements : function() {
+ this.$resource = this.$el.find(this.ui.resource)
+ this.$excludeSupport =
this.$el.find(this.ui.excludeSupport)
+ this.$recursiveSupport =
this.$el.find(this.ui.recursiveSupport)
+ this.$resourceType =
this.$el.find(this.ui.resourceType)
+ if(_.isUndefined(this.value) || _.isNull(this.value)){
this.value = {};
- }
- },
- getTemplate : function() {
- var optionsHtml="", selectTemplate =
'',excludeSupportToggleDiv='', recursiveSupportToggleDiv='';
- this.preserveResourceValues = {};
-
if(!_.isUndefined(this.resourcesAtSameLevel) && this.resourcesAtSameLevel){
- _.each(this.sameLevelOpts,
function(option){
- return optionsHtml += "<option
value='"+option+"'>"+option+"</option>";
-
- },this);
- selectTemplate = '<select
data-js="resourceType" class="btn dropdown-toggle" style="margin-right:
31px;margin-left: -130px;width: 100px;height: 29px;font-family:
Tahoma;font-size: 14px;border-radius: 10px;border: 2px #cccccc solid;">\
- '+optionsHtml+'\
- </select>';
-
- }
- if(!_.isUndefined(this.excludeSupport) &&
this.excludeSupport){
- excludeSupportToggleDiv = '<div
class="toggle-xa include-toggle" data-js="include"><div
class="toggle"></div></div>';
- }
- if(!_.isUndefined(this.recursiveSupport) &&
this.recursiveSupport){
- kclass =
!_.isEmpty(excludeSupportToggleDiv) ? 'recursive-toggle' : 'include-toggle';
-
if(!_.isUndefined(this.initilializePathPlugin) && this.initilializePathPlugin){
- kclass =
"recursive-toggle-path";
- }
- recursiveSupportToggleDiv = '<div
class="toggle-xa '+kclass+'" data-js="recursive"><div
class="toggle"></div></div>';
- }
- return _.template(selectTemplate+'<input
data-js="resource" maxlength="255"
type="text">'+excludeSupportToggleDiv+''+recursiveSupportToggleDiv);
- },
-
- /**
- * Adds the editor to the DOM
- */
- render: function() {
- var that = this, dirtyFieldValue = null;
- var XAUtil = require('utils/XAUtils');
- this.$el.html( this.template );
- this.$resource = this.$el.find(this.ui.resource)
- this.$excludeSupport =
this.$el.find(this.ui.excludeSupport)
- this.$recursiveSupport =
this.$el.find(this.ui.recursiveSupport)
- this.$resourceType =
this.$el.find(this.ui.resourceType)
-
- if(!_.isNull(this.value) && !_.isEmpty(this.value)){
+ }
+ },
+ /**
+ * Adds the editor to the DOM
+ */
+ render: function() {
+ //render template
+ this.$el.html( this.template );
+ this.initializeElements();
+ this.renderResource();
+ this.renderToggles();
+ this.renderSameLevelResource();
+ return this;
+ },
+ renderResource : function() {
+ var that = this;
+ if(!_.isNull(this.value) && !_.isEmpty(this.value)){
this.$resource.val(this.value.values.toString())
-
- //check dirty field value for resource
- this.$resource.on('change', function(e) {
-//
that.checkDirtyFieldForSelect2($(e.currentTarget), that, this.value);
- });
//to preserve resources values to text field
if(!_.isUndefined(this.value.resourceType)){
this.preserveResourceValues[this.value.resourceType] =
this.value.values.toString();
@@ -421,17 +401,26 @@
this.preserveResourceValues[this.name]
= this.value.values.toString();
}
}
- if(!_.isUndefined(this.select2Opts)){
-
this.$resource.select2(this.select2Opts).on('change',function(e){
+ //check dirtyField for input
+ this.$resource.on('change', function(e) {
+
if(_.isUndefined(that.resourceOpts.select2Opts)){
+
that.checkDirtyFieldForSelect2($(e.currentTarget), that, this.value);
+ }
+ });
+ //create select2 if select2Opts is specified
+ if(!_.isUndefined(this.resourceOpts.select2Opts)){
+
this.$resource.select2(this.resourceOpts.select2Opts).on('change',function(e){
console.log(e)
that.preserveResourceValues[that.$resourceType.val()] = e.currentTarget.value;
- //check dirty field value for resource
-// dirtyFieldValue =
XAUtil.checkDirtyFieldForSelect2($(e.currentTarget), dirtyFieldValue, that)
+ //check dirty field value for select2
resource field
that.checkDirtyFieldForSelect2($(e.currentTarget), that, this.value);
});
}
- var isExcludes = false, isRecursive = true;
+ },
+ renderToggles : function() {
+ var XAUtil = require('utils/XAUtils');
+ var that = this, isExcludes = false, isRecursive =
true;
if(this.excludeSupport){
if(!_.isNull(this.value)){
this.value.isExcludes =
_.isUndefined(this.value.isExcludes) ? false : this.value.isExcludes;
@@ -455,27 +444,26 @@
on: isRecursive,
text : {on : 'recursive', off :
'nonrecursive' },
width: 105
-// height: 20
+// height: 20
}).on('toggle', function (e, active) {
that.value.isRecursive = active;
XAUtil.checkDirtyFieldForToggle($(e.currentTarget))
});
}
- if(!_.isUndefined(this.$resourceType) &&
this.$resourceType.length > 0){
+ },
+ renderSameLevelResource : function() {
+ var that = this, dirtyFieldValue = null
+ if(!_.isUndefined(this.$resourceType) &&
this.$resourceType.length > 0){
if(!_.isNull(this.value) &&
!_.isEmpty(this.value)){
this.$resourceType.val(this.value.resourceType);
- //
}
this.$resourceType.on('change',
function(e) {
-
if(!_.isUndefined(that.select2Opts)){
-
if(!_.isUndefined(that.preserveResourceValues[e.currentTarget.value])){
-
that.$resource.select2('val',
that.preserveResourceValues[e.currentTarget.value].split(','))
- }else{
-
that.$resource.select2('val', '')
- }
- }else{
-
that.$resource.val('');
- }
+
if(!_.isUndefined(that.preserveResourceValues[e.currentTarget.value])){
+ var val =
_.isEmpty(that.preserveResourceValues[e.currentTarget.value]) ? '' :
that.preserveResourceValues[e.currentTarget.value].split(',');
+
that.$resource.select2('val', val)
+ }else{
+
that.$resource.select2('val', '')
+ }
//reset values
that.value.isExcludes = false;
that.value.isRecursive = true;
@@ -488,62 +476,74 @@
that.formView.trigger('policyForm:parentChildHideShow',true);
});
}
- return this;
- },
-
- getValue: function() {
- //checkParent
-
if(this.$el.parents('.control-group').hasClass('hideResource')){
+ },
+ getValue: function() {
+ //checkParent
+
if(this.$el.parents('.control-group').hasClass('hideResource')){
+ return null;
+ }
+ this.value['resource'] = this.$resource.val();
+ //validation
+ if(!_.isUndefined(this.validators) &&
($.inArray('required',this.validators) != -1)){
+ if(_.isEmpty(this.value.resource))
return null;
+ }
+ if(!_.isUndefined(this.$resourceType) &&
this.$resourceType.length > 0){
+ this.value['resourceType'] =
this.$resourceType.val();
+ }
+ return this.value;
+ },
+
+ setValue: function(val) {
+ return true;
+ },
+ checkDirtyFieldForSelect2 : function($el,that,value) {
+ var defaultResourceValue =
_.isUndefined(that.value.values) ? [] : that.value.values;
+
+ if($el.hasClass('dirtyField')){
+ var tmpValue={};
+ tmpValue.values = _.isEmpty(value) ? [] :
value.split(',');
+ tmpValue.isExcludes = that.value.isExcludes;
+ tmpValue.isRecursive = that.value.isRecursive;
+ if(_.isEqual(tmpValue, dirtyFieldValue)){
+ $el.removeClass('dirtyField');
}
- if(!_.isUndefined(this.$resourceType) &&
this.$resourceType.length > 0){
- this.value['resourceType'] =
this.$resourceType.val();
- }
- this.value['resource'] = this.$resource.val();
- //for validation
- if(!_.isUndefined(this.validators) &&
($.inArray('required',this.validators) != -1)){
- if(_.isEmpty(this.value.resource))
- return null;
- }
- return this.value;
- //return this.$el.find('.active').text() ==
"ON" ? true : false;
- },
-
- setValue: function(val) {
- return true;
- },
- checkDirtyFieldForSelect2 : function($el,that,value) {
- var defaultResourceValue =
_.isUndefined(that.value.values) ? [] : that.value.values;
-// that.value.values = this.value;
-
- if($el.hasClass('dirtyField')){
- var tmpValue={};
- if(_.isEmpty(value)){
- tmpValue.values = []
- }else{
- tmpValue.values =
value.split(',');
- }
- tmpValue.isExcludes =
that.value.isExcludes;
- tmpValue.isRecursive =
that.value.isRecursive;
- if(_.isEqual(tmpValue,
dirtyFieldValue)){
- $el.removeClass('dirtyField');
- }
-
- }else if(!$el.hasClass('dirtyField')){
- $el.addClass('dirtyField');
- if(!_.isNull(that.value)){
- that.value.values =
defaultResourceValue;
-
if(_.isUndefined(that.value.isExcludes)){
- that.value.isExcludes =
that.excludeSupport ? true : false;
- }
-
if(_.isUndefined(that.value.isRecursive)){
- that.value.isRecursive
= that.RecursiveSupport ? true : false;
- }
- }
- dirtyFieldValue = that.value
- }
+ }else if(!$el.hasClass('dirtyField')){
+ $el.addClass('dirtyField');
+ if(!_.isNull(that.value)){
+ that.value.values = defaultResourceValue;
+ if(_.isUndefined(that.value.isExcludes)){
+ that.value.isExcludes =
that.excludeSupport ? true : false;
+ }
+ if(_.isUndefined(that.value.isRecursive)){
+ that.value.isRecursive =
that.RecursiveSupport ? true : false;
+ }
+ }
+ dirtyFieldValue = that.value
}
-
+ },
+ getTemplate : function() {
+ var optionsHtml="", selectTemplate =
'',excludeSupportToggleDiv='', recursiveSupportToggleDiv='';
+ this.preserveResourceValues = {};
+ if(this.resourcesAtSameLevel){
+ _.each(this.sameLevelOpts,
function(option){ return optionsHtml += "<option
value='"+option+"'>"+option+"</option>"; },this);
+ selectTemplate = '<select
data-js="resourceType" class="btn dropdown-toggle sameLevelDropdown" >\
+
'+optionsHtml+'\
+
</select>';
+ }
+ if(this.excludeSupport){
+ excludeSupportToggleDiv = '<div
class="toggle-xa include-toggle" data-js="include"><div
class="toggle"></div></div>';
+ }
+ if(this.recursiveSupport){
+ kclass =
!_.isEmpty(excludeSupportToggleDiv) ? 'recursive-toggle' : 'include-toggle';
+ if(this.initilializePathPlugin){
+ kclass =
"recursive-toggle-path";
+ }
+ recursiveSupportToggleDiv = '<div
class="toggle-xa '+kclass+'" data-js="recursive"><div
class="toggle"></div></div>';
+ }
+ return _.template(selectTemplate+'<input
data-js="resource" type="text">'+
+
excludeSupportToggleDiv+''+recursiveSupportToggleDiv);
+ },
});
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js
----------------------------------------------------------------------
diff --git
a/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js
b/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js
index 7cf66a9..fc57134 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js
@@ -138,7 +138,6 @@ define(function(require) {
var name = ($(e.currentTarget).attr('data-js')
== that.ui.selectGroups.attr('data-js')) ? 'group': 'user';
that.checkDirtyFieldForDropDown(e);
- that.toggleAddButton(e);
if(e.removed != undefined){
var gNameArr = [];
if(that.model.get(name+'Name') !=
undefined)
@@ -148,11 +147,13 @@ define(function(require) {
}else{
that.model.unset(name+'Name');
}
+ that.toggleAddButton(e);
return;
}
if(!_.isUndefined(e.added)){
- var nameList =
_.map($(e.currentTarget).select2("data"), function(obj){return obj.text});
-
that.model.set(name+'Name',nameList.toString());
+ var nameList =
_.map($(e.currentTarget).select2("data"), function(obj){return obj.text});
+
that.model.set(name+'Name',nameList.toString());
+ that.toggleAddButton(e);
}
});
},
@@ -391,19 +392,31 @@ define(function(require) {
XAUtil.checkDirtyField(permList, perms, this.$el);
},
toggleAddButton : function(e){
- var temp = [];
+ var grpTemp = [], usrTemp = [];
this.collection.each(function(m){
- if(!_.isUndefined(m.get('groupId'))){
- temp.push.apply(temp,
m.get('groupId').split(','));
+ if(!_.isUndefined(m.get('groupName')) &&
!_.isNull(m.get('groupName'))){
+ grpTemp.push.apply(grpTemp,
m.get('groupName').split(','));
}
+ if(!_.isUndefined(m.get('userName')) &&
!_.isNull(m.get('userName'))){
+ usrTemp.push.apply(usrTemp,
m.get('userName').split(','));
+ }
});
if(!_.isUndefined(e)){
- if( !_.isUndefined(e.added) && ((temp.length +
1) == this.groupList.length))
- $('[data-action="addGroup"]').hide();
+ if( !_.isUndefined(e.added)){
+ if((grpTemp.length ) ==
this.groupList.length && ((usrTemp.length) == this.userList.length)){
+
$('[data-action="addGroup"]').hide();
+ }else{
+
$('[data-action="addGroup"]').show();
+ }
+ }
if(!_.isUndefined(e.removed))
$('[data-action="addGroup"]').show();
}else{
- $('[data-action="addGroup"]').show();
+ if((grpTemp.length ) == this.groupList.length
&& ((usrTemp.length) == this.userList.length)){
+ $('[data-action="addGroup"]').hide();
+ }else{
+ $('[data-action="addGroup"]').show();
+ }
}
},
policyCondtionChange :function(e){
@@ -464,24 +477,28 @@ define(function(require) {
this.collection.add(new Backbone.Model());
},
onRender : function(){
- this.toggleAddButton();
+// this.toggleAddButton();
},
addNew : function(){
var that =this;
- if(this.groupList.length > this.collection.length){
+ if(this.groupList.length > this.collection.length ||
(this.userList.length > this.collection.length)){
this.collection.add(new Backbone.Model());
- this.toggleAddButton();
+// this.toggleAddButton();
}
},
toggleAddButton : function(){
- var groupIds=[];
+ var groupNames=[], userNames=[];
this.collection.each(function(m){
- if(!_.isUndefined(m.get('groupId'))){
- var temp = m.get('groupId').split(',');
- groupIds.push.apply(groupIds,temp);
+ if(!_.isUndefined(m.get('groupName'))){
+ var temp =
m.get('groupName').split(',');
+ groupNames.push.apply(groupNames,temp);
+ }
+ if(!_.isUndefined(m.get('userName'))){
+ var temp = m.get('userName').split(',');
+ userNames.push.apply(userNames,temp);
}
});
- if(groupIds.length == this.groupList.length)
+ if(groupNames.length == this.groupList.length &&
userNames.length == this.userList.length )
this.$('button[data-action="addGroup"]').hide();
else
this.$('button[data-action="addGroup"]').show();
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
----------------------------------------------------------------------
diff --git
a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
index eacf119..0df992f 100644
---
a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
+++
b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
@@ -122,13 +122,68 @@ define(function(require){
this.rForm.$el.dirtyFields();
XAUtil.preventNavigation(localization.tt('dialogMsg.preventNavPolicyForm'),this.rForm.$el);
},
+ popupCallBack : function(msg,validateObj){
+ var that = this;
+ XAUtil.alertPopup({
+ msg :msg,
+ callback : function(){
+ // if(validateObj.auditLoggin)
+ // that.savePolicy();
+ }
+ });
+ },
onSave: function(){
var that = this, valid = false;
var errors = this.form.commit({validate : false});
if(! _.isEmpty(errors)){
return;
}
- this.savePolicy();
+ var validateObj = this.form.formValidation();
+ valid = (validateObj.groupSet && validateObj.permSet)
|| (validateObj.userSet && validateObj.userPerm);
+ if(!valid){
+ if(validateObj.groupSet &&
(!validateObj.permSet)){
+
this.popupCallBack(localization.tt('msg.addGroupPermission'),validateObj);
+ }else if((!validateObj.groupSet) &&
(validateObj.permSet)) {
+
this.popupCallBack(localization.tt('msg.addGroup'),validateObj);
+
+ }else if(validateObj.userSet &&
(!validateObj.userPerm)){
+
this.popupCallBack(localization.tt('msg.addUserPermission'),validateObj);
+ }else if((!validateObj.userSet) &&
(validateObj.userPerm)) {
+
this.popupCallBack(localization.tt('msg.addUser'),validateObj);
+
+ }else if((!validateObj.auditLoggin) &&
(!validateObj.groupPermSet)){
+ XAUtil.alertPopup({
+ msg
:localization.tt('msg.yourAuditLogginIsOff'),
+ callback : function(){
+
/*if(!that.model.isNew()){
+
that.model.destroy({success: function(model, response) {
+
XAUtil.notifySuccess('Success', localization.tt('msg.policyDeleteMsg'));
+
App.appRouter.navigate("#!/hdfs/"+that.assetModel.id+"/policies",{trigger:
true});
+ }});
+ }else{
+
XAUtil.notifyError('Error', localization.tt('msg.policyNotAddedMsg'));
+
App.appRouter.navigate("#!/hdfs/"+that.assetModel.id+"/policies",{trigger:
true});
+ }*/
+ }
+ });
+ }else{
+ this.savePolicy();
+ }
+ }else{
+ if(validateObj.groupSet &&
(!validateObj.permSet)){
+
this.popupCallBack(localization.tt('msg.addGroupPermission'),validateObj);
+ }else if((!validateObj.groupSet) &&
(validateObj.permSet)) {
+
this.popupCallBack(localization.tt('msg.addGroup'),validateObj);
+
+ }else if(validateObj.userSet &&
(!validateObj.userPerm)){
+
this.popupCallBack(localization.tt('msg.addUserPermission'),validateObj);
+ }else if((!validateObj.userSet) &&
(validateObj.userPerm)) {
+
this.popupCallBack(localization.tt('msg.addUser'),validateObj);
+
+ }else{
+ this.savePolicy();
+ }
+ }
},
savePolicy : function(){
var that = this;
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
----------------------------------------------------------------------
diff --git
a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
index ee96226..988f57c 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
@@ -87,7 +87,7 @@ define(function(require){
},
getSchema : function(){
var attrs = {};
- var basicSchema = ['id', 'name','isEnabled']
+ var basicSchema = ['name','isEnabled']
var schemaNames = ['description', 'isAuditEnabled'];
var formDataType = new BackboneFormDataType();
@@ -110,52 +110,12 @@ define(function(require){
if(!this.model.isNew()){
this.setUpSwitches();
}
-
this.$el.find('.field-isEnabled').find('.control-label').remove();
//checkParent
this.renderParentChildHideShow();
- },
- renderParentChildHideShow : function(onChangeOfSameLevelType) {
- var formDiv = this.$el.find('.policy-form');
- if(!this.model.isNew() && !onChangeOfSameLevelType){
- _.each(this.selectedResourceTypes,
function(val, sameLevelName) {
-
if(formDiv.find('.field-'+sameLevelName).length > 0){
-
formDiv.find('.field-'+sameLevelName).attr('data-name','field-'+val)
- }
- });
- }
- var resources = formDiv.find('.control-group');
- _.each(resources, function(rsrc){
- var parent = $(rsrc).attr('parent')
- if( !_.isUndefined(parent) && !
_.isEmpty(parent)){
- console.log(formDiv.find())
- var selector =
"div[data-name='field-"+parent+"']"
- if(formDiv.find(selector).length > 0 &&
!formDiv.find(selector).hasClass('hideResource')){
-
$(rsrc).removeClass('hideResource');
- }else{
-
$(rsrc).addClass('hideResource');
- }
- }
- },this);
- _.each(this.fields, function(obj, key){
- if(obj.$el.hasClass('hideResource')){
-
if($.inArray('required',obj.editor.validators) >= 0){
- this.defaultValidator[key] =
obj.editor.validators;
- obj.editor.validators=[];
- var label =
obj.$el.find('label').html();
-
obj.$el.find('label').html(label.replace('*', ''));
- }
- }else{
-
if(!_.isUndefined(this.defaultValidator[key])){
- obj.editor.validators =
this.defaultValidator[key];
-
if($.inArray('required',obj.editor.validators) >= 0){
- var label =
obj.$el.find('label').html();
-
obj.$el.find('label').html(label+"*");
- }
- }
- }
- }, this);
-// alert();
+ //to show error msg on below the field(only for policy
name)
+
this.fields.isEnabled.$el.find('.control-label').removeClass();
+
this.fields.name.$el.find('.help-inline').removeClass('help-inline').addClass('help-block
margin-left-5')
},
evAuditChange : function(form, fieldEditor){
XAUtil.checkDirtyFieldForToggle(fieldEditor.$el);
@@ -215,7 +175,48 @@ define(function(require){
});
},
-
+ renderParentChildHideShow : function(onChangeOfSameLevelType) {
+ var formDiv = this.$el.find('.policy-form');
+ if(!this.model.isNew() && !onChangeOfSameLevelType){
+ _.each(this.selectedResourceTypes,
function(val, sameLevelName) {
+
if(formDiv.find('.field-'+sameLevelName).length > 0){
+
formDiv.find('.field-'+sameLevelName).attr('data-name','field-'+val)
+ }
+ });
+ }
+ //hide form fields if it's parent is hidden
+ var resources = formDiv.find('.control-group');
+ _.each(resources, function(rsrc){
+ var parent = $(rsrc).attr('parent')
+ if( !_.isUndefined(parent) && !
_.isEmpty(parent)){
+ var selector =
"div[data-name='field-"+parent+"']"
+ if(formDiv.find(selector).length > 0 &&
!formDiv.find(selector).hasClass('hideResource')){
+
$(rsrc).removeClass('hideResource');
+ }else{
+
$(rsrc).addClass('hideResource');
+ }
+ }
+ },this);
+ //remove validation of fields if it's hidden
+ _.each(this.fields, function(obj, key){
+ if(obj.$el.hasClass('hideResource')){
+
if($.inArray('required',obj.editor.validators) >= 0){
+ this.defaultValidator[key] =
obj.editor.validators;
+ obj.editor.validators=[];
+ var label =
obj.$el.find('label').html();
+
obj.$el.find('label').html(label.replace('*', ''));
+ }
+ }else{
+
if(!_.isUndefined(this.defaultValidator[key])){
+ obj.editor.validators =
this.defaultValidator[key];
+
if($.inArray('required',obj.editor.validators) >= 0){
+ var label =
obj.$el.find('label').html();
+
obj.$el.find('label').html(label+"*");
+ }
+ }
+ }
+ }, this);
+ },
beforeSave : function(){
var that = this, resources = [];
@@ -327,9 +328,11 @@ define(function(require){
var url =
"service/plugins/services/lookupResource/"+that.rangerService.get('name');
var context ={
'userInput' :
extractLast( request.term ),
- 'resourceName' : null,
- 'resources' : {
null:null }
+ 'resourceName' :
that.pathFieldName,
+ 'resources' : {}
};
+ var val =
that.fields[that.pathFieldName].editor.getValue();
+
context.resources[that.pathFieldName] = _.isNull(val) || _.isEmpty(val) ? [] :
val.resource.split(",");
var p = $.ajax({
url : url,
type : "POST",
@@ -415,7 +418,7 @@ define(function(require){
return {
- containerCssClass :
options.containerCssClass,
+ containerCssClass : options.type,
closeOnSelect : true,
tags:true,
multiple: true,
@@ -448,14 +451,7 @@ define(function(require){
},
cache: false,
data: function (term, page) {
-// return
_.extend(that.getDataParams(type, term));
- var context ={
-
'userInput' : term,
-
'resourceName' : null,
-
'resources' : { null:null }
- };
- return
JSON.stringify(context);
-
+ return
that.getDataParams(term, options);
},
results: function (data, page)
{
var results = [];
@@ -498,23 +494,74 @@ define(function(require){
};
}
},
- evResourceTypeChange : function(form, fieldEditor){
- var that = this;
- var name = fieldEditor.$el.val();
- var sameLevel = _.findWhere(this.sameLevelType, {'name'
: fieldEditor.key});
-
form.$el.find('[data-editors="'+sameLevel.options+'"]').children().hide();
- this.fields[name].editor.$el.select2('val','');
- this.fields[name].editor.$el.show();
- form.$el.find('.'+name).show();
-
- _.each(sameLevel.options.split(','), function(nm){
- if(name != nm){
- var index =
this.fields.database.editor.validators.indexOf("required");
-
this.fields[nm].editor.validators.splice(index,1);
-
this.fields[nm].editor.$el.select2('val','');
+ getDataParams : function(term, options) {
+ var resources = {},resourceName = options.type;
+ var isParent = true, name = options.type, val =
null,isCurrentSameLevelField = true;
+ while(isParent){
+ var currentResource =
_.findWhere(this.rangerServiceDefModel.get('resources'), {'name': name });
+ //same level type
+
if(_.isUndefined(this.fields[currentResource.name])){
+ var sameLevelName =
'sameLevel'+currentResource.level;
+ name =
this.fields[sameLevelName].editor.$resourceType.val()
+ val =
this.fields[sameLevelName].getValue();
+ if(isCurrentSameLevelField){
+ resourceName = name;
+ }
+ }else{
+ val = this.fields[name].getValue();
}
- }, this);
+ resources[name] = _.isNull(val) ? [] :
val.resource.split(',');
+ if(!_.isEmpty(currentResource.parent)){
+ name = currentResource.parent;
+ }else{
+ isParent = false;
+ }
+ isCurrentSameLevelField = false;
+ }
+ var context ={
+ 'userInput' : term,
+ 'resourceName' : resourceName,
+ 'resources' : resources
+ };
+ return JSON.stringify(context);
+ },
+ formValidation : function(){
+ var groupSet = false,permSet = false,groupPermSet =
false;
+ var userSet=false, userPerm = false, userPermSet
=false,breakFlag =false;
+ console.log('validation called..');
+ this.formInputList.each(function(m){
+ if(_.isEmpty(m.attributes)) return;
+ if(m.has('groupName') || m.has('userName') ||
m.has('accesses') ){
+ if(! breakFlag){
+ groupSet = m.has('groupName') ?
true : false;
+ userSet = m.has('userName') ?
true : false;
+ permSet = m.has('accesses') ?
true : false;
+ if(groupSet && permSet){
+ groupPermSet = true;
+ userPermSet = false;
+ }else if(userSet && permSet){
+ userPermSet = true;
+ groupPermSet = false;
+ }else{
+ breakFlag=true;
+ }
+ }
+ }
+ });
+ var auditStatus =
this.fields.isAuditEnabled.editor.getValue();
+ var obj = { groupPermSet : groupPermSet ,
groupSet : groupSet,
+ userSet :
userSet, isUsers:userPermSet,
+ auditLoggin : auditStatus
+ };
+ if(groupSet || userSet){
+ obj['permSet'] = groupSet ? permSet : false;
+ obj['userPerm'] = userSet ? permSet : false;
+ }else{
+ obj['permSet'] = permSet;
+ obj['userPerm'] = userSet;
+ }
+ return obj;
},
});
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
----------------------------------------------------------------------
diff --git
a/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
b/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
index b4a255a..9d4fddc 100644
--- a/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
+++ b/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
@@ -27,6 +27,7 @@ define(function(require){
var localization = require('utils/XALangSupport');
var BackboneFormDataType =
require('models/BackboneFormDataType');
+ var ConfigurationList =
require('views/service/ConfigurationList')
require('backbone-forms');
require('backbone-forms.list');
@@ -58,6 +59,7 @@ define(function(require){
initialize: function(options) {
console.log("initialized a ServiceForm Form View");
_.extend(this, _.pick(options,
'rangerServiceDefModel'));
+ this.extraConfigColl = new Backbone.Collection();
this.setupFormForEditMode();
Backbone.Form.prototype.initialize.call(this, options);
@@ -100,10 +102,13 @@ define(function(require){
if(!this.model.isNew()){
_.each(this.model.get('configs'),function(value, name){
var configObj =
_.findWhere(this.rangerServiceDefModel.get('configs'),{'name' : name });
- if(configObj.type == 'bool'){
+ if(!_.isUndefined(configObj) &&
configObj.type == 'bool'){
this.model.set(name,
this.getStringFromBoolean(configObj, value))
}else{
this.model.set(name, value)
+ if(_.isUndefined(configObj)){
+
this.extraConfigColl.add(new Backbone.Model({'name' : name, 'value' : value}))
+ }
}
},this);
}
@@ -125,6 +130,10 @@ define(function(require){
},
/** all custom field rendering */
renderCustomFields: function(){
+ this.$('.extraServiceConfigs').html(new
ConfigurationList({
+ collection : this.extraConfigColl,
+ model : this.model,
+ }).render().el);
},
/** all post render plugin initialization */
@@ -150,6 +159,7 @@ define(function(require){
that.model.unset(obj.name);
}
});
+ this.extraConfigColl.each(function(obj){
config[obj.get('name')] = obj.get('value');})
this.model.set('configs',config);
//Set service type
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/webapp/styles/xa.css
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/styles/xa.css
b/security-admin/src/main/webapp/styles/xa.css
index 6c51ac0..57ce781 100644
--- a/security-admin/src/main/webapp/styles/xa.css
+++ b/security-admin/src/main/webapp/styles/xa.css
@@ -1684,8 +1684,8 @@ td.html-cell.renderable:last-child {
margin-bottom: 0 !important;
}
.policy-form .field-isEnabled{
-float: left;
-margin-bottom: 0 !important;
+margin-left: 413px;
+margin-bottom: 12px !important;
}
.policy-form .field-isEnabled .controls{
margin-left:30px;
@@ -1750,4 +1750,17 @@ margin-top: -29px;
}
.label-ranger {
background-color: #3C9C11;
+}
+.sameLevelDropdown{
+ margin-right: 31px;
+ margin-left: -130px;
+ width: 100px;
+ height: 29px;
+ font-family: Tahoma;
+ font-size: 14px;
+ border-radius: 10px;
+ border: 2px #cccccc solid;
+}
+.margin-left-5{
+ margin-left:5px;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/webapp/templates/policies/RangerPolicyForm_tmpl.html
----------------------------------------------------------------------
diff --git
a/security-admin/src/main/webapp/templates/policies/RangerPolicyForm_tmpl.html
b/security-admin/src/main/webapp/templates/policies/RangerPolicyForm_tmpl.html
index 270e53d..4a6533b 100644
---
a/security-admin/src/main/webapp/templates/policies/RangerPolicyForm_tmpl.html
+++
b/security-admin/src/main/webapp/templates/policies/RangerPolicyForm_tmpl.html
@@ -26,7 +26,6 @@
</div>
{{/if}}
<b data-fieldsets class="policy-form"></b>
-
</fieldset>
<fieldset>
<p class="formHeader">
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd69034/security-admin/src/main/webapp/templates/service/ServiceForm_tmpl.html
----------------------------------------------------------------------
diff --git
a/security-admin/src/main/webapp/templates/service/ServiceForm_tmpl.html
b/security-admin/src/main/webapp/templates/service/ServiceForm_tmpl.html
index e0f7f4d..75d621d 100644
--- a/security-admin/src/main/webapp/templates/service/ServiceForm_tmpl.html
+++ b/security-admin/src/main/webapp/templates/service/ServiceForm_tmpl.html
@@ -26,6 +26,7 @@
Config Properties :
</p>
<div class="serviceConfig" data-fields={{serviceConfig}}></div>
+ <div class="extraServiceConfigs" ></div>
</fieldset>
<div>
<div class="control-group field-username hdfs hive knox storm"
style="display: block;">