From 351fe17bb6c48765e3cf0b9211b7b160f2caf59b Mon Sep 17 00:00:00 2001 From: sadnub Date: Fri, 29 Jan 2021 13:25:58 -0500 Subject: [PATCH] reworked policy add for client, site, and agent. removed vue unit tests, added alertign to auto tasks, added edit autotask capabilities for certain fields, moved policy generation logic to save method on Client, Site, Agent, Policy models --- src/components/AgentTable.vue | 16 +- src/components/AutomatedTasksTab.vue | 83 +++- .../automation/PolicyAutomatedTasksTab.vue | 78 +++- src/components/automation/PolicyOverview.vue | 2 +- .../automation/modals/PolicyAdd.vue | 60 ++- .../modals/tasks/AddAutomatedTask.vue | 20 +- .../modals/tasks/EditAutomatedTask.vue | 164 +++++++ .../automation/automationmanager.spec.js | 248 ----------- test/jest/__tests__/automation/data.js | 106 ----- .../__tests__/automation/formmodal.spec.js | 128 ------ .../__tests__/automation/policyadd.spec.js | 139 ------ .../automation/policycheckstab.spec.js | 405 ------------------ .../automation/policyoverview.spec.js | 146 ------- .../__tests__/automation/policystatus.spec.js | 176 -------- .../automation/policytasksstab.spec.js | 300 ------------- .../__tests__/automation/relationview.spec.js | 143 ------- 16 files changed, 378 insertions(+), 1836 deletions(-) delete mode 100644 test/jest/__tests__/automation/automationmanager.spec.js delete mode 100644 test/jest/__tests__/automation/data.js delete mode 100644 test/jest/__tests__/automation/formmodal.spec.js delete mode 100644 test/jest/__tests__/automation/policyadd.spec.js delete mode 100644 test/jest/__tests__/automation/policycheckstab.spec.js delete mode 100644 test/jest/__tests__/automation/policyoverview.spec.js delete mode 100644 test/jest/__tests__/automation/policystatus.spec.js delete mode 100644 test/jest/__tests__/automation/policytasksstab.spec.js delete mode 100644 test/jest/__tests__/automation/relationview.spec.js diff --git a/src/components/AgentTable.vue b/src/components/AgentTable.vue index 9be63c9..9f05047 100644 --- a/src/components/AgentTable.vue +++ b/src/components/AgentTable.vue @@ -665,12 +665,16 @@ export default { } }, showPolicyAdd(agent) { - this.$q.dialog({ - component: PolicyAdd, - parent: this, - type: "agent", - object: agent, - }); + this.$q + .dialog({ + component: PolicyAdd, + parent: this, + type: "agent", + object: agent, + }) + .onOk(() => { + this.$emit("refreshEdit"); + }); }, toggleMaintenance(agent) { let data = { diff --git a/src/components/AutomatedTasksTab.vue b/src/components/AutomatedTasksTab.vue index c4ec484..65ee65d 100644 --- a/src/components/AutomatedTasksTab.vue +++ b/src/components/AutomatedTasksTab.vue @@ -33,6 +33,21 @@ Enabled + + + @@ -48,13 +63,7 @@ Run task now - + @@ -86,6 +95,24 @@ :disable="props.row.managed_by_policy" /> + + + + + + + + @@ -139,6 +166,7 @@ import { mapState } from "vuex"; import { mapGetters } from "vuex"; import mixins from "@/mixins/mixins"; import AddAutomatedTask from "@/components/modals/tasks/AddAutomatedTask"; +import EditAutomatedTask from "@/components/modals/tasks/EditAutomatedTask"; import ScriptOutput from "@/components/modals/checks/ScriptOutput"; export default { @@ -155,6 +183,8 @@ export default { scriptInfo: {}, columns: [ { name: "enabled", align: "left", field: "enabled" }, + { name: "smsalert", field: "text_alert", align: "left" }, + { name: "emailalert", field: "email_alert", align: "left" }, { name: "policystatus", align: "left" }, { name: "name", label: "Name", field: "name", align: "left" }, { name: "sync_status", label: "Sync Status", field: "sync_status", align: "left" }, @@ -202,6 +232,34 @@ export default { }) .catch(e => this.notifyError("Something went wrong")); }, + taskAlert(pk, alert_type, action, managed_by_policy) { + if (managed_by_policy) { + return; + } + this.$q.loading.show(); + + const data = { + id: pk, + }; + + if (alert_type === "Email") { + data.email_alert = action; + } else { + data.text_alert = action; + } + + const act = action ? "enabled" : "disabled"; + axios + .put(`/tasks/${pk}/automatedtasks/`, data) + .then(r => { + this.$q.loading.hide(); + this.notifySuccess(`${alert_type} alerts ${act}`); + }) + .catch(e => { + this.$q.loading.hide(); + this.notifyError("There was an issue editing task"); + }); + }, refreshTasks(id) { this.$store.dispatch("loadAutomatedTasks", id); }, @@ -209,6 +267,17 @@ export default { this.scriptInfo = props; this.showScriptOutput = true; }, + showEditTask(task) { + this.$q + .dialog({ + component: EditAutomatedTask, + parent: this, + task: task, + }) + .onOk(() => { + this.refreshTasks(this.automatedTasks.pk); + }); + }, runTask(pk, enabled) { if (!enabled) { this.notifyError("Task cannot be run when it's disabled. Enable it first."); diff --git a/src/components/automation/PolicyAutomatedTasksTab.vue b/src/components/automation/PolicyAutomatedTasksTab.vue index adfe2c3..2d2324d 100644 --- a/src/components/automation/PolicyAutomatedTasksTab.vue +++ b/src/components/automation/PolicyAutomatedTasksTab.vue @@ -39,6 +39,22 @@ Enabled + + + +