Skip to content

Commit

Permalink
Merge pull request #5584 from Countly/SER-1922-add-audit-logs-to-hook…
Browse files Browse the repository at this point in the history
…-create-edit-delete-actions

[SER-1922] add audit logs to hook create edit delete actions
  • Loading branch information
ArtursKadikis authored Oct 2, 2024
2 parents 4f84d32 + 2d1836e commit 8129806
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
41 changes: 40 additions & 1 deletion plugins/hooks/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const Triggers = require('./parts/triggers/index.js');
const Effects = require('./parts/effects/index.js');
const asyncLib = require('async');
const EventEmitter = require('events');

const common = require('../../../api/utils/common.js');
const { validateRead, validateCreate, validateDelete, validateUpdate } = require('../../../api/utils/rights.js');
const plugins = require('../../pluginManager.js');
Expand Down Expand Up @@ -304,6 +303,21 @@ plugins.register("/i/hook/save", function(ob) {
{new: true},
function(err, result) {
if (!err) {
// Audit log: Hook updated
if (result && result.value) {
plugins.dispatch("/systemlogs", {
params: params,
action: "hook_updated",
data: {
updatedHookID: result.value._id,
updatedBy: params.member._id,
updatedHookName: result.value.name
}
});
}
else {
common.returnMessage(params, 500, "No result found");
}
common.returnOutput(params, result && result.value);
}
else {
Expand All @@ -318,6 +332,16 @@ plugins.register("/i/hook/save", function(ob) {
function(err, result) {
log.d("insert new hook:", err, result);
if (!err && result && result.insertedIds && result.insertedIds[0]) {
// Audit log: Hook created
plugins.dispatch("/systemlogs", {
params: params,
action: "hook_created",
data: {
createdHookID: hookConfig._id,
createdBy: params.member._id,
createdHookName: hookConfig.name
}
});
common.returnOutput(params, result.insertedIds[0]);
}
else {
Expand Down Expand Up @@ -514,6 +538,12 @@ plugins.register("/i/hook/status", function(ob) {
}
Promise.all(batch).then(function() {
log.d("hooks all updated.");
// Audit log: Hook status updated
plugins.dispatch("/systemlogs", {
params: params,
action: "hook_status_updated",
data: { updatedHooksCount: Object.keys(statusList).length, requestedBy: params.member._id }
});
common.returnOutput(params, true);
});
}, paramsInstance);
Expand Down Expand Up @@ -548,6 +578,15 @@ plugins.register("/i/hook/delete", function(ob) {
function(err, result) {
log.d(err, result, "delete an hook");
if (!err) {
// Audit log: Hook deleted
plugins.dispatch("/systemlogs", {
params: params,
action: "hook_deleted",
data: {
deletedHookID: hookID,
requestedBy: params.member._id
}
});
common.returnMessage(params, 200, "Deleted an hook");
}
}
Expand Down
7 changes: 6 additions & 1 deletion plugins/hooks/frontend/public/localization/hooks.properties
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,9 @@ hooks.actions-tips = Select the actions the hook will do upon being triggered. Y
hooks.application-tips = The app(s) for which you want to create a hook.
hooks.trigger-count-tips = Number of times the hook has been triggered.
hooks.trigger-action-tips = Identifies the trigger for the hook, and the actions that show the method through which data will be sent.
hooks.trigger-save-failed = Hook could not be saved.
hooks.trigger-save-failed = Hook could not be saved.

systemlogs.action.hook_created = Hook Created
systemlogs.action.hook_updated = Hook Updated
systemlogs.action.hook_status_updated = Hook Status Updated
systemlogs.action.hook_deleted = Hook Deleted

0 comments on commit 8129806

Please sign in to comment.