reduced some code and tweaked the UI

This commit is contained in:
sadnub 2020-10-28 22:49:41 -04:00
parent 3730afd5d6
commit c49f6884a3
5 changed files with 107 additions and 174 deletions

View File

@ -23,12 +23,12 @@ class Policy(BaseAuditModel):
return self.name
def related_agents(self):
return self.related_server_agents() | self.related_workstation_agents()
return self.get_related("server") | self.get_related("workstation")
def related_server_agents(self):
explicit_agents = self.agents.filter(monitoring_type="server")
explicit_clients = self.server_clients.all()
explicit_sites = self.server_sites.all()
def get_related(self, mon_type):
explicit_agents = self.agents.filter(monitoring_type=mon_type)
explicit_clients = getattr(self, f"{mon_type}_clients").all()
explicit_sites = getattr(self, f"{mon_type}_sites").all()
filtered_agents_pks = Policy.objects.none()
@ -37,37 +37,12 @@ class Policy(BaseAuditModel):
filtered_agents_pks |= Agent.objects.filter(
client=site.client.client,
site=site.site,
monitoring_type="server",
monitoring_type=mon_type,
).values_list("pk", flat=True)
filtered_agents_pks |= Agent.objects.filter(
client__in=[client.client for client in explicit_clients],
monitoring_type="server",
).values_list("pk", flat=True)
return Agent.objects.filter(
models.Q(pk__in=filtered_agents_pks)
| models.Q(pk__in=explicit_agents.only("pk"))
)
def related_workstation_agents(self):
explicit_agents = self.agents.filter(monitoring_type="workstation")
explicit_clients = self.workstation_clients.all()
explicit_sites = self.workstation_sites.all()
filtered_agents_pks = Policy.objects.none()
for site in explicit_sites:
if site.client not in explicit_clients:
filtered_agents_pks |= Agent.objects.filter(
client=site.client.client,
site=site.site,
monitoring_type="workstation",
).values_list("pk", flat=True)
filtered_agents_pks |= Agent.objects.filter(
client__in=[client.client for client in explicit_clients],
monitoring_type="workstation",
monitoring_type=mon_type,
).values_list("pk", flat=True)
return Agent.objects.filter(

View File

@ -186,7 +186,7 @@ class GetRelated(APIView):
).data
response["agents"] = AgentHostnameSerializer(
policy.related_server_agents() | policy.related_workstation_agents(),
policy.related_agents(),
many=True,
).data

View File

@ -11,7 +11,7 @@ AUTH_USER_MODEL = "accounts.User"
# bump this version everytime vue code is changed
# to alert user they need to manually refresh their browser
APP_VER = "0.0.81"
APP_VER = "0.0.82"
# https://github.com/wh1te909/salt
LATEST_SALT_VER = "1.1.0"

View File

@ -1,5 +1,5 @@
<template>
<div style="width: 900px; max-width: 90vw;">
<div style="width: 900px; max-width: 90vw">
<q-card>
<q-bar>
<q-btn ref="refresh" @click="refresh" class="q-mr-sm" dense flat push icon="refresh" />Automation Manager
@ -10,17 +10,7 @@
</q-bar>
<div class="q-pa-md">
<div class="q-gutter-sm">
<q-btn
ref="new"
label="New"
dense
flat
push
unelevated
no-caps
icon="add"
@click="showAddPolicyModal"
/>
<q-btn ref="new" label="New" dense flat push unelevated no-caps icon="add" @click="showAddPolicyModal" />
<q-btn
ref="edit"
label="Edit"
@ -102,36 +92,21 @@
<!-- context menu -->
<q-menu context-menu>
<q-list dense style="min-width: 200px">
<q-item
clickable
v-close-popup
@click="showEditPolicyModal(props.row.id)"
id="context-edit"
>
<q-item clickable v-close-popup @click="showEditPolicyModal(props.row.id)" id="context-edit">
<q-item-section side>
<q-icon name="edit" />
</q-item-section>
<q-item-section>Edit</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
@click="showCopyPolicyModal(props.row)"
id="context-copy"
>
<q-item clickable v-close-popup @click="showCopyPolicyModal(props.row)" id="context-copy">
<q-item-section side>
<q-icon name="content_copy" />
</q-item-section>
<q-item-section>Copy</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
@click="deletePolicy(props.row.id)"
id="context-delete"
>
<q-item clickable v-close-popup @click="deletePolicy(props.row.id)" id="context-delete">
<q-item-section side>
<q-icon name="delete" />
</q-item-section>
@ -140,24 +115,14 @@
<q-separator></q-separator>
<q-item
clickable
v-close-popup
@click="showRelationsModal(props.row)"
id="context-relation"
>
<q-item clickable v-close-popup @click="showRelationsModal(props.row)" id="context-relation">
<q-item-section side>
<q-icon name="account_tree" />
</q-item-section>
<q-item-section>Show Relations</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
@click="showEditPatchPolicyModal(props.row)"
id="context-winupdate"
>
<q-item clickable v-close-popup @click="showEditPatchPolicyModal(props.row)" id="context-winupdate">
<q-item-section side>
<q-icon name="system_update" />
</q-item-section>
@ -173,47 +138,35 @@
</q-menu>
<!-- enabled checkbox -->
<q-td>
<q-checkbox
dense
@input="toggleCheckbox(props.row, 'Active')"
v-model="props.row.active"
/>
<q-checkbox dense @input="toggleCheckbox(props.row, 'Active')" v-model="props.row.active" />
</q-td>
<!-- enforced checkbox -->
<q-td>
<q-checkbox
dense
@input="toggleCheckbox(props.row, 'Enforced')"
v-model="props.row.enforced"
/>
<q-checkbox dense @input="toggleCheckbox(props.row, 'Enforced')" v-model="props.row.enforced" />
</q-td>
<q-td>
{{ props.row.name }}
<q-chip
v-if="props.row.default_server_policy"
color="primary"
text-color="white"
size="sm"
>Default Server</q-chip>
<q-chip
v-if="props.row.default_workstation_policy"
color="primary"
text-color="white"
size="sm"
>Default Workstation</q-chip>
<q-chip v-if="props.row.default_server_policy" color="primary" text-color="white" size="sm"
>Default Server</q-chip
>
<q-chip v-if="props.row.default_workstation_policy" color="primary" text-color="white" size="sm"
>Default Workstation</q-chip
>
</q-td>
<q-td>{{ props.row.desc }}</q-td>
<q-td>
<span
style="cursor:pointer;color:blue;text-decoration:underline"
style="cursor: pointer; color: blue; text-decoration: underline"
@click="showRelationsModal(props.row)"
>{{ `Show Relations (${ props.row.agents_count }+)` }}</span>
>{{ `Show Relations (${props.row.agents_count}+)` }}</span
>
</q-td>
<q-td>
<span
style="cursor:pointer;color:blue;text-decoration:underline"
style="cursor: pointer; color: blue; text-decoration: underline"
@click="showEditPatchPolicyModal(props.row)"
>{{ patchPolicyText(props.row) }}</span>
>{{ patchPolicyText(props.row) }}</span
>
</q-td>
<q-td>
<q-icon name="content_copy" size="1.5em" @click="showCopyPolicyModal(props.row)">
@ -247,7 +200,7 @@
<!-- patch policy modal -->
<q-dialog v-model="showPatchPolicyModal" @hide="closePatchPolicyModal">
<q-card style="width: 900px; max-width: 90vw;">
<q-card style="width: 900px; max-width: 90vw">
<q-bar>
{{ patchPolicyModalText() }}
<q-space />
@ -255,7 +208,7 @@
<q-tooltip content-class="bg-white text-primary">Close</q-tooltip>
</q-btn>
</q-bar>
<q-scroll-area :thumb-style="thumbStyle" style="height: 500px;">
<q-scroll-area :thumb-style="thumbStyle" style="height: 70vh">
<PatchPolicyForm :policy="policy" @close="closePatchPolicyModal" />
</q-scroll-area>
</q-card>

View File

@ -5,10 +5,7 @@
<q-space />
<q-btn icon="close" flat round dense v-close-popup />
</q-card-section>
<q-card-section
class="row items-center"
v-if="related.default_server_policy || related.default_workstation_policy"
>
<q-card-section class="row items-center" v-if="related.default_server_policy || related.default_workstation_policy">
<div v-if="related.default_server_policy" class="text-body">
<q-icon name="error_outline" color="info" size="1.5em" />This policy is set as the Default Server Policy.
</div>
@ -34,11 +31,11 @@
</q-tabs>
<q-separator />
<q-scroll-area :thumb-style="thumbStyle" style="height: 50vh">
<q-tab-panels v-model="tab" :animated="false">
<q-tab-panel name="clients">
<q-list separator padding>
<q-item :key="item.id+'servers'" v-for="item in related.server_clients">
<q-item :key="item.id + 'servers'" v-for="item in related.server_clients">
<q-item-section>
<q-item-label>{{ item.client }}</q-item-label>
</q-item-section>
@ -48,7 +45,7 @@
</q-item-label>
</q-item-section>
</q-item>
<q-item :key="item.id+'workstations'" v-for="item in related.workstation_clients">
<q-item :key="item.id + 'workstations'" v-for="item in related.workstation_clients">
<q-item-section>
<q-item-label>{{ item.client }}</q-item-label>
</q-item-section>
@ -63,7 +60,7 @@
<q-tab-panel name="sites">
<q-list separator padding>
<q-item :key="item.id+'servers'" v-for="item in related.server_sites">
<q-item :key="item.id + 'servers'" v-for="item in related.server_sites">
<q-item-section>
<q-item-label>{{ item.site }}</q-item-label>
<q-item-label caption>{{ item.client_name }}</q-item-label>
@ -74,7 +71,7 @@
</q-item-label>
</q-item-section>
</q-item>
<q-item :key="item.id+'workstations'" v-for="item in related.workstation_sites">
<q-item :key="item.id + 'workstations'" v-for="item in related.workstation_sites">
<q-item-section>
<q-item-label>{{ item.site }}</q-item-label>
<q-item-label caption>{{ item.client_name }}</q-item-label>
@ -102,6 +99,7 @@
</q-list>
</q-tab-panel>
</q-tab-panels>
</q-scroll-area>
</q-card-section>
</q-card>
</template>
@ -119,6 +117,13 @@ export default {
return {
tab: "clients",
related: {},
thumbStyle: {
right: "2px",
borderRadius: "5px",
backgroundColor: "#027be3",
width: "5px",
opacity: 0.75,
},
};
},
mounted() {