diff --git a/back/workflows.json b/back/workflows.json index 808ca146..08914fc4 100755 --- a/back/workflows.json +++ b/back/workflows.json @@ -51,31 +51,5 @@ } } ] - }, - { - "name": "Sample Plugin Object Workflow", - "trigger": { - "object_type": "Plugins_Objects", - "event_type": "create" - }, - "conditions": [ - { - "logic": "AND", - "conditions": [ - { - "field": "Plugin", - "operator": "equals", - "value": "ARPSCAN" - }, - { - "field": "Status", - "operator": "equals", - "value": "missing-in-last-scan" - } - ] - } - ], - "actions": [ - ] } ] \ No newline at end of file diff --git a/front/workflowsCore.php b/front/workflowsCore.php index 8797e2b4..5edbeb00 100755 --- a/front/workflowsCore.php +++ b/front/workflowsCore.php @@ -38,7 +38,7 @@ let fieldOptions = [ ]; let triggerTypes = [ - "Devices", "Plugins_Objects" + "Devices" ]; let operatorTypes = [ @@ -474,6 +474,7 @@ function createEditableDropdown(jsonPath, labelText, options, selectedValue, id) jsonPath: jsonPath, class: "form-control col-sm-8 col-xs-12" }); + // Add options to the select dropdown $.each(options, function (_, option) { @@ -788,6 +789,8 @@ function removeAction(wfIndex, actionIndex) { return; } + console.log(actionIndex); + // Remove the specified condition target.actions.splice(actionIndex, 1); diff --git a/server/workflows/app_events.py b/server/workflows/app_events.py index 2ada0dc3..d3c28b6e 100755 --- a/server/workflows/app_events.py +++ b/server/workflows/app_events.py @@ -122,7 +122,6 @@ class AppEvent_obj: """Generic function to create triggers dynamically.""" trigger_name = f"trg_{event}_{table_name.lower()}" - query = f""" CREATE TRIGGER IF NOT EXISTS "{trigger_name}" AFTER {event.upper()} ON "{table_name}" @@ -130,8 +129,8 @@ class AppEvent_obj: SELECT 1 FROM AppEvents WHERE AppEventProcessed = 0 AND ObjectType = '{table_name}' - AND ObjectGUID = {config['fields']['ObjectGUID']} - AND ObjectStatus = {config['fields']['ObjectStatus']} + AND ObjectGUID = {manage_prefix(config['fields']['ObjectGUID'], event)} + AND ObjectStatus = {manage_prefix(config['fields']['ObjectStatus'], event)} AND AppEventType = '{event.lower()}' ) BEGIN @@ -156,15 +155,15 @@ class AppEvent_obj: DATETIME('now'), FALSE, '{table_name}', - {config['fields']['ObjectGUID']}, -- ObjectGUID - {config['fields']['ObjectPrimaryID']}, -- ObjectPrimaryID - {config['fields']['ObjectSecondaryID']}, -- ObjectSecondaryID - {config['fields']['ObjectStatus']}, -- ObjectStatus - {config['fields']['ObjectStatusColumn']}, -- ObjectStatusColumn - {config['fields']['ObjectIsNew']}, -- ObjectIsNew - {config['fields']['ObjectIsArchived']}, -- ObjectIsArchived - {config['fields']['ObjectForeignKey']}, -- ObjectForeignKey - {config['fields']['ObjectPlugin']}, -- ObjectForeignKey + {manage_prefix(config['fields']['ObjectGUID'], event)}, -- ObjectGUID + {manage_prefix(config['fields']['ObjectPrimaryID'], event)}, -- ObjectPrimaryID + {manage_prefix(config['fields']['ObjectSecondaryID'], event)}, -- ObjectSecondaryID + {manage_prefix(config['fields']['ObjectStatus'], event)}, -- ObjectStatus + {manage_prefix(config['fields']['ObjectStatusColumn'], event)}, -- ObjectStatusColumn + {manage_prefix(config['fields']['ObjectIsNew'], event)}, -- ObjectIsNew + {manage_prefix(config['fields']['ObjectIsArchived'], event)}, -- ObjectIsArchived + {manage_prefix(config['fields']['ObjectForeignKey'], event)}, -- ObjectForeignKey + {manage_prefix(config['fields']['ObjectPlugin'], event)}, -- ObjectForeignKey '{event.lower()}' ); END; @@ -177,3 +176,10 @@ class AppEvent_obj: def save(self): # Commit changes self.db.commitDB() + +# Manage prefixes of column names +def manage_prefix(field, event): + if event == "delete": + return field.replace("NEW.", "OLD.") + return field + diff --git a/test/workflows.json b/test/workflows.json index 44b17134..08914fc4 100755 --- a/test/workflows.json +++ b/test/workflows.json @@ -1,17 +1,4 @@ [ - { - "name": "Empty Workflow", - "trigger": { - "object_type": "", - "event_type": "" - }, - "conditions": [ - - ], - "actions": [ - - ] - }, { "name": "Sample Device Update Workflow", "trigger": { @@ -36,14 +23,14 @@ "logic": "OR", "conditions": [ { - "field": "devSite", + "field": "devIsNew", "operator": "equals", - "value": "Home" + "value": "1" }, { "field": "devName", "operator": "contains", - "value": "Motorola" + "value": "Google" } ] } @@ -55,33 +42,14 @@ "type": "update_field", "field": "devIsNew", "value": "0" - } - ] - }, - { - "name": "Sample Plugin Object Workflow", - "trigger": { - "object_type": "Plugins_Objects", - "event_type": "create" - }, - "conditions": [ + }, { - "logic": "AND", - "conditions": [ - { - "field": "Plugin", - "operator": "equals", - "value": "ARPSCAN" - }, - { - "field": "Status", - "operator": "equals", - "value": "missing-in-last-scan" - } - ] + "type": "run_plugin", + "plugin": "SMTP", + "params": { + "message": "New device from Google detected." + } } - ], - "actions": [ ] } ] \ No newline at end of file