RANGER-1889: List Users belonging to Group in Group tab.

Signed-off-by: pradeep <prad...@apache.org>


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

Branch: refs/heads/ranger-1.0
Commit: 0e1169a5bb3202caec32f23ae83ace2d879caa2c
Parents: 72ed7d3
Author: ni3galave <nitin.gal...@gmail.com>
Authored: Thu Mar 1 18:26:37 2018 +0530
Committer: pradeep <prad...@apache.org>
Committed: Wed Mar 7 11:30:18 2018 +0530

----------------------------------------------------------------------
 .../java/org/apache/ranger/biz/XUserMgr.java    |  17 ++-
 .../java/org/apache/ranger/rest/XUserREST.java  |   5 +-
 .../scripts/modules/globalize/message/en.js     |   4 +-
 .../scripts/views/users/UserTableLayout.js      | 117 ++++++++++++++++++-
 security-admin/src/main/webapp/styles/xa.css    |  28 +++++
 .../org/apache/ranger/biz/TestXUserMgr.java     |  18 ++-
 .../org/apache/ranger/rest/TestXUserREST.java   |  11 +-
 7 files changed, 187 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/0e1169a5/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 71298a4..6acef0c 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
@@ -816,12 +816,13 @@ public class XUserMgr extends XUserMgrBase {
                return ret;
        }
 
-       public VXUserList getXGroupUsers(Long xGroupId) {
-               SearchCriteria searchCriteria = new SearchCriteria();
-               searchCriteria.addParam("xGroupId", xGroupId);
+        public VXUserList getXGroupUsers(SearchCriteria searchCriteria) {
+
+                VXUserList vXUserList = new VXUserList();
+
                VXGroupUserList vXGroupUserList = xGroupUserService
                                .searchXGroupUsers(searchCriteria);
-               VXUserList vXUserList = new VXUserList();
+
 
                List<VXUser> vXUsers = new ArrayList<VXUser>();
                if (vXGroupUserList != null) {
@@ -836,8 +837,14 @@ public class XUserMgr extends XUserMgrBase {
 
                        }
                        vXUserList.setVXUsers(vXUsers);
+                        
vXUserList.setStartIndex(searchCriteria.getStartIndex());
+                        
vXUserList.setResultSize(vXGroupUserList.getList().size());
+                        
vXUserList.setTotalCount(vXGroupUserList.getTotalCount());
+                        vXUserList.setPageSize(searchCriteria.getMaxRows());
+                        vXUserList.setSortBy(vXGroupUserList.getSortBy());
+                        vXUserList.setSortType(vXGroupUserList.getSortType());
                } else {
-                       logger.debug("No users found for group id : " + 
xGroupId);
+                        logger.debug("No users found for group id : " + 
searchCriteria.getParamValue("xGroupId"));
                }
                return vXUserList;
        }

http://git-wip-us.apache.org/repos/asf/ranger/blob/0e1169a5/security-admin/src/main/java/org/apache/ranger/rest/XUserREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/XUserREST.java 
b/security-admin/src/main/java/org/apache/ranger/rest/XUserREST.java
index a07c243..9a5c823 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/XUserREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/XUserREST.java
@@ -770,7 +770,10 @@ public class XUserREST {
        @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + 
RangerAPIList.GET_X_GROUP_USERS + "\")")
        public VXUserList getXGroupUsers(@Context HttpServletRequest request,
                        @PathParam("groupId") Long id){
-               return xUserMgr.getXGroupUsers(id);
+                SearchCriteria searchCriteria = 
searchUtil.extractCommonCriterias(
+                                request, xGroupUserService.sortFields);
+                searchCriteria.addParam("xGroupId", id);
+                return xUserMgr.getXGroupUsers(searchCriteria);
        }
 
        @GET

http://git-wip-us.apache.org/repos/asf/ranger/blob/0e1169a5/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 8aaf705..c3b41c1 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
@@ -424,7 +424,9 @@ define(function(require) {
                 activationTimeDelayMsg       :'Policy activation time delayed 
by more than 1hr from last update time.',
                 pleaseSelectAccessTypeForTagMasking : 'Please select access 
type first to enable add masking options.',
                 addUserOrGroupForDelegateAdmin      : 'Please select 
user/group for the selected permission(s)',
-                policyLabelsinfo               : 'Enter label of policy'
+                policyLabelsinfo               : 'Enter label of policy',
+                noUserFoundText                        : 'No user associate 
with this group.',
+                showInitialHundredUser  : 'Initially search filter is applied 
for first hundred users. To get more users click on '
  
                        },
                        plcHldr : {

http://git-wip-us.apache.org/repos/asf/ranger/blob/0e1169a5/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 410a8ad..886b789 100644
--- a/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
+++ b/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
@@ -64,7 +64,8 @@ define(function(require){
                btnShowHide             : '[data-action="showHide"]',
                        visibilityDropdown              : 
'[data-id="visibilityDropdown"]',
                        addNewBtnDiv    : '[data-id="addNewBtnDiv"]',
-                       deleteUser: '[data-id="deleteUserGroup"]'
+                        deleteUser: '[data-id="deleteUserGroup"]',
+                       showUserList:'[data-js="showUserList"]',
        },
 
                /** ui events hash */
@@ -76,7 +77,8 @@ define(function(require){
                        events['click ' + this.ui.btnSave]  = 'onSave';
                        events['click ' + this.ui.visibilityDropdown +' li a']  
= 'onVisibilityChange';
                        events['click ' + this.ui.deleteUser] = 'onDeleteUser';
-                       return events;
+            events['click ' + this.ui.showUserList] = 'showUserList';
+            return events;
                },
 
        /**
@@ -468,7 +470,20 @@ define(function(require){
                                        }),
                                        editable:false,
                                        sortable:false
-                               }
+                },
+                member :{
+                    label : "Users",
+                    click : false,
+                    cell  : Backgrid.HtmlCell.extend({className: 
'cellWidth-1'}),
+                    drag  : false,
+                    editable  : false,
+                    formatter : _.extend({}, Backgrid.CellFormatter.prototype, 
{
+                        fromRaw : function (rawValue,model) {
+                            return ('<div align="center"><button 
class="userViewicon" title = "View Users" data-js="showUserList" data-name="' + 
model.get('name')
+                                + '" data-id="' + model.id + '"<font 
color="black"><i class="icon-group"> </i></font></button></div>');
+                        }
+                    }),
+                }
                        };
             if(!SessionMgr.isSystemAdmin()){
                 delete cols.select;
@@ -479,6 +494,100 @@ define(function(require){
                        return this.groupList.constructor.getTableCols(cols, 
this.groupList);
                },
 
+        showUserList :function(e){
+            XAUtil.blockUI();
+            var that = this , name , msg = "", content = "" , totalRecords, 
infoMsg = "";
+            var anchor = $(e.currentTarget);
+            this.groupId = anchor.attr('data-id');
+            name = anchor.attr('data-name');
+            this.grpUserList = new VXUserList();
+            this.grpUserList.url  = "service/xusers/"+ this.groupId +"/users";
+            this.grpUserList.setPageSize(100);
+            this.grpUserList.fetch({
+                async : true,
+                cache : false,
+                reset : true,
+            }).then(function(){
+                XAUtil.blockUI('unblock');
+                totalRecords = this.state.totalRecords;
+                var title =  "<h4>User's List: " + name + "</h4>";
+                    _.each(that.grpUserList.models , function(model){
+                        msg +='<span class="label label-info userLists 
span-margin" >'+ model.get('name') + '</span>';
+                    });
+                    var html = '<div class="row-fluid">\
+                                    <div class="span12"><input type="text" 
data-id="userInput" placeholder="Search Users" class= 
"users-list-search"></div>\
+                                </div>';
+                    if(totalRecords > 100){
+                        var showAllUserbtn = '<button class="btn btn-mini 
showMore" data-id="'+ that.groupId +'" data-id="showMore" title="Show All 
Users">Show All Users</button>'
+                        infoMsg = '<div class="alert alert-warning 
infoWidth">'+localization.tt('msg.showInitialHundredUser')+showAllUserbtn+'</div>'
+                    }
+                    if(_.isEmpty(msg)){
+                            content = localization.tt("msg.noUserFoundText");
+                    }else{
+                            content = infoMsg + html + '<div class="usernames 
clearfix">' + msg +'</div>';
+                    }
+                    var modal = new Backbone.BootstrapModal({
+                        animate : true,
+                        content        : content,
+                        title   : title,
+                        okText  : localization.tt("lbl.ok"),
+                        allowCancel : true,
+                    }).open();
+                    modal.$el.find('.cancel').hide();
+                    that.showAllUser(modal, totalRecords, msg);
+            })
+        },
+
+        showAllUser : function(modal, totalRecords, msg){
+            var that = this;
+            var filterUserLists = _.clone(modal.$content.find('span'));
+            modal.$content.find('.showMore').on("click" ,function(){
+                modal.$el.find('.modal-body').scrollTop(0);
+                modal.$el.find('.modal-body').addClass('pointer-event');
+                modal.$el.find('.modal-body').append('<div 
class="loaderForModal"></div>');
+                this.grpUserList = new VXUserList();
+                this.grpUserList.url  = "service/xusers/"+ that.groupId 
+"/users";
+                this.grpUserList.setPageSize(totalRecords);
+                this.grpUserList.fetch({
+                    async : true,
+                    cache : false,
+                    reset : true,
+                }).then(function(){
+                    var tag ="";
+                    modal.$content.find('.showMore').attr('disabled',true);
+                    modal.$el.find('.modal-body').removeClass('pointer-event');
+                    modal.$el.find('.loaderForModal').remove();
+                    _.each(this.models, function(m){
+                        tag +='<span class="label label-info userLists 
span-margin" >'+ m.get('name') + '</span>';
+                    });
+                    modal.$el.find(".usernames").empty();
+                    modal.$el.find(".usernames").append(tag);
+                    filterUserLists = _.clone(modal.$content.find('span'));
+                    msg = tag;
+                })
+            });
+            modal.$el.find('[data-id="userInput"]').on("keyup" ,function(){
+                var input, users;
+                input = $('input[data-id="userInput"]');
+                users = msg;
+                if(!_.isEmpty(input.val())){
+                    users = _.filter(filterUserLists, function(v) {
+                        
if(v.innerText.toLowerCase().indexOf(input.val().toLowerCase()) > -1){
+                            return v;
+                        }
+                    });
+                }
+                modal.$el.find(".usernames").empty();
+                if(_.isEmpty(users)){
+                    users = "No users found."
+                }
+                modal.$el.find(".usernames").append(users);
+                if(_.isEmpty(input.val())){
+                    that.showAllUser(modal, totalRecords, msg);
+                }
+            })
+        },
+
                onUserGroupDeleteSuccess: function(jsonUsers,collection){
                        _.each(jsonUsers.vXStrings,function(ob){
                                var model = _.find(collection.models, 
function(mo){
@@ -696,6 +805,8 @@ define(function(require){
                /** on close */
                onClose: function(){
                        XAUtil.allowNavigation();
+                       $('.fade.modal').hide();
+                       $('.modal-backdrop').hide();
                }
 
        });

http://git-wip-us.apache.org/repos/asf/ranger/blob/0e1169a5/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 5ccbbc2..d57d169 100644
--- a/security-admin/src/main/webapp/styles/xa.css
+++ b/security-admin/src/main/webapp/styles/xa.css
@@ -1836,6 +1836,9 @@ margin-top: -29px;
   font-weight: normal;
   text-shadow: none;
 }
+.tr-inactive td button.userViewicon i{
+  color: #BCBCBC;
+}
 td.select-row-cell {
   text-align: center;
 }
@@ -2256,3 +2259,28 @@ textarea:read-only{
        max-height: 200px;
        overflow-y: auto;
 }
+.userViewicon {
+    float: center;
+    line-height: 12px;
+}
+.users-list-search{
+    width : 500px;
+    padding : 10px;
+}
+.span-margin{
+    margin: 2px;
+}
+.loaderForModal{
+  background: url(../images/loading.gif) no-repeat center center 
rgba(0,0,0,0.3);
+    position: absolute;
+    top: 0;
+    bottom: 0;
+    left: 0;
+    right: 0;
+}
+.pointer-event{
+    pointer-events: none;
+}
+.infoWidth{
+  width: 475px;
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/0e1169a5/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java
----------------------------------------------------------------------
diff --git 
a/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java 
b/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java
index 0b71695..39c60a9 100644
--- a/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java
+++ b/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java
@@ -589,7 +589,9 @@ public class TestXUserMgr {
 
        @Test
        public void test23GetXGroupUsers() {
-               VXUserList dbVXUserList = xUserMgr.getXGroupUsers(userId);
+                SearchCriteria testSearchCriteria = createsearchCriteria();
+                testSearchCriteria.addParam("xGroupId", userId);
+                VXUserList dbVXUserList = 
xUserMgr.getXGroupUsers(testSearchCriteria);
                VXGroup vXGroup = new VXGroup();
                vXGroup.setId(userId);
                vXGroup.setDescription("group test");
@@ -1659,4 +1661,18 @@ public class TestXUserMgr {
                                .getLoginId());
                Assert.assertNotNull(vXStringList);
        }
+
+        private SearchCriteria createsearchCriteria(){
+                SearchCriteria testsearchCriteria = new SearchCriteria();
+                testsearchCriteria.setStartIndex(0);
+                testsearchCriteria.setMaxRows(Integer.MAX_VALUE);
+                testsearchCriteria.setSortBy("id");
+                testsearchCriteria.setSortType("asc");
+                testsearchCriteria.setGetCount(true);
+                testsearchCriteria.setOwnerId(null);
+                testsearchCriteria.setGetChildren(false);
+                testsearchCriteria.setDistinct(false);
+
+                return testsearchCriteria;
+        }
 }

http://git-wip-us.apache.org/repos/asf/ranger/blob/0e1169a5/security-admin/src/test/java/org/apache/ranger/rest/TestXUserREST.java
----------------------------------------------------------------------
diff --git 
a/security-admin/src/test/java/org/apache/ranger/rest/TestXUserREST.java 
b/security-admin/src/test/java/org/apache/ranger/rest/TestXUserREST.java
index 1bf3099..529fd5b 100644
--- a/security-admin/src/test/java/org/apache/ranger/rest/TestXUserREST.java
+++ b/security-admin/src/test/java/org/apache/ranger/rest/TestXUserREST.java
@@ -105,11 +105,13 @@ import org.apache.ranger.db.XXUserDao;
 import org.apache.ranger.entity.XXPolicy;
 import org.apache.ranger.entity.XXUser;
 import org.apache.ranger.db.XXAuditMapDao;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+
 import javax.servlet.http.HttpServletRequest;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -1259,10 +1261,15 @@ public class TestXUserREST {
                
assertEquals(groupList.getResultSize(),retVxGroupList.getResultSize());
                Mockito.verify(xUserMgr).getXUserGroups(id);
        }
+        @SuppressWarnings("unchecked")
        @Test
        public void test73getXGroupUsers() {
                
                HttpServletRequest request = 
Mockito.mock(HttpServletRequest.class);
+                SearchCriteria testSearchCriteria=createsearchCriteria();
+                testSearchCriteria.addParam("xGroupId", id);
+
+                
Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest)Mockito.any()
 ,(List<SortField>)Mockito.any())).thenReturn(testSearchCriteria);
                
                VXUser testVXUser=createVXUser();
                VXUserList testVXUserList= new VXUserList();
@@ -1271,13 +1278,13 @@ public class TestXUserREST {
                testVXUserList.setVXUsers(testVXUsers);
                testVXUserList.setStartIndex(1);
                testVXUserList.setTotalCount(1);
-               
Mockito.when(xUserMgr.getXGroupUsers(id)).thenReturn(testVXUserList);
+                
Mockito.when(xUserMgr.getXGroupUsers(testSearchCriteria)).thenReturn(testVXUserList);
                VXUserList retVxGroupList= xUserRest.getXGroupUsers(request,id);
                
                assertNotNull(retVxGroupList);
                
assertEquals(testVXUserList.getTotalCount(),retVxGroupList.getTotalCount());
                
assertEquals(testVXUserList.getStartIndex(),retVxGroupList.getStartIndex());
-               Mockito.verify(xUserMgr).getXGroupUsers(id);
+                Mockito.verify(xUserMgr).getXGroupUsers(testSearchCriteria);
        }
        @SuppressWarnings("unchecked")
        @Test

Reply via email to