Skip to content

Commit

Permalink
Merge pull request #227 from razee-io/add_user_log
Browse files Browse the repository at this point in the history
add user_log code from internal razeedash
  • Loading branch information
rmgraham committed Feb 18, 2020
2 parents c2e8537 + 463afe3 commit 598bb36
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion imports/api/deployables/channels/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions imports/api/deployables/subscriptions/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down
16 changes: 16 additions & 0 deletions imports/api/userLog/userLog.js
Original file line number Diff line number Diff line change
@@ -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} );
}
7 changes: 7 additions & 0 deletions imports/api/userLog/utils.js
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit 598bb36

Please sign in to comment.