ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From me...@apache.org
Subject ranger git commit: RANGER-1405 : groups are not shown if exact user name is passed in search filter
Date Wed, 08 Mar 2017 04:31:17 GMT
Repository: ranger
Updated Branches:
  refs/heads/master 759a7b3e6 -> 6ad60b5d3


RANGER-1405 :  groups are not shown if exact user name is passed in search filter


Project: http://git-wip-us.apache.org/repos/asf/ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/6ad60b5d
Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/6ad60b5d
Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/6ad60b5d

Branch: refs/heads/master
Commit: 6ad60b5d3c29685b2867905cfe8386bc71c00fb7
Parents: 759a7b3
Author: Mehul Parikh <mehul@apache.org>
Authored: Wed Mar 8 10:00:47 2017 +0530
Committer: Mehul Parikh <mehul@apache.org>
Committed: Wed Mar 8 10:00:47 2017 +0530

----------------------------------------------------------------------
 .../ranger/services/knox/client/KnoxClient.java |   2 +-
 .../java/org/apache/ranger/biz/XUserMgr.java    | 100 ++++++++++++++++++-
 .../main/webapp/scripts/modules/XAOverrides.js  |   3 +-
 .../scripts/modules/globalize/message/en.js     |  10 +-
 .../webapp/scripts/views/reports/AuditLayout.js |  23 ++++-
 .../webapp/scripts/views/users/GroupCreate.js   |   2 +-
 .../webapp/scripts/views/users/UserCreate.js    |   2 +-
 .../scripts/views/users/UserTableLayout.js      |  77 ++++++++++----
 8 files changed, 190 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/6ad60b5d/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
----------------------------------------------------------------------
diff --git a/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
b/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
index f657795..4c389e3 100644
--- a/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
+++ b/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
@@ -220,7 +220,7 @@ public class KnoxClient {
 							JsonNode rootNode = objectMapper.readTree(jsonString);
 							JsonNode topologyNode = rootNode.findValue("topology");
 							if (topologyNode != null) {
-								JsonNode servicesNode = topologyNode.get("services");
+								JsonNode servicesNode = topologyNode.get("service");
 								if (servicesNode != null) {
 									Iterator<JsonNode> services = servicesNode.getElements();
 									while (services.hasNext()) {

http://git-wip-us.apache.org/repos/asf/ranger/blob/6ad60b5d/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java b/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
index 62cffa5..0df25b9 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
@@ -1472,7 +1472,78 @@ public class XUserMgr extends XUserMgrBase {
 				vXUserListSort = xUserService.searchXUsers(searchCriteria);
 				vXUserExactMatch = getXUserByUserName((String)searchCriteria.getParamList().get("name"));
 			}
+			int vXUserExactMatchwithSearchCriteria = 0;
 			if(vXUserExactMatch != null){
+				vXUserListSort = xUserService.searchXUsers(searchCriteria);
+				HashMap<String, Object> searchCriteriaParamList = searchCriteria.getParamList();
+				vXUserExactMatchwithSearchCriteria = 1;
+				for(String caseKey : searchCriteriaParamList.keySet()){
+					switch (caseKey.toLowerCase()) {
+						case "isvisible":
+							Integer isVisible = vXUserExactMatch.getIsVisible();
+							if(isVisible != null && !isVisible.equals(searchCriteriaParamList.get(caseKey))){
+								vXUserExactMatchwithSearchCriteria = -1;
+							}
+							break;
+						case "status":
+							Integer status = vXUserExactMatch.getStatus();
+							if(status != null && !status.equals(searchCriteriaParamList.get(caseKey))){
+								vXUserExactMatchwithSearchCriteria = -1;
+							}
+							break;
+						case "usersource":
+							Integer userSource = vXUserExactMatch.getUserSource();
+							if(userSource != null && !userSource.equals(searchCriteriaParamList.get(caseKey))){
+								vXUserExactMatchwithSearchCriteria = -1;
+							}
+							break;
+						case "emailaddress":
+							String email = vXUserExactMatch.getEmailAddress();
+							if(email != null && !email.equals(searchCriteriaParamList.get(caseKey))){
+								vXUserExactMatchwithSearchCriteria = -1;
+							}
+							break;
+						case "userrole":
+							if(vXUserExactMatch.getUserRoleList() != null && !vXUserExactMatch.getUserRoleList().contains(searchCriteriaParamList.get(caseKey))){
+								vXUserExactMatchwithSearchCriteria = -1;
+							}
+							break;
+						case "userrolelist":
+							@SuppressWarnings("unchecked")
+							Collection<String> userrolelist = (Collection<String>) searchCriteriaParamList.get(caseKey);
+							if(!CollectionUtils.isEmpty(userrolelist)){
+								for(String role:userrolelist){
+									if(vXUserExactMatch.getUserRoleList() != null && vXUserExactMatch.getUserRoleList().contains(role)){
+										vXUserExactMatchwithSearchCriteria = 1;
+										break;
+									}
+									else{
+										vXUserExactMatchwithSearchCriteria = -1;
+									}
+								}
+							}
+							break;
+						default:
+							logger.warn("XUserMgr.searchXUsers: unexpected searchCriteriaParam:" + caseKey);
+							break;
+					}
+					if(vXUserExactMatchwithSearchCriteria == -1){
+						break;
+					}
+				}
+			}
+			if(vXUserExactMatchwithSearchCriteria == 1){
+				VXGroupList groups = getXUserGroups(vXUserExactMatch.getId());
+				if(groups.getListSize() > 0){
+					Collection<String> groupNameList = new ArrayList<String>();
+					Collection<Long> groupIdList = new ArrayList<Long>();
+					for(VXGroup group:groups.getList()){
+						groupIdList.add(group.getId());
+						groupNameList.add(group.getName());
+					}
+					vXUserExactMatch.setGroupIdList(groupIdList);
+					vXUserExactMatch.setGroupNameList(groupNameList);
+				}
 				List<VXUser> vXUsers = new ArrayList<VXUser>();
 				if(searchCriteria.getStartIndex() == 0){
 					vXUsers.add(0,vXUserExactMatch);
@@ -1523,13 +1594,40 @@ public class XUserMgr extends XUserMgrBase {
 				vXGroupListSort = xGroupService.searchXGroups(searchCriteria);
 				vXGroupExactMatch = getGroupByGroupName((String)searchCriteria.getParamList().get("name"));
 			}
+			int vXGroupExactMatchwithSearchCriteria = 0;
 			if(vXGroupExactMatch != null){
+				HashMap<String, Object> searchCriteriaParamList = searchCriteria.getParamList();
+				vXGroupExactMatchwithSearchCriteria = 1;
+				for(String caseKey : searchCriteriaParamList.keySet()){
+					switch (caseKey.toLowerCase()) {
+						case "isvisible":
+							Integer isVisible = vXGroupExactMatch.getIsVisible();
+							if(isVisible != null && !isVisible.equals(searchCriteriaParamList.get(caseKey))){
+								vXGroupExactMatchwithSearchCriteria = -1;
+							}
+							break;
+						case "groupsource":
+							Integer groupsource = vXGroupExactMatch.getGroupSource();
+							if(groupsource != null && !groupsource.equals(searchCriteriaParamList.get(caseKey))){
+								vXGroupExactMatchwithSearchCriteria = -1;
+							}
+							break;
+						default:
+							logger.warn("XUserMgr.searchXGroups: unexpected searchCriteriaParam:" + caseKey);
+							break;
+					}
+					if(vXGroupExactMatchwithSearchCriteria == -1){
+						break;
+					}
+				}
+			}
+			if(vXGroupExactMatchwithSearchCriteria == 1){
 				List<VXGroup> vXGroups = new ArrayList<VXGroup>();
 				if(searchCriteria.getStartIndex() == 0){
 					vXGroups.add(0,vXGroupExactMatch);
 				}
 				for(VXGroup vXGroup:vXGroupListSort.getList()){
-					if(vXGroupExactMatch.getId()!=null && vXGroup!=null){
+					if(vXGroupExactMatch.getId() != null && vXGroup != null){
 						if(!vXGroupExactMatch.getId().equals(vXGroup.getId())){
 							vXGroups.add(vXGroup);
 						}

http://git-wip-us.apache.org/repos/asf/ranger/blob/6ad60b5d/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 94ab1c2..1e2b553 100644
--- a/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
+++ b/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
@@ -1291,7 +1291,8 @@
 		      var collection = this.collection;
 		      var selectedModels = this.selectedModels = {};
 		      this.listenTo(collection.fullCollection || collection,
-		                    "backgrid:selected", function (model, selected) {
+		                    "backgrid:selected", function (model, selected, clearSelectedModels)
{
+		    	if(clearSelectedModels) selectedModels = {}; 
 		        if (selected) selectedModels[model.id || model.cid] = 1;
 		        else {
 		          delete selectedModels[model.id || model.cid];

http://git-wip-us.apache.org/repos/asf/ranger/blob/6ad60b5d/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js b/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js
index 7a4b82c..1551d86 100644
--- a/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js
+++ b/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js
@@ -388,7 +388,11 @@ define(function(require) {
                 noServiceToExport       :'No service found to export policies.',
                 noServiceToImport       :'No service found to import policies.',
                 noPolicytoExport        :'No policies found to export!',
-                importingFiles          :'Importing policies from file is started...'
+                importingFiles          :'Importing policies from file is started...',
+                noDeleteUserRow           :'Please select user first to delete.',
+                noDeleteGroupRow        :'Please select Group first to delete.',
+                plsSelectUserToSetVisibility :' Please select user to set visibility or selected
user is already visible/hidden.',
+                plsSelectGroupToSetVisibility:' Please select group to set visibility or
selected group is already visible/hidden.',
  
 			},
 			plcHldr : {
@@ -415,8 +419,8 @@ define(function(require) {
 				passwordError          :'Password should be minimum 8 characters with min one alphabet
and one numeric.',
 				userNameValidationMsg  :'1. User name should be start with alphabet / numeric / underscore
/ non-us characters.<br> 2. Allowed special character ,._\-+/@= and space. <br>3.
Name length should be greater than one.',
 				groupNameValidationMsg :'1. Group name should be start with alphabet / numeric / underscore
/ non-us characters.<br> 2. Allowed special character ,._\-+/@= and space. <br>3.
Name length should be greater than one.',
-                                firstNameValidationMsg :'1. First name should be start with
alphabet / numeric / underscore / non-us characters.<br> 2. Allowed special character
._-@ and space. <br>3. Name length should be greater than one.',
-                                lastNameValidationMsg  :'1. Last name should be start with
alphabet / numeric / underscore / non-us characters.<br> 2. Allowed special character
._-@ and space. <br>3. Name length should be greater than one.',
+                firstNameValidationMsg :'1. First name should be start with alphabet / numeric
/ underscore / non-us characters.<br> 2. Allowed special character ._-@ and space. <br>3.
Name length should be greater than one.',
+                lastNameValidationMsg  :'1. Last name should be start with alphabet / numeric
/ underscore / non-us characters.<br> 2. Allowed special character ._-@ and space. <br>3.
Name length should be greater than one.',
 			},
 			serverMsg : {
 				

http://git-wip-us.apache.org/repos/asf/ranger/blob/6ad60b5d/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js b/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
index 6221149..8a0abb8 100644
--- a/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
+++ b/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
@@ -521,7 +521,14 @@ define(function(require) {
 				      callbacks :  { 
 				    	  valueMatches :function(facet, searchTerm, callback) {
 								switch (facet) {
-									case 'Audit Type':
+								    case 'Service Name':
+										var serviceList 	= new RangerServiceList();
+										serviceList.setPageSize(100);
+										serviceList.fetch().done(function(){
+											callback(serviceList.map(function(model){return model.get('name');}));
+										});
+										break;
+								    case 'Audit Type':
 										callback([]);
 										break;
 									case 'Start Date' :
@@ -561,6 +568,20 @@ define(function(require) {
 					placeholder    : localization.tt('msg.searchForPluginStatus'),
 					container         : this.ui.visualSearch,
 					query             : '',
+					callbacks :  { 
+				    	  valueMatches :function(facet, searchTerm, callback) {
+								switch (facet) {
+								    case 'Service Name':
+										var serviceList 	= new RangerServiceList();
+										serviceList.setPageSize(100);
+										serviceList.fetch().done(function(){
+											callback(serviceList.map(function(model){return model.get('name');}));
+										});
+										break;
+								}     
+			            	
+							}
+				      }
 			}
 			this.visualSearch = XAUtils.addVisualSearch(searchOpt, serverAttrName, this.pluginInfoList,
pluginAttr);
 		},

http://git-wip-us.apache.org/repos/asf/ranger/blob/6ad60b5d/security-admin/src/main/webapp/scripts/views/users/GroupCreate.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/users/GroupCreate.js b/security-admin/src/main/webapp/scripts/views/users/GroupCreate.js
index f915468..d16cbe5 100644
--- a/security-admin/src/main/webapp/scripts/views/users/GroupCreate.js
+++ b/security-admin/src/main/webapp/scripts/views/users/GroupCreate.js
@@ -129,7 +129,7 @@ define(function(require){
 					App.appRouter.navigate("#!/users/grouptab",{trigger: true});
 					
 					var groupList = new VXGroupList();
-					   
+					 _.extend(groupList.queryParams, XAUtil.getUserDataParams());   
 					groupList.fetch({
 						   cache:false
 					   }).done(function(){

http://git-wip-us.apache.org/repos/asf/ranger/blob/6ad60b5d/security-admin/src/main/webapp/scripts/views/users/UserCreate.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/users/UserCreate.js b/security-admin/src/main/webapp/scripts/views/users/UserCreate.js
index 46eff6d..99631f6 100644
--- a/security-admin/src/main/webapp/scripts/views/users/UserCreate.js
+++ b/security-admin/src/main/webapp/scripts/views/users/UserCreate.js
@@ -161,7 +161,7 @@ define(function(require){
 					App.appRouter.navigate("#!/users/usertab",{trigger: true});
 					
 					var userList = new VXUserList();
-					   
+					_.extend(userList.queryParams, XAUtil.getUserDataParams())
 					userList.fetch({
 					   cache:false
 					}).done(function(){

http://git-wip-us.apache.org/repos/asf/ranger/blob/6ad60b5d/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js b/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
index 4b1b036..8e465d7 100644
--- a/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
+++ b/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
@@ -99,6 +99,7 @@ define(function(require){
 		/** all events binding here */
 		bindEvents : function(){
 			var that = this;
+			
 			/*this.listenTo(this.model, "change:foo", this.modelChanged, this);*/
 			/*this.listenTo(communicator.vent,'someView:someEvent', this.someEventHandler, this)'*/
 		},
@@ -111,8 +112,20 @@ define(function(require){
 			} else {
 				this.renderUserTab();
 			}
+			this.bindEventToColl(this.collection);
+			this.bindEventToColl(this.groupList);
 			this.addVisualSearch();
 		},
+		bindEventToColl : function(coll){
+			if(_.isUndefined(coll)) return;
+			this.listenTo(coll, "sync reset", function(){
+				this.$el.find('table input[type="checkbox"]').prop('checked',false)
+				coll.each(function(model, key, value){
+					coll.trigger("backgrid:selected", model, false, true);
+					coll.deselect(model);
+				}, this);
+			}, this);
+		},
 		onTabChange : function(e){
 			var that = this;
 			this.chgFlags = [];
@@ -132,22 +145,35 @@ define(function(require){
 			var updateReq = {};
 			var collection = this.showUsers ? this.collection : this.groupList;
 
-			_.each(collection.selected, function(m){
-				if( m.get('isVisible') != status ){
-					m.set('isVisible', status);
+			collection.each(function(m){
+				if(m.selected && m.get('isVisible') != status){
+				  	m.set('isVisible', status);
 					m.toServer();
 					updateReq[m.get('id')] = m.get('isVisible');
 				}
 			});
-
+			if(_.isEmpty(updateReq)){
+				if(this.showUsers){
+					XAUtil.alertBoxWithTimeSet(localization.tt('msg.plsSelectUserToSetVisibility'));
+				}else{
+					XAUtil.alertBoxWithTimeSet(localization.tt('msg.plsSelectGroupToSetVisibility'));
+				}
+				
+				return;
+			}
 			var clearCache = function(coll){
-                _.each(Backbone.fetchCache._cache, function(url, val){
-                   var urlStr = coll.url;
-                   if((val.indexOf(urlStr) != -1)){
-                       Backbone.fetchCache.clearItem(val);
-                   }
-                });
-                coll.fetch({reset: true, cache : false});
+					_.each(Backbone.fetchCache._cache, function(url, val){
+		                   var urlStr = coll.url;
+		                   if((val.indexOf(urlStr) != -1)){
+		                       Backbone.fetchCache.clearItem(val);
+		                   }
+		                });
+					coll.fetch({reset: true, cache:false}).done(function(coll){
+	                	coll.each(function(model){
+	                		coll.trigger("backgrid:selected", model, false, true);
+	    					coll.deselect(model);
+	    				}, this);
+	                })
 			}
 			if(this.showUsers){
 				collection.setUsersVisibility(updateReq, {
@@ -174,11 +200,12 @@ define(function(require){
 						if(!_.isUndefined(resp) && !_.isUndefined(resp.responseJSON) && !_.isUndefined(resp.responseJSON.msgDesc)){
 							XAUtil.notifyError('Error', resp.responseJSON.msgDesc);
 						}else{
-							XAUtil.notifyError('Error', "Error occurred while updating user");
+							XAUtil.notifyError('Error', "Error occurred while updating group");
 						}
 						collection.trigger('error','',resp)
 					},
                 });
+
 			}
 		},
 		renderUserTab : function(){
@@ -227,7 +254,7 @@ define(function(require){
 			var that = this;
 			var tableRow = Backgrid.Row.extend({
 				render: function () {
-    				tableRow.__super__.render.apply(this, arguments);
+					tableRow.__super__.render.apply(this, arguments);
     				if(!this.model.get('isVisible')){
     					this.$el.addClass('tr-inactive');
     				}
@@ -359,6 +386,7 @@ define(function(require){
     				}
     				return this;
 				},
+				
 			});
 			this.rTableList.show(new XATableLayout({
 				columns: this.getGroupColumns(),
@@ -455,8 +483,10 @@ define(function(require){
 			var collection = that.showUsers ? that.collection : that.groupList;
 			var selArr = [];
 			var message = '';
-			_.each(collection.selected,function(obj){
-                                 selArr.push(obj.get('name'));
+			collection.each(function(obj){
+				if(obj.selected){
+	                selArr.push(obj.get('name'));
+	            }
             });
 			var  vXStrings = [];
 			var jsonUsers  = {};
@@ -469,9 +499,16 @@ define(function(require){
 			jsonUsers.vXStrings = vXStrings;
 
 			var total_selected = jsonUsers.vXStrings.length;
-
-			if(total_selected == 1) {
-                                message = 'Are you sure you want to delete '+(that.showUsers
? 'user':'group')+' \''+ _.escape( jsonUsers.vXStrings[0].value )+'\'?';
+			if(total_selected == 0){
+				if(that.showUsers){
+					XAUtil.alertBoxWithTimeSet(localization.tt('msg.noDeleteUserRow'));
+				}else{
+					XAUtil.alertBoxWithTimeSet(localization.tt('msg.noDeleteGroupRow'));
+				}
+				return;
+			}
+            if(total_selected == 1) {
+                message = 'Are you sure you want to delete '+(that.showUsers ? 'user':'group')+'
\''+ _.escape( jsonUsers.vXStrings[0].value )+'\'?';
 			}
 			else {
 				message = 'Are you sure you want to delete '+total_selected+' '+(that.showUsers ? 'users':'groups')+'?';
@@ -486,7 +523,7 @@ define(function(require){
 							model.deleteUsers(jsonUsers,{
 								success: function(response,options){
 									XAUtil.blockUI('unblock');
-									that.onUserGroupDeleteSuccess(jsonUsers,collection);
+									that.collection.getFirstPage({fetch:true});
 									XAUtil.notifySuccess('Success','User deleted successfully!');
 									that.collection.selected = {};
 								},
@@ -501,7 +538,7 @@ define(function(require){
 							model.deleteGroups(jsonUsers,{
 								success: function(response){
 									XAUtil.blockUI('unblock');
-									that.onUserGroupDeleteSuccess(jsonUsers,collection);
+									that.groupList.getFirstPage({fetch:true});
 									XAUtil.notifySuccess('Success','Group deleted successfully!');
 									that.groupList.selected  = {};
 								},


Mime
View raw message