Allow bulk resetting agent policies from settings UI. Modified agent edit serializer to fix errors

This commit is contained in:
sadnub
2020-09-09 13:10:29 -04:00
parent 0ded76956f
commit 4a6ea2b105
5 changed files with 139 additions and 5 deletions

View File

@@ -170,7 +170,7 @@ export default {
},
methods: {
getAgentInfo() {
axios.get(`/agents/${this.selectedAgentPk}/agentdetail/`).then(r => {
axios.get(`/agents/${this.selectedAgentPk}/agenteditdetails/`).then(r => {
this.agent = r.data;
this.allTimezones = Object.freeze(r.data.all_timezones);
@@ -206,9 +206,7 @@ export default {
data.time_zone = this.timezone;
}
delete data.services;
delete data.disks;
delete data.local_ip;
delete data.all_timezones;
axios
.patch("/agents/editagent/", data)

View File

@@ -38,6 +38,11 @@
class="col-6"
/>
</q-card-section>
<q-card-section class="row">
<div class="col-4">Reset Patch Policy on Agents:</div>
<div class="col-2"></div>
<q-btn color="negative" label="Reset" @click="resetPatchPolicyModal" />
</q-card-section>
</q-tab-panel>
<!-- alerts -->
<q-tab-panel name="alerts">
@@ -191,18 +196,25 @@
</q-form>
</template>
</q-splitter>
<q-dialog v-model="showResetPatchPolicyModal">
<ResetPatchPolicy @close="showResetPatchPolicyModal = false" />
</q-dialog>
</q-card>
</template>
<script>
import axios from "axios";
import mixins from "@/mixins/mixins";
import ResetPatchPolicy from "@/components/modals/coresettings/ResetPatchPolicy";
export default {
name: "EditCoreSettings",
components: { ResetPatchPolicy },
mixins: [mixins],
data() {
return {
showResetPatchPolicyModal: false,
ready: false,
settings: {},
email: null,
@@ -250,6 +262,9 @@ export default {
const removed = this.settings.email_alert_recipients.filter(k => k !== email);
this.settings.email_alert_recipients = removed;
},
resetPatchPolicyModal() {
this.showResetPatchPolicyModal = true;
},
editSettings() {
this.$q.loading.show();
axios

View File

@@ -0,0 +1,118 @@
<template>
<q-card style="min-width: 400px">
<q-card-section class="row">
<q-card-actions align="left">
<div class="text-h6">Reset Agent Patch Policy</div>
</q-card-actions>
<q-space />
<q-card-actions align="right">
<q-btn v-close-popup flat round dense icon="close" />
</q-card-actions>
</q-card-section>
<q-card-section>
<div class="text-subtitle3">
Reset the patch policies for agents in a specific client or site.
You can also leave the client and site blank to reset the patch policy for all agents.
(This might take a while)
</div>
<q-form @submit.prevent="submit">
<q-card-section>
<q-select
label="Clients"
@clear="clearClient"
clearable
options-dense
outlined
v-model="client"
:options="client_options"
/>
</q-card-section>
<q-card-section>
<q-select
:disabled="client === null"
@clear="clearSite"
label="Sites"
clearable
options-dense
outlined
v-model="site"
:options="site_options"
/>
</q-card-section>
<q-card-actions align="right">
<q-btn label="Reset Policies" color="primary" type="submit" />
<q-btn label="Cancel" v-close-popup />
</q-card-actions>
</q-form>
</q-card-section>
</q-card>
</template>
<script>
import { notifySuccessConfig, notifyErrorConfig } from "@/mixins/mixins";
export default {
name: "ResetPatchPolicy",
data() {
return {
client: null,
site: null,
client_options: [],
};
},
methods: {
submit() {
this.$q.loading.show();
let data = {};
if (this.client !== null) {
data.client = this.client.label;
}
if (this.site !== null) {
data.site = this.site.label;
}
this.$store
.dispatch("automation/resetPatchPolicies", data)
.then(r => {
this.$q.loading.hide();
this.$q.notify(notifySuccessConfig("The agent policies were reset successfully!"));
this.$emit("close");
})
.catch(e => {
this.$q.notify(notifyErrorConfig("There was an error reseting policies"));
});
},
getClients() {
this.$store
.dispatch("loadClients")
.then(r => {
this.client_options = r.data.map(client => ({ label: client.client, value: client.id, sites: client.sites }));
})
.catch(e => {
this.$q.notify(notifyErrorConfig("There was an error loading the clients!"));
});
},
clearClient() {
this.client = null;
this.site = null;
},
clearSite() {
this.site = null;
},
},
computed: {
site_options() {
return !!this.client ? this.client.sites.map(site => ({ label: site.site, value: site.id })) : [];
},
buttonText() {
return !!this.client ? "Clear Policies for ALL Agents" : "Clear Policies";
},
},
mounted() {
this.getClients();
},
};
</script>

View File

@@ -98,6 +98,9 @@ export default {
},
deletePatchPolicy(context, pk) {
return axios.delete(`/automation/winupdatepolicy/${pk}/`)
},
resetPatchPolicies(context, data) {
return axios.patch("/automation/winupdatepolicy/reset/", data)
}
}
}

View File

@@ -197,7 +197,7 @@ export default function () {
});
},
loadClients(context) {
return axios.get("/clients/listclients/");
return axios.get("/clients/clients/");
},
loadSites(context) {
return axios.get("/clients/listsites/");