diff --git a/imports/api/deployables/channels/methods.js b/imports/api/deployables/channels/methods.js index d1459727..a6ac5379 100644 --- a/imports/api/deployables/channels/methods.js +++ b/imports/api/deployables/channels/methods.js @@ -20,6 +20,8 @@ import { Channels } from './channels'; import { DeployableVersions } from './deployableVersions'; import { requireOrgAccess } from '/imports/api/org/utils.js'; import { updateDeployablesCountStat } from '../../stat/utils.js'; +import { logUserAction } from '../../userLog/utils.js'; + import uuid from 'uuid/v4'; // https://docs.meteor.com/api/check.html @@ -34,7 +36,9 @@ Meteor.methods({ check( orgId, String ); check( appId, String ); check( channelName, String ); - + + logUserAction(Meteor.userId(), 'updateChannel', `Update channel ${orgId}:${appId}:${channelName}`); + Channels.update( { 'org_id': orgId, @@ -54,6 +58,8 @@ Meteor.methods({ check( orgId, String ); check( channelName, NonEmptyString); + logUserAction(Meteor.userId(), 'addChannel', `Add channel ${orgId}:${channelName}`); + Channels.insert({ 'org_id': orgId, 'name': channelName, @@ -70,6 +76,8 @@ Meteor.methods({ check( channelName, String ); check( resourceId, String ); + logUserAction(Meteor.userId(), 'removeChannel', `Remove channel ${orgId}:${channelName}:${resourceId}`); + Channels.remove({ 'org_id': orgId, 'name': channelName }); DeployableVersions.remove({ 'org_id': orgId, 'channel_id': resourceId}); updateDeployablesCountStat(orgId); diff --git a/imports/api/deployables/subscriptions/methods.js b/imports/api/deployables/subscriptions/methods.js index 5dfb5f93..ecd0e132 100644 --- a/imports/api/deployables/subscriptions/methods.js +++ b/imports/api/deployables/subscriptions/methods.js @@ -20,6 +20,7 @@ import { Subscriptions } from './subscriptions.js'; import { requireOrgAccess } from '/imports/api/org/utils.js'; import uuid from 'uuid/v4'; import { pub } from '/imports/api/lib/pubsub'; +import { logUserAction } from '../../userLog/utils.js'; // https://docs.meteor.com/api/check.html const NonEmptyString = Match.Where((x) => { @@ -39,6 +40,8 @@ Meteor.methods({ check( version, String); check( versionName, String); + logUserAction(Meteor.userId(), 'updateSubscription', `Update subscription ${orgId}:${groupId}:${groupName}:${tags}:${resourceId}:${resourceName}:${version}:${versionName}`); + Subscriptions.update( { 'org_id': orgId, @@ -77,6 +80,8 @@ Meteor.methods({ check( version, String); check( versionName, String); + logUserAction(Meteor.userId(), 'addSubscription', `Add subscription ${orgId}:${groupName}:${tags}:${resourceId}:${resourceName}:${version}:${versionName}`); + Subscriptions.insert({ 'org_id': orgId, 'name': groupName, @@ -102,6 +107,8 @@ Meteor.methods({ check( orgId, String ); check( groupName, String ); + logUserAction(Meteor.userId(), 'removeSubscription', `Remove subscription ${orgId}:${groupName}`); + Subscriptions.remove({ 'org_id': orgId, 'name': groupName }); var msg = { diff --git a/imports/api/userLog/userLog.js b/imports/api/userLog/userLog.js new file mode 100644 index 00000000..ddd614ac --- /dev/null +++ b/imports/api/userLog/userLog.js @@ -0,0 +1,16 @@ +// Colletion to hold all user log entries + +import { Mongo } from 'meteor/mongo'; +import { Meteor } from 'meteor/meteor'; + +export const UserLog = new Mongo.Collection('user_log'); + +UserLog.deny({ + insert() { return true; }, + update() { return true; }, + remove() { return true; }, +}); + +if ( Meteor.isServer ) { + UserLog._ensureIndex( { 'userid': 1, 'action': 1} ); +} diff --git a/imports/api/userLog/utils.js b/imports/api/userLog/utils.js new file mode 100644 index 00000000..defb8d11 --- /dev/null +++ b/imports/api/userLog/utils.js @@ -0,0 +1,7 @@ +import { UserLog } from './userLog.js'; + +const logUserAction = function(userid, action, message) { + UserLog.insert({ userid: userid, action: action, message: message, created: new Date() }); +}; + +export { logUserAction }; \ No newline at end of file