From 0c7bec64660fe0a0da87664fb2039a36b20cf104 Mon Sep 17 00:00:00 2001 From: "d.tseytlin" Date: Wed, 23 Mar 2016 22:14:19 +0300 Subject: [PATCH] Feature #53 Tracing UOA logs --- backend/app/controllers/uoaclasstypes.js | 23 ++++++++++++ backend/app/controllers/uoas.js | 35 +++++++++++++++++-- backend/app/controllers/uoataglinks.js | 16 +++++++++ backend/app/controllers/uoatags.js | 23 ++++++++++++ backend/app/controllers/uoatypes.js | 23 ++++++++++++ .../db_dump/patches/20160322-01-essences.sql | 1 + 6 files changed, 119 insertions(+), 2 deletions(-) diff --git a/backend/app/controllers/uoaclasstypes.js b/backend/app/controllers/uoaclasstypes.js index 24ed96531..78fdf44b2 100644 --- a/backend/app/controllers/uoaclasstypes.js +++ b/backend/app/controllers/uoaclasstypes.js @@ -1,6 +1,8 @@ var client = require('app/db_bootstrap'), _ = require('underscore'), config = require('config'), + BoLogger = require('app/bologger'), + bologger = new BoLogger(), UnitOfAnalysisClassType = require('app/models/uoaclasstypes'), AccessMatrix = require('app/models/access_matrices'), Translation = require('app/models/translations'), @@ -58,6 +60,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisClassType.insert(req.body).returning(UnitOfAnalysisClassType.id)); }).then(function (data) { + bologger.log({ + user: req.user.id, + action: 'insert', + object: 'UnitOfAnalysisClassType', + entity: _.first(data).id, + info: 'Add new uoa class type' + }); res.status(201).json(_.first(data)); }, function (err) { next(err); @@ -68,6 +77,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisClassType.update(req.body).where(UnitOfAnalysisClassType.id.equals(req.params.id))); }).then(function () { + bologger.log({ + user: req.user.id, + action: 'update', + object: 'UnitOfAnalysisClassType', + entity: req.params.id, + info: 'Update uoa class type' + }); res.status(202).end(); }, function (err) { next(err); @@ -78,6 +94,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisClassType.delete().where(UnitOfAnalysisClassType.id.equals(req.params.id))); }).then(function () { + bologger.log({ + user: req.user.id, + action: 'delete', + object: 'UnitOfAnalysisClassType', + entity: req.params.id, + info: 'Delete uoa class type' + }); res.status(204).end(); }, function (err) { next(err); diff --git a/backend/app/controllers/uoas.js b/backend/app/controllers/uoas.js index 5191118ad..53fae7a29 100644 --- a/backend/app/controllers/uoas.js +++ b/backend/app/controllers/uoas.js @@ -1,6 +1,8 @@ var client = require('app/db_bootstrap'), _ = require('underscore'), config = require('config'), + BoLogger = require('app/bologger'), + bologger = new BoLogger(), vl = require('validator'), UnitOfAnalysis = require('app/models/uoas'), UnitOfAnalysisType = require('app/models/uoatypes'), @@ -60,9 +62,16 @@ module.exports = { co(function* () { req.body.creatorId = req.user.id; req.body.ownerId = req.user.id; - req.body.createTime = new Date(); + req.body.created = new Date(); return yield thunkQuery(UnitOfAnalysis.insert(req.body).returning(UnitOfAnalysis.id)); }).then(function (data) { + bologger.log({ + user: req.user.id, + action: 'insert', + object: 'UnitOfAnalysis', + entity: _.first(data).id, + info: 'Add new uoa' + }); res.status(201).json(_.first(data)); }, function (err) { next(err); @@ -71,9 +80,17 @@ module.exports = { updateOne: function (req, res, next) { co(function* () { - delete req.body.createTime; + delete req.body.created; + req.body.updated = new Date(); return yield thunkQuery(UnitOfAnalysis.update(req.body).where(UnitOfAnalysis.id.equals(req.params.id))); }).then(function () { + bologger.log({ + user: req.user.id, + action: 'update', + object: 'UnitOfAnalysis', + entity: req.params.id, + info: 'Update uoa' + }); res.status(202).end(); }, function (err) { next(err); @@ -84,6 +101,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysis.delete().where(UnitOfAnalysis.id.equals(req.params.id))); }).then(function () { + bologger.log({ + user: req.user.id, + action: 'delete', + object: 'UnitOfAnalysis', + entity: req.params.id, + info: 'Delete uoa' + }); res.status(204).end(); }, function (err) { next(err); @@ -268,6 +292,13 @@ module.exports = { newUoa.id = created[0].id; newUoa.parse_status = 'Ok'; newUoa.messages.push('Added'); + bologger.log({ + user: req.user.id, + action: 'insert', + object: (!bologger.data.essence) ? 'UnitOfAnalysis' : null, + entity: created[0].id, + info: 'Add new uoa (bulk import)' + }); } } } diff --git a/backend/app/controllers/uoataglinks.js b/backend/app/controllers/uoataglinks.js index 97212d294..7a63e736b 100644 --- a/backend/app/controllers/uoataglinks.js +++ b/backend/app/controllers/uoataglinks.js @@ -1,6 +1,8 @@ var client = require('app/db_bootstrap'), _ = require('underscore'), config = require('config'), + BoLogger = require('app/bologger'), + bologger = new BoLogger(), UnitOfAnalysisTagLink = require('app/models/uoataglinks'), UnitOfAnalysisTag = require('app/models/uoatags'), UnitOfAnalysisClassType = require('app/models/uoaclasstypes'), @@ -99,6 +101,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisTagLink.insert(req.body).returning(UnitOfAnalysisTagLink.id)); }).then(function (data) { + bologger.log({ + user: req.user.id, + action: 'insert', + object: 'UnitOfAnalysisTagLink', + entity: _.first(data).id, + info: 'Add new uoa tag link' + }); res.status(201).json(_.first(data)); }, function (err) { next(err); @@ -109,6 +118,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisTagLink.delete().where(UnitOfAnalysisTagLink.id.equals(req.params.id))); }).then(function () { + bologger.log({ + user: req.user.id, + action: 'delete', + object: 'UnitOfAnalysisTagLink', + entity: req.params.id, + info: 'Delete uoa tag link' + }); res.status(204).end(); }, function (err) { next(err); diff --git a/backend/app/controllers/uoatags.js b/backend/app/controllers/uoatags.js index 5d679ece5..432385505 100644 --- a/backend/app/controllers/uoatags.js +++ b/backend/app/controllers/uoatags.js @@ -1,6 +1,8 @@ var client = require('app/db_bootstrap'), _ = require('underscore'), config = require('config'), + BoLogger = require('app/bologger'), + bologger = new BoLogger(), UnitOfAnalysisTag = require('app/models/uoatags'), AccessMatrix = require('app/models/access_matrices'), Translation = require('app/models/translations'), @@ -58,6 +60,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisTag.insert(req.body).returning(UnitOfAnalysisTag.id)); }).then(function (data) { + bologger.log({ + user: req.user.id, + action: 'insert', + object: 'UnitOfAnalysisTag', + entity: _.first(data).id, + info: 'Add new uoa tag' + }); res.status(201).json(_.first(data)); }, function (err) { next(err); @@ -68,6 +77,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisTag.update(req.body).where(UnitOfAnalysisTag.id.equals(req.params.id))); }).then(function () { + bologger.log({ + user: req.user.id, + action: 'update', + object: 'UnitOfAnalysisTag', + entity: req.params.id, + info: 'Update uoa tag' + }); res.status(202).end(); }, function (err) { next(err); @@ -78,6 +94,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisTag.delete().where(UnitOfAnalysisTag.id.equals(req.params.id))); }).then(function () { + bologger.log({ + user: req.user.id, + action: 'delete', + object: 'UnitOfAnalysisTag', + entity: req.params.id, + info: 'Delete uoa tag' + }); res.status(204).end(); }, function (err) { next(err); diff --git a/backend/app/controllers/uoatypes.js b/backend/app/controllers/uoatypes.js index 8377471f0..69f02c030 100644 --- a/backend/app/controllers/uoatypes.js +++ b/backend/app/controllers/uoatypes.js @@ -1,6 +1,8 @@ var client = require('app/db_bootstrap'), _ = require('underscore'), config = require('config'), + BoLogger = require('app/bologger'), + bologger = new BoLogger(), UnitOfAnalysisType = require('app/models/uoatypes'), AccessMatrix = require('app/models/access_matrices'), Translation = require('app/models/translations'), @@ -58,6 +60,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisType.insert(req.body).returning(UnitOfAnalysisType.id)); }).then(function (data) { + bologger.log({ + user: req.user.id, + action: 'insert', + object: 'UnitOfAnalysisType', + entity: _.first(data).id, + info: 'Add new uoa type' + }); res.status(201).json(_.first(data)); }, function (err) { next(err); @@ -68,6 +77,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisType.update(req.body).where(UnitOfAnalysisType.id.equals(req.params.id))); }).then(function () { + bologger.log({ + user: req.user.id, + action: 'update', + object: 'UnitOfAnalysisType', + entity: req.params.id, + info: 'Update uoa type' + }); res.status(202).end(); }, function (err) { next(err); @@ -78,6 +94,13 @@ module.exports = { co(function* () { return yield thunkQuery(UnitOfAnalysisType.delete().where(UnitOfAnalysisType.id.equals(req.params.id))); }).then(function () { + bologger.log({ + user: req.user.id, + action: 'delete', + object: 'UnitOfAnalysisType', + entity: req.params.id, + info: 'Delete uoa type' + }); res.status(204).end(); }, function (err) { next(err); diff --git a/backend/db_dump/patches/20160322-01-essences.sql b/backend/db_dump/patches/20160322-01-essences.sql index 85caf7747..8f68dee3d 100644 --- a/backend/db_dump/patches/20160322-01-essences.sql +++ b/backend/db_dump/patches/20160322-01-essences.sql @@ -13,6 +13,7 @@ WITH new_values ("tableName","name","fileName","nameField") as ( ('UnitOfAnalysisType', 'UnitOfAnalysisType', 'uoatypes', 'name'), ('UnitOfAnalysisClassType', 'UnitOfAnalysisClassType', 'uoaclasstypes', 'name'), ('UnitOfAnalysisTag', 'UnitOfAnalysisTag', 'uoatags', 'name'), +('UnitOfAnalysisTagLink', 'UnitOfAnalysisTagLink', 'uoataglinks', 'id'), ('Projects', 'projects', 'projects', 'codeName'), ('Discussions', 'Discussions', 'discussions', 'name'), ('Users', 'Users', 'users', 'email'),