Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ module.exports = function (grunt) {
'./resources/javascripts/chain/bootstrap.min.js',
'./resources/javascripts/chain/modernizr.min.js',
'./resources/javascripts/chain/pace.min.js',
'./resources/bower_components/moment/moment.js',
'./resources/javascripts/chain/retina.min.js',
'./resources/javascripts/chain/select2.full.min.js',
'./resources/javascripts/chain/jquery.cookies.js',
'./resources/javascripts/chain/bootstrap-timepicker.min.js',
'./resources/javascripts/chain/wysihtml5-0.3.0.min.js',
'./resources/javascripts/chain/bootstrap-wysihtml5.js',
'./resources/bower_components/bootstrap-daterangepicker/daterangepicker.js',
'./app/assets/javascripts/build.min.js'
],
dest: './app/assets/javascripts/build.min.js'
Expand All @@ -59,6 +61,7 @@ module.exports = function (grunt) {
'./resources/stylesheets/chain/bootstrap-timepicker.min.css',
'./resources/stylesheets/chain/select2.min.css',
'./resources/stylesheets/chain/select2-bootstrap.css',
'./resources/bower_components/bootstrap-daterangepicker/daterangepicker.css',
'./resources/stylesheets/custom.css'
]
}
Expand Down
7,217 changes: 6,534 additions & 683 deletions app/assets/javascripts/build.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/stylesheets/build.min.css

Large diffs are not rendered by default.

88 changes: 83 additions & 5 deletions app/controllers/audit_logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
*/
var AdminBaseCrudController = require('./basecrud.js');

/**
* Async library
*/
const async = require('async');

/**
* AdminLogSystem controller
*/
Expand Down Expand Up @@ -40,16 +45,89 @@ class AdminLogAudit extends AdminBaseCrudController {
* @private
*/
this._viewsPath = 'log_audit';

/**
* Mongoose Searchable fields
*
* @type {string[]}
* @private
*/
this._modelSearchableFields = ['diff'];

/**
* Population fields
*
* @type {string}
* @private
*/
this._modelPopulateFields = 'userId';
}

load(readyCallback) {
super.load(function (err) {
if (err) return readyCallback(err);

// TODO: Load filters
readyCallback();
async.series([callback => {

super.load(callback);

}, callback => {

this.loadFiltersData(callback);

}], readyCallback);
}

/**
* Load left search filters data
*
* @param callback
*/
loadFiltersData(callback) {

async.series([callback => {

this.loadResources(callback);

}, callback => {

this.loadActions(callback);

}], callback);
}

/**
* Load resources types
*
* @param callback
*/
loadResources(callback) {

this.model.model.distinct('resource', (err, resources) => {
if (err) return callback(err);

this.data.filtersData = this.data.filtersData ? this.data.filtersData : {};

this.data.filtersData.resources = resources;

callback();
});
}

/**
* Load actions
*
* @param callback
*/
loadActions(callback) {

this.model.model.distinct('action', (err, actions) => {
if (err) return callback(err);

this.data.filtersData = this.data.filtersData ? this.data.filtersData : {};

this.data.filtersData.actions = actions;

}.bind(this));
callback();
});
}
}

Expand Down
12 changes: 11 additions & 1 deletion app/models/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class ConfigurationModel extends BaseModel {
* @private
*/
this._configuration = null;

/**
* To Enable Audit traces.
* 1. Call enableAudit()
* 2. Do not forget to add `last_modified_by` field to this schema.
*/
this.enableAudit();
}

/**
Expand All @@ -32,6 +39,8 @@ class ConfigurationModel extends BaseModel {
*/
defineSchema() {

var Types = this.mongoose.Schema.Types;

var schemaObject = {
project: {
name: {type: String}
Expand Down Expand Up @@ -64,7 +73,8 @@ class ConfigurationModel extends BaseModel {
searchBase: {type: String},
searchFilter: {type: String}
}
}
},
last_modified_by: {type: Types.ObjectId, ref: 'user'}
};

// Creating DBO Schema
Expand Down
76 changes: 68 additions & 8 deletions app/models/log_audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,60 @@ var BaseModel = require('./base');
*/
var merge = require('merge');

/**
* Lodash helper
*/
const _ = require('lodash');

/**
* Resources model
*/
class LogAuditModel extends BaseModel {
/**
* Model constructor
*/
constructor (listName) {
constructor(listName) {
// We must call super() in child class to have access to 'this' in a constructor
super(listName);

/**
* Response fields
*
* @type {string[]}
*/
this.responseFields = ['resource', 'resourceId', 'action', 'userId'];

/**
*
* @type {*[]}
*/
this.inFieldFilterFields = [{
name: 'inFieldResource',
field: 'resource'
}, {
name: 'inFieldAction',
field: 'action'
}, {
name: 'inFieldUserId',
field: 'userId'
}, {
name: 'inFieldResourceId',
field: 'resourceId'
}];

/**
*
* @type {Array}
*/
this.customFilters = ['customDateRange'];
}

/**
* Define Schema
*
* @override
*/
defineSchema () {
defineSchema() {

var Types = this.mongoose.Schema.Types;

Expand All @@ -39,7 +75,7 @@ class LogAuditModel extends BaseModel {
fieldsChanged: [{type: String, index: true}],
diff: {type: Types.Mixed}, // a JSON-stringified array of objects, stringified so it is searchable
message: {type: String},
userId: {type: Types.ObjectId, index: true},
userId: {type: Types.ObjectId, ref: 'user', index: true},
createdAt: {type: Date, 'default': Date.now, index: true}
};

Expand All @@ -64,7 +100,7 @@ class LogAuditModel extends BaseModel {
* @param {string} rawData.message - Text message.
* @param {Object} rawData.userId - User ID who made the change.
*/
writeRaw (rawData) {
writeRaw(rawData) {
this.insert(rawData);
}

Expand All @@ -80,7 +116,7 @@ class LogAuditModel extends BaseModel {
* @param {Object} [logData.resourceModel] - Affected resource model.
* @param {function} [callback] - Callback function.
*/
traceModelChange (logData, callback) {
traceModelChange(logData, callback) {

if (typeof callback === 'undefined') callback = function () {
};
Expand All @@ -95,7 +131,7 @@ class LogAuditModel extends BaseModel {

this.writeRaw(merge(rawData, {
action: 'created',
message: logData.item.name ? logData.item.name + ' was created.' : logData.resource + ' was created.'
message: typeof logData.item.name === 'string' ? logData.item.name + ' was created.' : logData.resource + ' was created.'
}));

return callback();
Expand Down Expand Up @@ -133,7 +169,7 @@ class LogAuditModel extends BaseModel {

this.writeRaw(merge(rawData, {
action: 'modified',
message: logData.oldItem.name ? logData.oldItem.name + ' was modified.' : logData.resource + ' was modified.',
message: typeof logData.oldItem.name === 'string' ? logData.oldItem.name + ' was modified.' : logData.resource + ' was modified.',
fieldsChanged: diff.map(diffEntry => diffEntry.name),
diff: JSON.stringify(diff)
}));
Expand All @@ -145,12 +181,36 @@ class LogAuditModel extends BaseModel {

this.writeRaw(merge(rawData, {
action: 'removed',
message: logData.item.name ? logData.item.name + ' was removed.' : logData.resource + ' was removed.'
message: typeof logData.item.name === 'string' ? logData.item.name + ' was removed.' : logData.resource + ' was removed.'
}));

return callback();
}
}

/**
* Build and add a conditions based on custom filters
*
* @param mongoFilters {{}}
* @param customFilters {[{}]}
*
* @return {{}}
*/
addCustomFilters(mongoFilters, customFilters) {

// [ { filterName: 'customDateRange', filterValue: '10/15/2016 - 10/29/2016' } ]
let customDateRange = _.find(customFilters, {filterName: 'customDateRange'});
if (customDateRange && customDateRange.filterValue) {

let from = customDateRange.filterValue.split(' - ')[0];
let to = customDateRange.filterValue.split(' - ')[1];

mongoFilters.$and.push({createdAt: {$gte: from}});
mongoFilters.$and.push({createdAt: {$lte: to}});
}

return mongoFilters;
}
}

/**
Expand Down
10 changes: 9 additions & 1 deletion app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class UserModel extends BaseModel {
* @private
*/
this._afterLDAPSignUp = null;

/**
* To Enable Audit traces.
* 1. Call enableAudit()
* 2. Do not forget to add `last_modified_by` field to this schema.
*/
this.enableAudit();
}

set afterLDAPSignUp(callback) {
Expand Down Expand Up @@ -84,7 +91,8 @@ class UserModel extends BaseModel {
"first": String
},
"roles": [String],
notifications: []
notifications: [],
last_modified_by: {type: Types.ObjectId, ref: 'user'}
};

/**
Expand Down
Loading