fix being ablwe to add/edit automation and alert templates on sites and clients

This commit is contained in:
sadnub 2021-03-31 12:03:26 -04:00
parent 84b6be9364
commit 77f7778d4a
6 changed files with 53 additions and 44 deletions

View File

@ -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"])

View File

@ -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",
)

View File

@ -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()

View File

@ -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();

View File

@ -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

View File

@ -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() {