From 4ef77341148f2af285586b1dc503074ddf0c5bea Mon Sep 17 00:00:00 2001 From: Josh Krawczyk Date: Sat, 30 May 2020 11:51:55 -0400 Subject: [PATCH 1/2] Fix Django Tests --- api/tacticalrmm/checks/tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/tacticalrmm/checks/tests.py b/api/tacticalrmm/checks/tests.py index 54292972..7f1c10e5 100644 --- a/api/tacticalrmm/checks/tests.py +++ b/api/tacticalrmm/checks/tests.py @@ -4,7 +4,7 @@ from .serializers import CheckSerializer # , PolicyChecksSerializer class TestCheckViews(BaseTestCase): def test_add_disk_check(self): - url = "/checks/addstandardcheck/" + url = "/checks/" disk_data = { "pk": self.agent.pk, "check_type": "diskspace", @@ -22,7 +22,7 @@ class TestCheckViews(BaseTestCase): self.check_not_authenticated("post", url) def test_add_policy_disk_check(self): - url = "/checks/addstandardcheck/" + url = "/checks/" policy_disk_data = { "policy": self.policy.pk, "check_type": "diskspace", @@ -32,7 +32,7 @@ class TestCheckViews(BaseTestCase): } resp = self.client.post(url, policy_disk_data, format="json") self.assertEqual(resp.status_code, 200) - data = PolicyChecksSerializer(self.policy).data + data = CheckSerializer(self.policy).data self.assertEqual(data["diskchecks"][0]["threshold"], 87) self.assertEqual(data["diskchecks"][0]["failures"], 1) self.assertEqual(data["diskchecks"][0]["disk"], "M:") From 71cf0cbafc0cd5af242b7d3732058dbb46be7958 Mon Sep 17 00:00:00 2001 From: Josh Krawczyk Date: Sat, 30 May 2020 16:21:21 -0400 Subject: [PATCH 2/2] More Fixes --- api/tacticalrmm/checks/tests.py | 24 +++++++------ .../components/automation/PolicyChecksTab.vue | 34 +++++++++---------- web/src/store/store.js | 8 ++--- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/api/tacticalrmm/checks/tests.py b/api/tacticalrmm/checks/tests.py index 7f1c10e5..3545d350 100644 --- a/api/tacticalrmm/checks/tests.py +++ b/api/tacticalrmm/checks/tests.py @@ -4,13 +4,15 @@ from .serializers import CheckSerializer # , PolicyChecksSerializer class TestCheckViews(BaseTestCase): def test_add_disk_check(self): - url = "/checks/" + url = "/checks/checks/" disk_data = { "pk": self.agent.pk, - "check_type": "diskspace", - "disk": "C:", - "threshold": 41, - "failure": 4, + "check": { + "check_type": "diskspace", + "disk": "C:", + "threshold": 41, + "failure": 4 + } } resp = self.client.post(url, disk_data, format="json") self.assertEqual(resp.status_code, 200) @@ -22,13 +24,15 @@ class TestCheckViews(BaseTestCase): self.check_not_authenticated("post", url) def test_add_policy_disk_check(self): - url = "/checks/" + url = "/checks/checks/" policy_disk_data = { "policy": self.policy.pk, - "check_type": "diskspace", - "disk": "M:", - "threshold": 87, - "failure": 1, + "check": { + "check_type": "diskspace", + "disk": "M:", + "threshold": 87, + "failure": 1, + } } resp = self.client.post(url, policy_disk_data, format="json") self.assertEqual(resp.status_code, 200) diff --git a/web/src/components/automation/PolicyChecksTab.vue b/web/src/components/automation/PolicyChecksTab.vue index 59c76a76..d22a744f 100644 --- a/web/src/components/automation/PolicyChecksTab.vue +++ b/web/src/components/automation/PolicyChecksTab.vue @@ -151,14 +151,14 @@ @@ -247,22 +247,23 @@ export default { }; }, methods: { - checkAlertAction(pk, category, alert_type, alert_action) { - const action = alert_action ? "enabled" : "disabled"; - const data = { - alertType: alert_type, - checkid: pk, - category: category, - action: action - }; - const alertColor = alert_action ? "positive" : "warning"; + checkAlert(id, alert_type, action) { + const data = {}; + if (alert_type === "Email") { + data.email_alert = action; + } else { + data.text_alert = action; + } + + const act = action ? "enabled" : "disabled"; + const color = action ? "positive" : "warning"; this.$store - .dispatch("editCheckAlertAction", data) + .dispatch("editCheckAlert", id, data) .then(r => { this.$q.notify({ - color: alertColor, + color: color, icon: "fas fa-check-circle", - message: `${alert_type} alerts ${action}` + message: `${alert_type} alerts ${act}` }); }); }, @@ -310,14 +311,13 @@ export default { deleteCheck(check) { this.$q .dialog({ - title: `Delete ${check.check_type} check`, + title: `Delete ${check.check_type} check?`, ok: { label: "Delete", color: "negative" }, cancel: true, }) .onOk(() => { - const data = { pk: check.id, checktype: check.check_type }; this.$store - .dispatch("deleteCheck", data) + .dispatch("deleteCheck", check.id) .then(r => { this.$store.dispatch("automation/loadPolicyChecks", check.id); this.$q.notify(notifySuccessConfig("Check Deleted!")); diff --git a/web/src/store/store.js b/web/src/store/store.js index 90b84bf9..a9b37443 100644 --- a/web/src/store/store.js +++ b/web/src/store/store.js @@ -159,11 +159,11 @@ export const store = new Vuex.Store({ loadAgentServices(context, agentpk) { return axios.get(`/services/${agentpk}/services/`); }, - editCheckAlertAction(context, data) { - return axios.patch("/checks/checkalert/", data); + editCheckAlert(context, pk, data) { + return axios.patch(`/checks/${pk}/check/`, data); }, - deleteCheck(context, data) { - return axios.delete("checks/deletestandardcheck/", { data: data }); + deleteCheck(context, pk) { + return axios.delete(`/checks/${pk}/check/`); }, editAutoTask(context, data) { return axios.patch(`/tasks/${data.id}/automatedtasks/`, data);