modify database for workstation/server policies
This commit is contained in:
parent
17369890d2
commit
0a6ff54497
|
@ -129,7 +129,14 @@ class GetRelated(APIView):
|
||||||
response = {}
|
response = {}
|
||||||
|
|
||||||
policy = (
|
policy = (
|
||||||
Policy.objects.filter(pk=pk).prefetch_related("clients", "sites").first()
|
Policy.objects.filter(pk=pk)
|
||||||
|
.prefetch_related(
|
||||||
|
"workstation_clients",
|
||||||
|
"workstation_sites",
|
||||||
|
"server_clients",
|
||||||
|
"server_sites",
|
||||||
|
)
|
||||||
|
.first()
|
||||||
)
|
)
|
||||||
|
|
||||||
response["clients"] = ClientSerializer(policy.clients.all(), many=True).data
|
response["clients"] = ClientSerializer(policy.clients.all(), many=True).data
|
||||||
|
@ -157,7 +164,7 @@ class GetRelated(APIView):
|
||||||
related_type = request.data["type"]
|
related_type = request.data["type"]
|
||||||
pk = request.data["pk"]
|
pk = request.data["pk"]
|
||||||
|
|
||||||
#If policy is set in request
|
# If policy is set in request
|
||||||
if request.data["policy"] != 0:
|
if request.data["policy"] != 0:
|
||||||
policy = get_object_or_404(Policy, pk=request.data["policy"])
|
policy = get_object_or_404(Policy, pk=request.data["policy"])
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
# Generated by Django 3.1 on 2020-08-21 21:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('automation', '0004_auto_20200617_0332'),
|
||||||
|
('clients', '0003_auto_20200609_1607'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='client',
|
||||||
|
name='policy',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='site',
|
||||||
|
name='policy',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='client',
|
||||||
|
name='server_policy',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='server_clients', to='automation.policy'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='client',
|
||||||
|
name='workstation_policy',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='workstation_clients', to='automation.policy'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='site',
|
||||||
|
name='server_policy',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='server_sites', to='automation.policy'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='site',
|
||||||
|
name='workstation_policy',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='workstation_sites', to='automation.policy'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -4,9 +4,17 @@ from agents.models import Agent
|
||||||
|
|
||||||
class Client(models.Model):
|
class Client(models.Model):
|
||||||
client = models.CharField(max_length=255, unique=True)
|
client = models.CharField(max_length=255, unique=True)
|
||||||
policy = models.ForeignKey(
|
workstation_policy = models.ForeignKey(
|
||||||
"automation.Policy",
|
"automation.Policy",
|
||||||
related_name="clients",
|
related_name="workstation_clients",
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
)
|
||||||
|
|
||||||
|
server_policy = models.ForeignKey(
|
||||||
|
"automation.Policy",
|
||||||
|
related_name="server_clients",
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
|
@ -33,9 +41,17 @@ class Client(models.Model):
|
||||||
class Site(models.Model):
|
class Site(models.Model):
|
||||||
client = models.ForeignKey(Client, related_name="sites", on_delete=models.CASCADE)
|
client = models.ForeignKey(Client, related_name="sites", on_delete=models.CASCADE)
|
||||||
site = models.CharField(max_length=255)
|
site = models.CharField(max_length=255)
|
||||||
policy = models.ForeignKey(
|
workstation_policy = models.ForeignKey(
|
||||||
"automation.Policy",
|
"automation.Policy",
|
||||||
related_name="sites",
|
related_name="workstation_sites",
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
)
|
||||||
|
|
||||||
|
server_policy = models.ForeignKey(
|
||||||
|
"automation.Policy",
|
||||||
|
related_name="server_sites",
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
|
|
|
@ -1,19 +1,64 @@
|
||||||
<template>
|
<template>
|
||||||
<q-card style="width: 60vw">
|
<q-card style="width: 60vw">
|
||||||
<q-card-section class="row items-center">
|
<q-card-section class="row items-center">
|
||||||
<div class="text-h6">Edit policy assigned to {{ type }}</div>
|
<div class="text-h6">Edit policies assigned to {{ type }}</div>
|
||||||
<q-space />
|
<q-space />
|
||||||
<q-btn icon="close" flat round dense v-close-popup />
|
<q-btn icon="close" flat round dense v-close-popup />
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-form @submit="submit" ref="form">
|
<q-form @submit="submit" ref="form">
|
||||||
<q-card-section>
|
<q-card-section v-if="type !== 'agent'">
|
||||||
<q-select
|
<q-select
|
||||||
v-model="selected"
|
v-model="selectedServerPolicy"
|
||||||
:options="options"
|
:options="options"
|
||||||
filled
|
filled
|
||||||
options-selected-class="text-green"
|
options-selected-class="text-green"
|
||||||
dense
|
dense
|
||||||
clearable
|
clearable
|
||||||
|
label="Server Policy"
|
||||||
|
>
|
||||||
|
<template v-slot:option="props">
|
||||||
|
<q-item v-bind="props.itemProps" v-on="props.itemEvents">
|
||||||
|
<q-item-section avatar>
|
||||||
|
<q-icon v-if="props.selected" name="check" />
|
||||||
|
</q-item-section>
|
||||||
|
<q-item-section>
|
||||||
|
<q-item-label v-html="props.opt.label" />
|
||||||
|
</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</template>
|
||||||
|
</q-select>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section>
|
||||||
|
<q-select
|
||||||
|
v-model="selectedWorkstationPolicy"
|
||||||
|
:options="options"
|
||||||
|
filled
|
||||||
|
options-selected-class="text-green"
|
||||||
|
dense
|
||||||
|
clearable
|
||||||
|
label="Workstation Policy"
|
||||||
|
>
|
||||||
|
<template v-slot:option="props">
|
||||||
|
<q-item v-bind="props.itemProps" v-on="props.itemEvents">
|
||||||
|
<q-item-section avatar>
|
||||||
|
<q-icon v-if="props.selected" name="check" />
|
||||||
|
</q-item-section>
|
||||||
|
<q-item-section>
|
||||||
|
<q-item-label v-html="props.opt.label" />
|
||||||
|
</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</template>
|
||||||
|
</q-select>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section v-if="type === 'agent'">
|
||||||
|
<q-select
|
||||||
|
v-model="selectedAgentPolicy"
|
||||||
|
:options="options"
|
||||||
|
filled
|
||||||
|
options-selected-class="text-green"
|
||||||
|
dense
|
||||||
|
clearable
|
||||||
|
label="Policy"
|
||||||
>
|
>
|
||||||
<template v-slot:option="props">
|
<template v-slot:option="props">
|
||||||
<q-item v-bind="props.itemProps" v-on="props.itemEvents">
|
<q-item v-bind="props.itemProps" v-on="props.itemEvents">
|
||||||
|
@ -28,7 +73,7 @@
|
||||||
</q-select>
|
</q-select>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section class="row items-center">
|
<q-card-section class="row items-center">
|
||||||
<q-btn label="Add Policy" color="primary" type="submit" />
|
<q-btn label="Add Policies" color="primary" type="submit" />
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-form>
|
</q-form>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -45,29 +90,32 @@ export default {
|
||||||
type: {
|
type: {
|
||||||
required: true,
|
required: true,
|
||||||
type: String,
|
type: String,
|
||||||
validator: function(value) {
|
validator: function (value) {
|
||||||
// The value must match one of these strings
|
// The value must match one of these strings
|
||||||
return ["agent", "site", "client"].includes(value);
|
return ["agent", "site", "client"].includes(value);
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selected: null,
|
selectedWorkstationPolicy: null,
|
||||||
options: []
|
selectedServerPolicy: null,
|
||||||
|
selectedAgentPolicy: null,
|
||||||
|
options: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
policies: "automation/policies"
|
policies: "automation/policies",
|
||||||
})
|
}),
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
submit() {
|
submit() {
|
||||||
this.$q.loading.show();
|
this.$q.loading.show();
|
||||||
|
|
||||||
let data = {};
|
let data = {};
|
||||||
(data.pk = this.pk), (data.type = this.type);
|
data.pk = this.pk;
|
||||||
|
data.type = this.type;
|
||||||
data.policy = this.selected === null ? 0 : this.selected.value;
|
data.policy = this.selected === null ? 0 : this.selected.value;
|
||||||
|
|
||||||
this.$store
|
this.$store
|
||||||
|
@ -88,7 +136,7 @@ export default {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.options = this.policies.map(policy => ({
|
this.options = this.policies.map(policy => ({
|
||||||
label: policy.name,
|
label: policy.name,
|
||||||
value: policy.id
|
value: policy.id,
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
|
@ -101,20 +149,38 @@ export default {
|
||||||
.dispatch("automation/getRelatedPolicies", { pk, type })
|
.dispatch("automation/getRelatedPolicies", { pk, type })
|
||||||
.then(r => {
|
.then(r => {
|
||||||
if (r.data.id !== undefined) {
|
if (r.data.id !== undefined) {
|
||||||
this.selected = {
|
if (type === "agent") {
|
||||||
label: r.data.name,
|
this.selectedAgentPolicy = {
|
||||||
value: r.data.id
|
label: r.data.name,
|
||||||
};
|
value: r.data.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type !== "agent") {
|
||||||
|
if (r.data.server_policy.id !== undefined) {
|
||||||
|
this.selectedServerPolicy = {
|
||||||
|
label: r.data.server_policy.name,
|
||||||
|
value: r.data.server_policy.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r.data.workstation_policy.id !== undefined) {
|
||||||
|
this.selectedWorkstationPolicy = {
|
||||||
|
label: r.data.workstation_policy.name,
|
||||||
|
value: r.data.workstation_policy.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
this.$q.notify(notifyErrorConfig("Add error occured while loading"));
|
this.$q.notify(notifyErrorConfig("Add error occured while loading"));
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.getPolicies();
|
this.getPolicies();
|
||||||
this.getRelation(this.pk, this.type);
|
this.getRelation(this.pk, this.type);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue