You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ve...@apache.org on 2017/05/13 04:04:02 UTC

ranger git commit: RANGER-1576 : Show attribute values to tags column in audit log

Repository: ranger
Updated Branches:
  refs/heads/master b7c425945 -> 55329a3e1


RANGER-1576 : Show attribute values to tags column in audit log

Signed-off-by: Velmurugan Periasamy <ve...@apache.org>


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

Branch: refs/heads/master
Commit: 55329a3e13580f014e282d319dc3168bb3e55507
Parents: b7c4259
Author: Gautam Borad <ga...@apache.org>
Authored: Fri May 12 17:24:49 2017 +0530
Committer: Velmurugan Periasamy <ve...@apache.org>
Committed: Sat May 13 00:02:46 2017 -0400

----------------------------------------------------------------------
 .../src/main/webapp/scripts/utils/XAUtils.js    |  51 ++++++-
 .../webapp/scripts/views/reports/AuditLayout.js | 141 ++++++++++++++-----
 security-admin/src/main/webapp/styles/xa.css    |  35 ++++-
 3 files changed, 182 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/55329a3e/security-admin/src/main/webapp/scripts/utils/XAUtils.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/utils/XAUtils.js b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
index 08aa95a..03e218d 100644
--- a/security-admin/src/main/webapp/scripts/utils/XAUtils.js
+++ b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
@@ -1289,10 +1289,51 @@ define(function(require) {
 		return !_.isUndefined(obj['resources']) && !_.isEmpty(obj['resources'])
 		 		&& !_.isNull(obj['resources']) ? false : true;
 	};
-        XAUtils.removeEmptySearchValue = function(arr) {
-                return  _.reject(arr,function(m){
-                        return (m.get('value')=="");
-                });
+    XAUtils.removeEmptySearchValue = function(arr) {
+            return  _.reject(arr,function(m){
+                    return (m.get('value')=="");
+            });
+    };
+        XAUtils.showAuditLogTags = function(rawValue, model) {
+                var showMoreLess = false, id = model.id, tagLabels = '';
+                var tagNames = _.pluck(rawValue, 'type');
+                if (!_.isUndefined(rawValue)) {
+                        var tagArr = _.map(rawValue, function(tag, i) {
+                                if(tag.attributes && !_.isEmpty(tag.attributes)){
+                                        tagLabels = '<a href="javascript:void(0)" data-name="tags" data-id="'+model.id+''+i+'" class="tagsColumn">'+tag.type+'</a>';
+                                }else{
+                                        tagLabels = tag.type;
+                                }
+                                tagLabels += (i+1 < rawValue.length) ? '&nbsp;,&nbsp;' : '';
+                                if (i >= 4){
+                                        return '<span class="float-left-margin-1" audit-log-id="'
+                                        + id + '" style="display:none;">' + tagLabels
+                                        + '</span>';
+                                }
+                                else{
+                                        if (i == 3 && rawValue.length > 4) {
+                                                showMoreLess = true;
+                                                return '<span class="float-left-margin-1" audit-log-id="'
+                                                                + id + '">' + tagLabels + '</span>';
+                                        } else{
+                                                return '<span class="float-left-margin-1" audit-log-id="'
+                                                + id + '">' + tagLabels + '</span>';
+                                        }
+                                }
+                        });
+                        if (showMoreLess) {
+                                tagArr.push('<span class="float-left-margin-1"><a href="javascript:void(0);" data-id="showMore" class="" audit-log-id="'
+                                                                + id
+                                                                + '"><code style=""> + More..</code></a></span><span class="float-left-margin-1"><a href="javascript:void(0);" data-id="showLess" class="" audit-log-id="'
+                                                                + id
+                                                                + '" style="display:none;"><code> - Less..</code></a></span>');
+                        }
+                        tagArr.unshift('<div data-id="tagDiv" class="popovertag">');
+                        tagArr.push('</div>');
+                        return tagArr.length ? tagArr.join(' ') : '--';
+                } else{
+                        return '--';
+                }
         };
 	return XAUtils;
-});
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ranger/blob/55329a3e/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 b98e2cc..40f56dd 100644
--- a/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
+++ b/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
@@ -84,8 +84,10 @@ define(function(require) {
 			tab 				: '.nav-tabs',
 			refreshTable		: '[data-id="refreshTable"]',
 			quickFilter			: '[data-id="quickFilter"]',
-                        visualSearch		: '.visual_search',
-                        'iconSearchInfo' : '[data-id="searchInfo"]',
+            visualSearch		: '.visual_search',
+            'iconSearchInfo' : '[data-id="searchInfo"]',
+            btnShowMore : '[data-id="showMore"]',
+                        btnShowLess : '[data-id="showLess"]',
 			
 		},
 
@@ -95,6 +97,8 @@ define(function(require) {
 			events['click ' + this.ui.refresh]         = 'onRefresh';
 			events['click ' + this.ui.searchBtn]  	   = 'onSearch';
 			events['click '+this.ui.tab+' a']		   = 'onTabChange';
+                        events['click ' + this.ui.btnShowMore]  = 'onShowMore';
+                        events['click ' + this.ui.btnShowLess]  = 'onShowLess';
 			return events;
 		},
 
@@ -111,15 +115,15 @@ define(function(require) {
 			var date = new Date().toString();
 			this.timezone = date.replace(/^.*GMT.*\(/, "").replace(/\)$/, "");
 			this.initializeServiceDefColl();
-                        if(_.isUndefined(App.vsHistory)){
-                                var startDateModel = new Backbone.Model({'category':'Start Date', value:Globalize.format(new Date(),"MM/dd/yyyy")});
-                                App.vsHistory = {'bigData':[startDateModel], 'admin':[], 'loginSession':[], 'plugin':[],'pluginStatus':[]};
-                        }
+            if(_.isUndefined(App.vsHistory)){
+                    var startDateModel = new Backbone.Model({'category':'Start Date', value:Globalize.format(new Date(),"MM/dd/yyyy")});
+                    App.vsHistory = {'bigData':[startDateModel], 'admin':[], 'loginSession':[], 'plugin':[],'pluginStatus':[]};
+            }
 		},
 
 		/** all events binding here */
 		bindEvents : function() {
-			//this.listenTo(this.collection, "change:foo", this.render, this);
+                        this.listenTo(this.accessAuditList, "sync",this.showTagsAttributes, this);
 		},
 
 		initializeServiceDefColl : function() {
@@ -142,6 +146,7 @@ define(function(require) {
 				this.addSearchForBigDataTab();
 				this.modifyTableForSubcolumns();
 			}
+                        this.showTagsAttributes();
 
 		},
 		modifyTableForSubcolumns : function(){
@@ -157,7 +162,7 @@ define(function(require) {
 					<th class="renderable aip" > </th>\
 					<th class="renderable aip" > </th>\
 					<th class="renderable ruser"></th>\
-					<th class="renderable cip"> </th>\
+                                        <th class="renderable ruser"></th>\
 				</tr>');
 		},
 		modifyPluginStatusTableSubcolumns : function(){
@@ -178,15 +183,16 @@ define(function(require) {
 			switch (tab) {
 				case "#bigData":
 					this.currentTab = '#bigData';
-                                        //Remove empty search values on tab changes for visual search.
-                                        App.vsHistory.bigData = XAUtils.removeEmptySearchValue(App.vsHistory.bigData);
+                    //Remove empty search values on tab changes for visual search.
+                    App.vsHistory.bigData = XAUtils.removeEmptySearchValue(App.vsHistory.bigData);
 					this.ui.visualSearch.show();
 					this.ui.visualSearch.parents('.well').show();
 					this.renderBigDataTable();
 					this.modifyTableForSubcolumns();
 					this.addSearchForBigDataTab();
-					this.listenTo(this.accessAuditList, "request", that.updateLastRefresh)
+                                        this.listenTo(this.accessAuditList, "request", that.updateLastRefresh);
                     this.ui.iconSearchInfo.show();
+                                        this.showTagsAttributes();
 					break;
 				case "#admin":
 					this.currentTab = '#admin';
@@ -830,6 +836,9 @@ define(function(require) {
 				},
 				onClick: function (e) {
 					var self = this;
+                                        if($(e.target).hasClass('tagsColumn') || $(e.target).closest('td').hasClass("tagsColumn")){
+                                                return;
+                                        }
 					var policyId = this.model.get('policyId');
 					if(policyId == -1){
 						return;
@@ -1005,36 +1014,47 @@ define(function(require) {
 						sortable:false,
 						editable:false
 					},
-					eventCount : {
-						label : 'Event Count',
-						cell: "string",
+                                        clusterName : {
+                                                label : localization.tt("lbl.clusterName"),
+                                                cell: 'html',
 						click : false,
 						drag : false,
 						sortable:false,
-						editable:false
+                                                editable:false,
+                                                formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
+                                                        fromRaw: function (rawValue, model) {
+                                                                rawValue = _.escape(rawValue);
+                                                                return '<span title="'+rawValue+'">'+rawValue+'</span>';
+                                                        }
+                                                }),
 					},
-					tags : {
-						label : 'Tags',
+                                        eventCount : {
+                                                label : 'Event Count',
 						cell: "string",
 						click : false,
 						drag : false,
 						sortable:false,
 						editable:false
 					},
-					clusterName : {
-						label : localization.tt("lbl.clusterName"),
-						cell: 'html',
+                                        tags : {
+                                                label : 'Tags',
+                                                cell: Backgrid.HtmlCell.extend({
+                                                        className : 'tagsColumn'
+                                                }),
 						click : false,
 						drag : false,
 						sortable:false,
 						editable:false,
 						formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
 							fromRaw: function (rawValue, model) {
-								rawValue = _.escape(rawValue);
-								return '<span title="'+rawValue+'">'+rawValue+'</span>';
+                                                                if(_.isUndefined(rawValue)){
+                                                                        return '<center>--</center>';
+                                                                }
+                                                                return XAUtils.showAuditLogTags(_.sortBy(JSON.parse(rawValue), 'type'), model);
 							}
 						}),
 					},
+
 			};
 			return this.accessAuditList.constructor.getTableCols(cols, this.accessAuditList);
 		},
@@ -1212,6 +1232,20 @@ define(function(require) {
 						editable:false,
 						sortable:false
 					},
+                                        clusterName : {
+                                                label : localization.tt("lbl.clusterName"),
+                                                cell: 'html',
+                                                click : false,
+                                                drag : false,
+                                                sortable:false,
+                                                editable:false,
+                                                formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
+                                                        fromRaw: function (rawValue, model) {
+                                                                rawValue = _.escape(rawValue);
+                                                                return '<span title="'+rawValue+'">'+rawValue+'</span>';
+                                                        }
+                                                }),
+                                        },
 					httpRetCode : {
 						cell : 'html',
 						label	: localization.tt('lbl.httpResponseCode'),
@@ -1231,20 +1265,7 @@ define(function(require) {
 						editable:false,
 						sortable:false
 					},
-					clusterName : {
-						label : localization.tt("lbl.clusterName"),
-						cell: 'html',
-						click : false,
-						drag : false,
-						sortable:false,
-						editable:false,
-						formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
-							fromRaw: function (rawValue, model) {
-								rawValue = _.escape(rawValue);
-								return '<span title="'+rawValue+'">'+rawValue+'</span>';
-							}
-						}),
-					},
+
 					
 			};
 			return this.policyExportAuditList.constructor.getTableCols(cols, this.policyExportAuditList);
@@ -1502,10 +1523,56 @@ define(function(require) {
 					delete collection.queryParams[obj.label];
 			});
 		},
-
 		updateLastRefresh : function(){
 			this.ui.lastUpdateTimeLabel.html(Globalize.format(new Date(),  "MM/dd/yyyy hh:mm:ss tt"));
 		},
+                showTagsAttributes : function(reset){
+                        var that = this;
+                        this.accessAuditList.each(function(model){
+                                if(!_.isUndefined(model.get('tags'))){
+                                        var tagData = JSON.parse(model.get('tags'));
+                                        _.each(_.sortBy(tagData, 'type'), function(e, i){
+                                                var $table = $('<div class="popover-heading" data-id="'+model.id+'">Attribute Details</div><table class="table table-bordered table-condensed tag-attr-table"  style="margin-left:-5px;"><tbody></tr><tr><td>Name</td><td>Value</td></tr></tbody></table>'),
+                                                $tbody = $table.find('tbody');
+                                                var $tr = '';
+                                                 _.each(e.attributes, function(val, key){
+                                                         $tr += ('<tr><td>'+_.escape(key)+'</td><td>'+ _.escape(val) +'</td></tr>');
+                                                });
+                                                $tbody.append($($tr));
+                                                that.$el.find('table a[data-name="tags"][data-id="'+model.id+''+i+'"]').popover({
+                                                        content: $table,
+                                                        html: true,
+                                                        trigger: 'click',
+                                                        placement: 'bottom',
+                                                        container: 'body',
+                                                }).on("click", function(e){
+                                                        e.stopPropagation();
+                                                        $('[data-name="tags"]').not(this).popover('hide');
+                                                        $('.popover').find(".popover-content").addClass("tag-attr-popover");
+
+                                                }).on("focusout", function(e){
+                                                        $(e.target).popover('hide');
+                                                });
+
+
+                                        });
+                                }
+                        });
+                },
+                onShowMore : function(e){
+                        var id = $(e.currentTarget).attr('audit-log-id');
+                        this.rTableList.$el.find('[audit-log-id="'+id+'"]').show();
+                        $('[data-id="showLess"][audit-log-id="'+id+'"]').show();
+                        $('[data-id="showMore"][audit-log-id="'+id+'"]').hide();
+                        $('[data-id="showMore"][audit-log-id="'+id+'"]').parents('div[data-id="tagDiv"]').addClass('set-height-groups');
+                },
+                onShowLess : function(e){
+                        var id = $(e.currentTarget).attr('audit-log-id');
+                        this.rTableList.$el.find('[audit-log-id="'+id+'"]').slice(4).hide();
+                        $('[data-id="showLess"][audit-log-id="'+id+'"]').hide();
+                        $('[data-id="showMore"][audit-log-id="'+id+'"]').show();
+                        $('[data-id="showMore"][audit-log-id="'+id+'"]').parents('div[data-id="tagDiv"]').removeClass('set-height-groups')
+                },
 		/** on close */
 		onClose : function() {
 			clearInterval(this.timerId);

http://git-wip-us.apache.org/repos/asf/ranger/blob/55329a3e/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 06ef1d0..c70c0bc 100644
--- a/security-admin/src/main/webapp/styles/xa.css
+++ b/security-admin/src/main/webapp/styles/xa.css
@@ -2147,9 +2147,38 @@ td.subgrid-custom-cell{
     text-transform: capitalize;   
 }
 .importbtn{
-        margin-right: 5px ;
-        margin-top:-2px;
+    margin-right: 5px ;
+    margin-top:-2px;
 }
 .text-decoration:hover{
-        text-decoration: none;
+    text-decoration: none;
+}
+.taginfo td, .taginfo th{
+  text-align: center;
+  vertical-align: middle;
+}
+.font-weight-100{
+        font-weight: 100
+}
+.float-left-margin-1{
+    float: left;
+    margin: 1px;
+}
+.tag-attr-popover{
+        padding: 5px;
+}
+.popover-heading {
+    font-weight: bold;
+    margin: 1px;
+}
+.tag-attr-table{
+   border-color: transparent;
+   border-top-color: #dddddd;
+}
+
+.tag-attr-popover .table{
+        margin-bottom:0;
 }
+.tag-attr-popover .table td:first-child{
+        border-left-color:transparent;
+}
\ No newline at end of file