You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ni...@apache.org on 2021/08/27 10:35:40 UTC

[ranger] branch ranger-2.2 updated: RANGER-3293 : Show user source details on user tab in ranger UI.

This is an automated email from the ASF dual-hosted git repository.

ni3galave pushed a commit to branch ranger-2.2
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/ranger-2.2 by this push:
     new 79f21e1  RANGER-3293 : Show user source details on user tab in ranger UI.
79f21e1 is described below

commit 79f21e1de687e5bbf7b24f2695033c7f0825775f
Author: Nitin Galave <ni...@apache.org>
AuthorDate: Wed Aug 18 17:54:33 2021 +0530

    RANGER-3293 : Show user source details on user tab in ranger UI.
---
 .../src/main/webapp/scripts/utils/XAViewUtils.js   |   9 ++
 .../main/webapp/scripts/views/users/GroupForm.js   |  10 ++
 .../main/webapp/scripts/views/users/UserForm.js    |  34 +++++--
 .../webapp/scripts/views/users/UserTableLayout.js  | 113 +++++++++++++++++++--
 .../webapp/templates/users/GroupForm_tmpl.html     |  25 +++++
 .../main/webapp/templates/users/UserForm_tmpl.html |  29 ++++++
 6 files changed, 201 insertions(+), 19 deletions(-)

diff --git a/security-admin/src/main/webapp/scripts/utils/XAViewUtils.js b/security-admin/src/main/webapp/scripts/utils/XAViewUtils.js
index e9edc9a..d73a2df 100644
--- a/security-admin/src/main/webapp/scripts/utils/XAViewUtils.js
+++ b/security-admin/src/main/webapp/scripts/utils/XAViewUtils.js
@@ -130,6 +130,15 @@ define(function(require) {
         }).open();
         modal.$el.find('.cancel').hide();
     };
+
+    XAViewUtil.syncUsersGroupsDetails = function(self){
+        var syncData = [];
+        var syncDetails = JSON.parse(self.model.get('otherAttributes'));
+        _.mapObject(syncDetails, function(value, key) {
+                syncData.push({'label': key, 'value': value});
+        })
+        return syncData;
+    }
 	
 	return XAViewUtil;
 
diff --git a/security-admin/src/main/webapp/scripts/views/users/GroupForm.js b/security-admin/src/main/webapp/scripts/views/users/GroupForm.js
index 0c6ef5b..034d3ed 100644
--- a/security-admin/src/main/webapp/scripts/views/users/GroupForm.js
+++ b/security-admin/src/main/webapp/scripts/views/users/GroupForm.js
@@ -23,6 +23,7 @@ define(function(require){
 
 	var Backbone		= require('backbone');
 	var XAEnums			= require('utils/XAEnums');
+	var XAViewUtils		= require('utils/XAViewUtils');
 	
 	require('backbone-forms');
 	require('backbone-forms.templates');
@@ -31,6 +32,12 @@ define(function(require){
 	{
 		_viewName : 'GroupForm',
 
+				/**Form template**/
+
+		templateData : function(){
+			return {syncSourceInfo : this.syncData}
+		},
+
     	/**
 		* intialize a new GroupForm Form View 
 		* @constructs
@@ -39,6 +46,9 @@ define(function(require){
 			console.log("initialized a GroupForm Form View");
 			_.extend(this, _.pick(options,''));
     		Backbone.Form.prototype.initialize.call(this, options);
+			if (this.model && !_.isUndefined(this.model.get('otherAttributes'))) {
+				this.syncData = XAViewUtils.syncUsersGroupsDetails(this);
+			}
 
 			this.bindEvents();
 		},
diff --git a/security-admin/src/main/webapp/scripts/views/users/UserForm.js b/security-admin/src/main/webapp/scripts/views/users/UserForm.js
index d32fa49..586a1c0 100644
--- a/security-admin/src/main/webapp/scripts/views/users/UserForm.js
+++ b/security-admin/src/main/webapp/scripts/views/users/UserForm.js
@@ -29,6 +29,7 @@ define(function(require){
 	var XAEnums			= require('utils/XAEnums');
 	var XAUtils			= require('utils/XAUtils');
 	var AddGroup 		= require('views/common/AddGroup');
+	var XAViewUtils		= require('utils/XAViewUtils');
 
 	require('backbone-forms');
 	require('backbone-forms.templates');
@@ -37,17 +38,6 @@ define(function(require){
 	{
 		_viewName : 'UserForm',
 
-		/**
-		* intialize a new UserForm Form View
-		* @constructs
-		*/
-		initialize: function(options) {
-			console.log("initialized a UserForm Form View");
-			_.extend(this, _.pick(options,'groupList','showBasicFields'));
-    		Backbone.Form.prototype.initialize.call(this, options);
-
-			this.bindEvents();
-		},
 
 		/** all events binding here */
 		bindEvents : function(){
@@ -60,6 +50,26 @@ define(function(require){
     		});
 		},
 
+		/**Form template**/
+
+		templateData : function(){
+			return {syncSourceInfo : this.syncData}
+		},
+		/**
+		* intialize a new UserForm Form View
+		* @constructs
+		*/
+		initialize: function(options) {
+			console.log("initialized a UserForm Form View");
+			_.extend(this, _.pick(options,'groupList','showBasicFields'));
+			Backbone.Form.prototype.initialize.call(this, options);
+			if (this.model && !_.isUndefined(this.model.get('otherAttributes'))) {
+				this.syncData = XAViewUtils.syncUsersGroupsDetails(this);
+			}
+
+			this.bindEvents();
+		},
+
 	    /** fields for the form
 		*/
 		fields: ['name', 'description'],
@@ -208,6 +218,7 @@ define(function(require){
 
 				this.fields.password.$el.show();
 				this.fields.passwordConfirm.$el.show();
+				this.$el.children('fieldset').hide()
 			}
 			if(	(!this.model.isNew() && (this.showBasicFields))){
 				this.fields.password.$el.hide();
@@ -221,6 +232,7 @@ define(function(require){
 					var labelStr = this.fields.firstName.$el.find('label').html().replace('*','');
 					this.fields.firstName.$el.find('label').html(labelStr);
 				}
+				this.$el.children('fieldset').show()
 			}
 		},
 		removeElementFromArr : function(arr ,elem){
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 57d7a96..d443327 100755
--- a/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
+++ b/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
@@ -40,6 +40,7 @@ define(function(require){
         var VXRole			= require('models/VXRole');
 
 	var UsertablelayoutTmpl = require('hbs!tmpl/users/UserTableLayout_tmpl');
+	var XAViewUtils		= require('utils/XAViewUtils');
 
 	var UserTableLayout = Backbone.Marionette.Layout.extend(
 	/** @lends UserTableLayout */
@@ -76,7 +77,8 @@ define(function(require){
             deleteUser: '[data-id="deleteUserGroup"]',
             showUserList:'[data-js="showUserList"]',
             addNewRoles: '[data-id="addNewRoles"]',
-            hideShowVisibility: '[data-id="hideShowVisibility"]'
+            hideShowVisibility: '[data-id="hideShowVisibility"]',
+            syncDetailes : '[data-id="syncDetailes"]',
     	},
 
 		/** ui events hash */
@@ -89,6 +91,7 @@ define(function(require){
 			events['click ' + this.ui.visibilityDropdown+ ' a']  = 'onVisibilityChange';
 			events['click ' + this.ui.deleteUser] = 'onDeleteUser';
             events['click ' + this.ui.showUserList] = 'showUserList';
+            events['click '+this.ui.syncDetailes] = 'onSyncDetailes';
             return events;
 		},
 
@@ -442,6 +445,22 @@ define(function(require){
 					editable:false,
 					sortable:false,
 				},
+				syncSource : {
+					label	: localization.tt("lbl.syncSource"),
+					cell	: Backgrid.HtmlCell.extend({className: 'cellWidth-1'}),
+					formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
+						fromRaw: function (rawValue, model) {
+							if(!_.isUndefined(rawValue)){
+								return '<span class="badge badge-green">'+rawValue+'</span>';
+							}else
+								return '--';
+						}
+					}),
+					click : false,
+					drag : false,
+					editable:false,
+					sortable:false,
+				},
 				groupNameList : {
 					cell	: Backgrid.HtmlCell.extend({className: 'cellWidth-1'}),
 					label : localization.tt("lbl.groups"),
@@ -473,7 +492,22 @@ define(function(require){
 					}),
 					editable:false,
 					sortable:false
-				}
+				},
+				otherAttributes : {
+                    cell    : 'html',
+                    label : localization.tt("h.syncDetails"),
+                    editable:false,
+                    sortable:false,
+                    formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
+                        fromRaw: function (rawValue, model) {
+                            if (!_.isUndefined(rawValue)) {
+                                return('<button data-id="syncDetailes" data-for="users" title="Sync Details" id="'+ model.get('id') +'" ><i class="fa-fw fa fa-eye"> </i></button>');
+                            } else {
+                                return '<center> -- </center>'
+                            }
+                        }
+                    }),
+                },
 			};
                         if(!SessionMgr.isSystemAdmin()){
                             delete cols.select;
@@ -553,6 +587,22 @@ define(function(require){
 					editable:false,
 					sortable:false,
 				},
+				syncSource : {
+					label	: localization.tt("lbl.syncSource"),
+					cell	: Backgrid.HtmlCell.extend({className: 'cellWidth-1'}),
+					formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
+						fromRaw: function (rawValue, model) {
+							if(!_.isUndefined(rawValue)){
+								return '<span class="badge badge-green">'+rawValue+'</span>';
+							}else
+								return '--';
+						}
+					}),
+					click : false,
+					drag : false,
+					editable:false,
+					sortable:false,
+				},
 				isVisible : {
 					label	: localization.tt("lbl.visibility"),
 					cell	: Backgrid.HtmlCell.extend({className: 'cellWidth-1'}),
@@ -585,8 +635,23 @@ define(function(require){
                                 + '" data-id="' + model.id + '"<font color="black"><i class="fa-fw fa fa-group"> </i></font></button></div>');
                         }
                     }),
-                }
-			};
+                },
+                otherAttributes : {
+                    cell    : 'html',
+                    label : localization.tt("h.syncDetails"),
+                    editable:false,
+                    sortable:false,
+                    formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
+                        fromRaw: function (rawValue, model) {
+                            if (!_.isUndefined(rawValue)) {
+                                return('<button data-id="syncDetailes" data-for="groups" title="Sync Details" id="'+ model.get('id') +'" ><i class="fa-fw fa fa-eye"> </i></button>');
+                            } else {
+                                return '<center> -- </center>'
+                            }
+                        }
+                    }),
+                },
+            };
             if(!SessionMgr.isSystemAdmin()){
                 delete cols.select;
             }
@@ -984,7 +1049,7 @@ define(function(require){
 			if(this.showUsers){
 				placeholder = localization.tt('h.searchForYourUser');	
 				coll = this.collection;
-				searchOpt = ['User Name','Email Address','Visibility', 'Role','User Source','User Status'];//,'Start Date','End Date','Today'];
+				searchOpt = ['User Name','Email Address','Visibility', 'Role','User Source','User Status', 'Sync Source'];//,'Start Date','End Date','Today'];
 				var userRoleList = _.map(XAEnums.UserRoles,function(obj,key){return {label:obj.label,value:key};});
                 serverAttrName  = [{text : "User Name", label :"name", urlLabel : "userName"},
                                     {text : "Email Address", label :"emailAddress", urlLabel : "emailAddress"},
@@ -992,15 +1057,16 @@ define(function(require){
                                     {text : "Visibility", label :"isVisible", 'multiple' : true, 'optionsArr' : XAUtil.enumToSelectLabelValuePairs(XAEnums.VisibilityStatus), urlLabel : "visibility"},
                                     {text : "User Source", label :"userSource", 'multiple' : true, 'optionsArr' : XAUtil.enumToSelectLabelValuePairs(XAEnums.UserTypes), urlLabel : "userSource"},
                                     {text : "User Status", label :"status", 'multiple' : true, 'optionsArr' : XAUtil.enumToSelectLabelValuePairs(XAEnums.ActiveStatus), urlLabel : "userStatus"},
+                                    {text : "Sync Source", label :"syncSource", urlLabel : "syncSource"}
                                 ];
             } else if(this.showGroups){
 				placeholder = localization.tt('h.searchForYourGroup');
 				coll = this.groupList;
-				searchOpt = ['Group Name','Group Source', 'Visibility'];//,'Start Date','End Date','Today'];
+				searchOpt = ['Group Name','Group Source', 'Visibility', 'Sync Source'];//,'Start Date','End Date','Today'];
                 serverAttrName  = [{text : "Group Name", label :"name", urlLabel : "groupName"},
                                     {text : "Visibility", label :"isVisible", 'multiple' : true, 'optionsArr' : XAUtil.enumToSelectLabelValuePairs(XAEnums.VisibilityStatus), urlLabel : "visibility"},
-                                    {text : "Group Source", label :"groupSource", 'multiple' : true, 'optionsArr' : XAUtil.enumToSelectLabelValuePairs(XAEnums.GroupTypes), urlLabel : "groupSource"}
-                                ];
+                                    {text : "Group Source", label :"groupSource", 'multiple' : true, 'optionsArr' : XAUtil.enumToSelectLabelValuePairs(XAEnums.GroupTypes), urlLabel : "groupSource"},
+                                    {text : "Sync Source", label :"syncSource", urlLabel : "syncSource"}];
             } else{
                 placeholder = localization.tt('h.searchForYourRole');
                 coll = this.roleList;
@@ -1047,6 +1113,9 @@ define(function(require){
 //										callback(XAUtil.hackForVSLabelValuePairs(XAEnums.ActiveStatus));
 										callback(that.getActiveStatusNVList());
 										break;
+									case 'Sync Source':
+										callback( _.map(XAEnums.UserSyncSource, function(obj){ return obj.label; }) );
+										break;
 									/*case 'Start Date' :
 										setTimeout(function () { XAUtil.displayDatepicker(that.ui.visualSearch, callback); }, 0);
 										break;
@@ -1092,6 +1161,34 @@ define(function(require){
 				this.ui.addNewBtnDiv.children().hide()
 			}
 		},
+        onSyncDetailes : function(e){
+            var that = this;
+            if (e.currentTarget.dataset.for =="users") {
+                var syncData = this.collection.models.find(function(m){return m.id == e.currentTarget.id});
+            } else {
+                var syncData = this.groupList.models.find(function(m){return m.id == e.currentTarget.id});
+            }
+            var SyncSourceView = Backbone.Marionette.ItemView.extend({
+                template : require('hbs!tmpl/reports/UserSyncInfo_tmpl'),
+                templateHelpers:function(){
+                   return {'syncSourceInfo' : XAViewUtils.syncUsersGroupsDetails(this)};
+                },
+                initialize: function(){
+                },
+                onRender: function(){}
+            });
+            var modal = new Backbone.BootstrapModal({
+                animate : true,
+                content     : new SyncSourceView({model : syncData}),
+                title: localization.tt("h.syncDetails"),
+                okText :localization.tt("lbl.ok"),
+                allowCancel : true,
+                escape : true,
+                focusOk : false
+            }).open();
+            modal.$el.find('.cancel').hide();
+        },
+
 		/** all post render plugin initialization */
 		initializePlugins: function(){
 		},
diff --git a/security-admin/src/main/webapp/templates/users/GroupForm_tmpl.html b/security-admin/src/main/webapp/templates/users/GroupForm_tmpl.html
index a47f040..f1dadad 100644
--- a/security-admin/src/main/webapp/templates/users/GroupForm_tmpl.html
+++ b/security-admin/src/main/webapp/templates/users/GroupForm_tmpl.html
@@ -17,4 +17,29 @@
 <form class="form-horizontal">
     <div class="" data-fields="name"></div>
     <div class="" data-fields="description"></div>
+    <fieldset>
+        <p class="wrap-header bold formHeader">Sync Details : </p>
+        <div class="wrap position-relative">
+            <table class="table table-bordered table-condensed backgrid">
+                <thead>
+                    <tr>
+                        <th class="renderable loginId">Name</th>
+                        <th class="renderable loginId">Value</th>
+                    </tr>
+                </thead>
+                <tbody>
+                    {{#if syncSourceInfo}}
+                        {{#each syncSourceInfo}}
+                            <tr>
+                                <td class="string-cell renderable" >{{tt label}}</td>
+                                <td class="string-cell renderable white-space-normal" title={{value}} >{{value}}</td>
+                            </tr>
+                        {{/each}}
+                    {{else}}
+                        <tr><td class="emptySet text-muted" colspan="2"><center>No Sync Details Found</center></td></tr>
+                    {{/if}}
+                </tbody>
+            </table>
+        </div>
+    </fieldset>
 </form>
\ No newline at end of file
diff --git a/security-admin/src/main/webapp/templates/users/UserForm_tmpl.html b/security-admin/src/main/webapp/templates/users/UserForm_tmpl.html
index d466c26..e85d880 100644
--- a/security-admin/src/main/webapp/templates/users/UserForm_tmpl.html
+++ b/security-admin/src/main/webapp/templates/users/UserForm_tmpl.html
@@ -23,4 +23,33 @@
     <div class="" data-fields="emailAddress"></div>
     <div class="" data-fields="userRoleList"></div>
     <div class="" data-customfields="groupIdList"></div>
+    <fieldset>
+      <p class="wrap-header bold formHeader">Sync Details : </p>
+      <div class="wrap position-relative">
+        <table class="table table-bordered table-condensed backgrid">
+          <thead>
+            <tr>
+              <th class="renderable loginId">Name</th>
+              <th class="renderable loginId">Value</th>
+            </tr>
+          </thead>
+          <tbody>
+            {{#if syncSourceInfo}}
+              {{#each syncSourceInfo}}
+                <tr>
+                  <td class="string-cell renderable" >{{tt label}}</td>
+                  <td class="string-cell renderable white-space-normal" title={{value}} >{{value}}</td>
+                </tr>
+              {{/each}}
+            {{else}}
+              <tr>
+                <td class="emptySet text-muted" colspan="2">
+                  <center>No Sync Details Found!!</center>
+                </td>
+              </tr>
+            {{/if}}
+          </tbody>
+        </table>
+      </div>
+    </fieldset>
 </form>
\ No newline at end of file