Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

old hooks #5893

Open
wants to merge 32 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d6f6147
old hooks
ar2rsawseen Jan 8, 2025
c575fd6
Merge branch 'next' into next-hooks-test
ar2rsawseen Jan 8, 2025
ecb82c6
Merge branch 'next' into next-hooks-test
ar2rsawseen Jan 8, 2025
f6868c8
add template test id changes
ar2rsawseen Jan 8, 2025
61f7193
Added getting console logs
can-angun Jan 8, 2025
84b83ea
Added comment out to settings for test
can-angun Jan 8, 2025
49b5676
Added jobs full data control
can-angun Jan 8, 2025
be2bb94
Added failed case for test
can-angun Jan 9, 2025
799dc25
Empty-Commit
can-angun Jan 9, 2025
ca40878
Added wait for verify
can-angun Jan 9, 2025
6ff18ed
Removed skip from one case
can-angun Jan 9, 2025
db94b3e
Added comment out to jobs
can-angun Jan 9, 2025
464f583
Added check pace
can-angun Jan 9, 2025
30fb353
Added installLogsPrinter
can-angun Jan 9, 2025
4d07e2b
Added ref call
can-angun Jan 9, 2025
cb2e8cf
Removed skips from cases
can-angun Jan 9, 2025
78efe41
Added debug cypress log to out to workflow
can-angun Jan 9, 2025
103e9b1
Added win.console.log
can-angun Jan 9, 2025
21170bd
Removed comment out
can-angun Jan 9, 2025
e3d0c0d
Added logging settings
can-angun Jan 9, 2025
80b35c6
Update hooks.js
can-angun Jan 9, 2025
36030e6
Discard some changes
can-angun Jan 9, 2025
47b01fa
Merge branch 'next-hooks-test' of github.com:Countly/countly-server i…
can-angun Jan 9, 2025
7b98efe
Updated package files
can-angun Jan 9, 2025
23867ff
removed cypress-log-to-output
can-angun Jan 9, 2025
3556df8
Fixed linter error
can-angun Jan 9, 2025
1480aaa
Discard hook files
can-angun Jan 9, 2025
c0f4d94
Update main.yml
can-angun Jan 9, 2025
6ca3257
Update api.js
can-angun Jan 9, 2025
2d1bcec
Update api_endpoint.js
can-angun Jan 9, 2025
dd85c93
Update hooks.properties
can-angun Jan 9, 2025
addce4b
Merge branch 'next' into next-hooks-test
can-angun Jan 10, 2025
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
468 changes: 468 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

134 changes: 0 additions & 134 deletions plugins/hooks/README.md

This file was deleted.

145 changes: 38 additions & 107 deletions plugins/hooks/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 @@ -272,82 +273,46 @@ plugins.register("/permissions/features", function(ob) {
plugins.register("/i/hook/save", function(ob) {
let paramsInstance = ob.params;


validateCreate(ob.params, FEATURE_NAME, function(params) {
let hookConfig = params.qstring.hook_config;
if (!hookConfig) {
common.returnMessage(params, 400, 'Invalid hookConfig');
return true;
}

try {
hookConfig = JSON.parse(hookConfig);
hookConfig = sanitizeConfig(hookConfig);
if (hookConfig) {
// Null check for hookConfig
if (!(common.validateArgs(hookConfig, CheckHookProperties(hookConfig)))) {
common.returnMessage(params, 400, 'Not enough args');
return true;
}
if (!(common.validateArgs(hookConfig, CheckHookProperties(hookConfig)))) {
common.returnMessage(params, 400, 'Not enough args');
return true;
}

if (hookConfig.effects && !validateEffects(hookConfig.effects)) {
common.returnMessage(params, 400, 'Invalid configuration for effects');
return true;
}
if (hookConfig && hookConfig.effects && !validateEffects(hookConfig.effects)) {
common.returnMessage(params, 400, 'Invalid configuration for effects');
return true;
}

if (hookConfig._id) {
const id = hookConfig._id;
delete hookConfig._id;
return common.db.collection("hooks").findAndModify(
{ _id: common.db.ObjectID(id) },
{},
{$set: hookConfig},
{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 {
common.returnMessage(params, 500, "Failed to save an hook");
}
if (hookConfig._id) {
const id = hookConfig._id;
delete hookConfig._id;
return common.db.collection("hooks").findAndModify(
{ _id: common.db.ObjectID(id) },
{},
{$set: hookConfig},
{new: true},
function(err, result) {
if (!err) {
common.returnOutput(params, result && result.value);
}
);
}

}
if (hookConfig) {
hookConfig.createdBy = params.member._id; // Accessing property now with proper check
hookConfig.created_at = new Date().getTime();
else {
common.returnMessage(params, 500, "Failed to save an hook");
}
});
}
hookConfig.createdBy = params.member._id;
hookConfig.created_at = new Date().getTime();
return common.db.collection("hooks").insert(
hookConfig,
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 @@ -502,8 +467,8 @@ plugins.register("/o/hook/list", function(ob) {
});
}
catch (err) {
log.e('get hook list failed', err);
common.returnMessage(params, 500, "Failed to get hook list" + err.message);
log.e('get hook list failed');
common.returnMessage(params, 500, "Failed to get hook list");
}
}, paramsInstance);
return true;
Expand Down Expand Up @@ -544,16 +509,7 @@ 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);
}).catch(function(err) {
log.e('Failed to update hook statuses: ', err);
common.returnMessage(params, 500, "Failed to update hook statuses: " + err.message);
});
}, paramsInstance);
return true;
Expand Down Expand Up @@ -587,23 +543,14 @@ 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");
}
}
);
}
catch (err) {
log.e('delete hook failed', hookID, err);
common.returnMessage(params, 500, "Failed to delete an hook" + err.message);
log.e('delete hook failed', hookID);
common.returnMessage(params, 500, "Failed to delete an hook");
}
}, paramsInstance);
return true;
Expand All @@ -615,56 +562,40 @@ plugins.register("/i/hook/test", function(ob) {

validateCreate(paramsInstance, FEATURE_NAME, async(params) => {
let hookConfig = params.qstring.hook_config;
if (!hookConfig) {
common.returnMessage(params, 400, 'Invalid hookConfig');
return;
}

try {
hookConfig = JSON.parse(hookConfig);
if (!hookConfig) {
common.returnMessage(params, 400, 'Parsed hookConfig is invalid');
return;
}
hookConfig = sanitizeConfig(hookConfig);
const mockData = JSON.parse(params.qstring.mock_data);

if (!(common.validateArgs(hookConfig, CheckHookProperties(hookConfig)))) {
common.returnMessage(params, 403, "hook config invalid" + JSON.stringify(hookConfig));
return; // Add return to exit early
common.returnMessage(params, 403, "hook config invalid");
}

// Null check for effects
if (hookConfig.effects && !validateEffects(hookConfig.effects)) {
if (hookConfig && hookConfig.effects && !validateEffects(hookConfig.effects)) {
common.returnMessage(params, 400, 'Config invalid');
return; // Add return to exit early
return true;
}


// trigger process
log.d(JSON.stringify(hookConfig), "[hook test config]");
const results = [];

// build mock data
const trigger = hookConfig.trigger;
if (!trigger) {
common.returnMessage(params, 400, 'Trigger is missing');
return;
}
hookConfig._id = null;

log.d("[hook test mock data]", mockData);
const obj = {
is_mock: true,
params: mockData,
rule: hookConfig
};

log.d("[hook test config data]", obj);
const t = new Triggers[trigger.type]({
rules: [hookConfig],
});

// output trigger result
// out put trigger result
const triggerResult = await t.process(obj);
log.d("[hook trigger test result]", triggerResult);
results.push(JSON.parse(JSON.stringify(triggerResult)));
Expand Down Expand Up @@ -695,8 +626,8 @@ plugins.register("/i/hook/test", function(ob) {
return false;
}
catch (e) {
log.e("hook test error", e, hookConfig);
common.returnMessage(params, 503, "Hook test failed." + e.message);
log.e("hook test error", e);
common.returnMessage(params, 503, "Hook test failed.");
return;
}
}, paramsInstance);
Expand Down
4 changes: 2 additions & 2 deletions plugins/hooks/api/parts/triggers/api_endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class APIEndPointTrigger {
*/
async process(ob) {
// log.d(JSON.stringify(ob), "[hook trigger api_endpoint]");
const {params} = ob || {};
const {paths} = params || {};
const {params} = ob;
const {paths} = params;
const hookPath = paths.length >= 4 ? paths[3] : null;
const {qstring} = params || {};

Expand Down
Loading
Loading