From 77f7778d4ac4c8c2469a89b112f3400b773d747f Mon Sep 17 00:00:00 2001 From: sadnub Date: Wed, 31 Mar 2021 12:03:26 -0400 Subject: [PATCH] fix being ablwe to add/edit automation and alert templates on sites and clients --- api/tacticalrmm/agents/views.py | 2 +- api/tacticalrmm/clients/serializers.py | 2 + api/tacticalrmm/clients/views.py | 6 +- .../automation/modals/PolicyAdd.vue | 60 +++++++++---------- .../modals/alerts/AlertTemplateAdd.vue | 23 ++++--- web/src/views/Dashboard.vue | 4 +- 6 files changed, 53 insertions(+), 44 deletions(-) diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 3cc41c62..feeab286 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -87,7 +87,7 @@ def uninstall(request): return Response(f"{name} will now be uninstalled.") -@api_view(["PATCH"]) +@api_view(["PATCH", "PUT"]) def edit_agent(request): agent = get_object_or_404(Agent, pk=request.data["id"]) diff --git a/api/tacticalrmm/clients/serializers.py b/api/tacticalrmm/clients/serializers.py index afea8dbb..52044c57 100644 --- a/api/tacticalrmm/clients/serializers.py +++ b/api/tacticalrmm/clients/serializers.py @@ -33,6 +33,7 @@ class SiteSerializer(ModelSerializer): "name", "server_policy", "workstation_policy", + "alert_template", "client_name", "client", "custom_fields", @@ -75,6 +76,7 @@ class ClientSerializer(ModelSerializer): "name", "server_policy", "workstation_policy", + "alert_template", "sites", "custom_fields", ) diff --git a/api/tacticalrmm/clients/views.py b/api/tacticalrmm/clients/views.py index eebb1237..3ab4d3a5 100644 --- a/api/tacticalrmm/clients/views.py +++ b/api/tacticalrmm/clients/views.py @@ -167,13 +167,15 @@ class GetUpdateSite(APIView): def put(self, request, pk): site = get_object_or_404(Site, pk=pk) - if ( + if "client" in request.data["site"].keys() and ( site.client.id != request.data["site"]["client"] and site.client.sites.count() == 1 ): return notify_error("A client must have at least one site") - serializer = SiteSerializer(instance=site, data=request.data["site"]) + serializer = SiteSerializer( + instance=site, data=request.data["site"], partial=True + ) serializer.is_valid(raise_exception=True) serializer.save() diff --git a/web/src/components/automation/modals/PolicyAdd.vue b/web/src/components/automation/modals/PolicyAdd.vue index 252a9c79..c65108e8 100644 --- a/web/src/components/automation/modals/PolicyAdd.vue +++ b/web/src/components/automation/modals/PolicyAdd.vue @@ -111,45 +111,43 @@ export default { let data = {}; let url = ""; - if (this.type === "client" || this.type === "site") { + if (this.type === "client") { + url = `/clients/${this.object.id}/client/`; data = { - pk: this.object.id, - server_policy: this.selectedServerPolicy, - workstation_policy: this.selectedWorkstationPolicy, + client: { + pk: this.object.id, + server_policy: this.selectedServerPolicy, + workstation_policy: this.selectedWorkstationPolicy, + }, + }; + } else if (this.type === "site") { + url = `/clients/sites/${this.object.id}/`; + data = { + site: { + pk: this.object.id, + server_policy: this.selectedServerPolicy, + workstation_policy: this.selectedWorkstationPolicy, + }, }; - - if (this.type === "client") url = `/clients/${this.object.id}/client/`; - else if (this.type === "site") url = `/clients/${this.object.id}/site/`; - - this.$axios - .put(url, data) - .then(r => { - this.$q.loading.hide(); - this.onOk(); - this.notifySuccess("Policies Updated Successfully!"); - }) - .catch(e => { - this.$q.loading.hide(); - this.notifyError("There was an error updating policies"); - }); } else if (this.type === "agent") { + url = "/agents/editagent/"; data = { id: this.object.id, policy: this.selectedAgentPolicy, }; - - this.$axios - .patch("/agents/editagent/", data) - .then(r => { - this.$q.loading.hide(); - this.onOk(); - this.notifySuccess("Policies Updated Successfully!"); - }) - .catch(e => { - this.$q.loading.hide(); - this.notifyError("There was an error updating policies"); - }); } + + this.$axios + .put(url, data) + .then(r => { + this.$q.loading.hide(); + this.onOk(); + this.notifySuccess("Policies Updated Successfully!"); + }) + .catch(e => { + this.$q.loading.hide(); + this.notifyError("There was an error updating policies"); + }); }, getPolicies() { this.$q.loading.show(); diff --git a/web/src/components/modals/alerts/AlertTemplateAdd.vue b/web/src/components/modals/alerts/AlertTemplateAdd.vue index dc3a320e..dd6a72a0 100644 --- a/web/src/components/modals/alerts/AlertTemplateAdd.vue +++ b/web/src/components/modals/alerts/AlertTemplateAdd.vue @@ -65,15 +65,22 @@ export default { this.$q.loading.show(); - const data = { - id: this.object.id, - alert_template: this.selectedTemplate, - }; - let url = ""; - if (this.type === "client") url = `/clients/${this.object.id}/client/`; - else if (this.type === "site") url = `/clients/${this.object.id}/site/`; - else if (this.type === "policy") url = `/automation/policies/${this.object.id}/`; + let data = {}; + if (this.type === "client") { + url = `/clients/${this.object.id}/client/`; + data = { + client: { id: this.object.id, alert_template: this.selectedTemplate }, + }; + } else if (this.type === "site") { + url = `/clients/sites/${this.object.id}/`; + data = { + site: { id: this.object.id, alert_template: this.selectedTemplate }, + }; + } else if (this.type === "policy") { + url = `/automation/policies/${this.object.id}/`; + data = { id: this.object.id, alert_template: this.selectedTemplate }; + } const text = this.selectedTemplate ? "assigned" : "removed"; this.$axios diff --git a/web/src/views/Dashboard.vue b/web/src/views/Dashboard.vue index 556e3880..784db4a4 100644 --- a/web/src/views/Dashboard.vue +++ b/web/src/views/Dashboard.vue @@ -617,7 +617,7 @@ export default { object: node, }) .onOk(() => { - this.getTree(); + this.clearTreeSelected(); }); }, showAddSiteModal(node) { @@ -666,7 +666,7 @@ export default { object: node, }) .onOk(() => { - this.getTree(); + this.clearTreeSelected(); }); }, reload() {