fix issues in audit logs

This commit is contained in:
Westly Wright 2015-12-21 17:55:49 -07:00
parent ca39a5ed0b
commit d792e127c4
3 changed files with 72 additions and 46 deletions

View File

@ -1,11 +1,10 @@
import Ember from 'ember';
import Sortable from 'ui/mixins/sortable';
import { debouncedObserver } from 'ui/utils/debounce';
import C from 'ui/utils/constants';
export default Ember.Controller.extend(Sortable, {
application: Ember.inject.controller(),
queryParams: ['sortBy', 'sortOrder', 'limit', 'forceReload', 'depaginate'],
queryParams: ['sortBy', 'sortOrder', 'eventType', 'resourceType', 'resourceId', 'clientIp', 'authType'],
sortableContent: Ember.computed.alias('model.auditLog'),
resourceTypeAndId: null,
@ -21,6 +20,16 @@ export default Ember.Controller.extend(Sortable, {
changeSort: function(name) {
this._super(name);
},
search: function() {
this.setProperties({
eventType: this.get('filters.eventType'),
resourceType: this.get('filters.resourceType'),
resourceId: this.get('filters.resourceId'),
clientIp: this.get('filters.clientIp'),
authType: this.get('filters.authType'),
});
this.send('filterLogs');
},
showResponseObjects: function(request, response) {
this.get('application').setProperties({
showAuditLogResponses: true,
@ -44,6 +53,13 @@ export default Ember.Controller.extend(Sortable, {
resourceType: null,
runtime: null,
});
this.setProperties({
eventType: null,
resourceType: null,
resourceId: null,
clientIp: null,
authType: null,
});
this.setProperties({
sortBy: 'created',
sortOrder: 'desc',
@ -57,8 +73,11 @@ export default Ember.Controller.extend(Sortable, {
sortOrder: 'desc',
descending: true,
limit: 100,
forceReload: true,
depaginate: false,
eventType: null,
resourceType: null,
resourceId: null,
clientIp: null,
authType: null,
authTypes: null,
authTypeReadable: null,
filters: {
@ -69,6 +88,7 @@ export default Ember.Controller.extend(Sortable, {
created: null,
description: null,
eventType: null,
clientIp: null,
id: null,
kind: null,
resourceId: null,
@ -89,10 +109,6 @@ export default Ember.Controller.extend(Sortable, {
}.on('init'),
filtersHaveChanged: debouncedObserver('filters.accountId','filters.authType','filters.authenticatedAsAccountId','filters.authenticatedAsIdentityId','filters.created','filters.description','filters.eventType','filters.id','filters.kind','filters.resourceId','filters.resourceType','filters.runtime', function() {
this.send('filterLogs');
}, 500),
setSortOrderObserver: function() {
var out = 'asc';
@ -105,6 +121,14 @@ export default Ember.Controller.extend(Sortable, {
}.observes('descending'),
resourceIdReady: function() {
if (this.get('filters.resourceType')) {
return false;
} else {
return true;
}
}.property('filters.resourceType'),
showPagination: function() {
var pagination = this.get('model.auditLog.pagination');

View File

@ -9,9 +9,21 @@ export default Ember.Route.extend({
sortOrder: {
refreshModel: true
},
limit: {
eventType: {
refreshModel: true
},
resourceType: {
refreshModel: true
},
resourceId: {
refreshModel: true
},
clientIp: {
refreshModel: true
},
authType: {
refreshModel: true
}
},
runLaterId: null,
@ -21,8 +33,6 @@ export default Ember.Route.extend({
filterLogs: function() {
Ember.run.cancel(this.get('runLaterId'));
this.set('runLaterId', null);
this.refresh();
},
logsSorted: function() {
Ember.run.cancel(this.get('runLaterId'));
@ -54,18 +64,15 @@ export default Ember.Route.extend({
this.set('userHasPaged', false);
this.set('runLaterId', null);
this.set('runLaterId', null);
},
model: function(params) {
var filters;
if (this.controller) {
filters = this.controller.get('filters');
if (this.get('runLaterId')) {
Ember.run.cancel(this.get('runLaterId'));
this.set('runLaterId', null);
}
return this.store.find('auditLog', null, this.parseFilters(params, filters)).then((response) => {
return this.store.find('auditLog', null, this.parseFilters(params)).then((response) => {
var resourceTypes = this.get('store').all('schema').filterBy('links.collection').map((x) => { return x.get('_id'); });
@ -84,15 +91,15 @@ export default Ember.Route.extend({
},
scheduleLogUpdate: function() {
const intervalCount = 2000;
const intervalCount = 30000;
this.set('runLaterId',
Ember.run.later(() => {
var params = this.paramsFor('admin-tab.audit-logs');
var filters = this.controller.get('filters');
//var filters = this.controller.get('filters');
this.store.find('auditLog', null, this.parseFilters(params, filters)).then((response) => {
this.store.find('auditLog', null, this.parseFilters(params)).then((response) => {
// We can get into a state where the user paged but we have an unresolved promise from the previous
// run. If thats the case we dont want to replace the page with this unresolved promise.
@ -106,34 +113,28 @@ export default Ember.Route.extend({
}, intervalCount));
},
parseFilters: function(params, filters) {
var paramsOut = params;
paramsOut.include = 'account';
if (filters) {
Object.keys(filters).forEach((key) => {
/* do we have a non-null filter?*/
if (filters[key]) {
/*does the filter exist in the current params - if so add new filters to it*/
if (params.filter) {
paramsOut.filter[key] = filters[key];
parseFilters: function(params) {
var returnValue = {
filter: {
},
limit: 100,
depaginate: false,
forceReload: true
};
if (params) {
_.forEach(params, (item, key) => {
if (key !== 'sortBy' && key !== 'sortOrder' && key !== 'forceReload') {
if (item) {
returnValue.filter[key] = item;
} else {
/*it doesnt so create it*/
paramsOut.filter = {};
paramsOut.filter[key] = filters[key];
}
}
else {
/*did we remove the filter by hand?*/
if (!filters[key] && (paramsOut.filter && paramsOut.filter[key])) {
/*delete it*/
delete paramsOut.filter[key];
delete returnValue.filter[key];
}
} else {
returnValue[key] = item;
}
});
}
return paramsOut;
return returnValue;
},
});

View File

@ -10,6 +10,7 @@
{{input class="form-control input-sm r-mr5" value=filters.eventType placeholder="Event Type"}}
<div class="input-group r-mr5">
<span class="input-group-btn">
{{input class="form-control input-sm pull-right" value=filters.resourceId placeholder="Resource ID" disabled=resourceIdReady}}
<button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">{{if filters.resourceType filters.resourceType 'Resource Type:'}} <i class="icon icon-chevron-down"></i></button>
<ul class="dropdown-menu" role="menu">
<li role="presentation" class="dropdown-header">
@ -21,7 +22,6 @@
</li>
{{/each}}
</ul>
{{input class="form-control input-sm" value=filters.resourceId placeholder="Resource ID"}}
</span>
</div>
{{input class="form-control input-sm r-mr5" value=filters.clientIp placeholder="Request IP"}}
@ -38,7 +38,8 @@
{{/each}}
</ul>
</span>
<a class="btn btn-sm btn-primary r-ml5" {{action "clearAll"}} style="margin-right: 8px;"><i class="icon icon-close icon-sm"></i> Clear All</a>
<a class="btn btn-sm btn-danger r-ml5" {{action "clearAll"}}> Clear All</a>
<a class="btn btn-sm btn-primary r-ml5" {{action "search"}}> Search</a>
</div>
</div>
<table class="grid fixed table table-hover r-mb15">