feat: double-click agent action #232

This commit is contained in:
wh1te909 2021-01-14 02:21:08 +00:00
parent d310bf8bbf
commit 7b2ec90de9
9 changed files with 178 additions and 3 deletions

View File

@ -0,0 +1,26 @@
# Generated by Django 3.1.4 on 2021-01-14 01:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("accounts", "0009_user_show_community_scripts"),
]
operations = [
migrations.AddField(
model_name="user",
name="agent_dblclick_action",
field=models.CharField(
choices=[
("editagent", "Edit Agent"),
("takecontrol", "Take Control"),
("remotebg", "Remote Background"),
],
default="editagent",
max_length=50,
),
),
]

View File

@ -3,12 +3,21 @@ from django.contrib.auth.models import AbstractUser
from logs.models import BaseAuditModel
AGENT_DBLCLICK_CHOICES = [
("editagent", "Edit Agent"),
("takecontrol", "Take Control"),
("remotebg", "Remote Background"),
]
class User(AbstractUser, BaseAuditModel):
is_active = models.BooleanField(default=True)
totp_key = models.CharField(max_length=50, null=True, blank=True)
dark_mode = models.BooleanField(default=True)
show_community_scripts = models.BooleanField(default=True)
agent_dblclick_action = models.CharField(
max_length=50, choices=AGENT_DBLCLICK_CHOICES, default="editagent"
)
agent = models.OneToOneField(
"agents.Agent",

View File

@ -278,6 +278,18 @@ class TestUserAction(TacticalTestCase):
r = self.client.patch(url, data, format="json")
self.assertEqual(r.status_code, 200)
data = {"agent_dblclick_action": "editagent"}
r = self.client.patch(url, data, format="json")
self.assertEqual(r.status_code, 200)
data = {"agent_dblclick_action": "remotebg"}
r = self.client.patch(url, data, format="json")
self.assertEqual(r.status_code, 200)
data = {"agent_dblclick_action": "takecontrol"}
r = self.client.patch(url, data, format="json")
self.assertEqual(r.status_code, 200)
self.check_not_authenticated("patch", url)

View File

@ -197,4 +197,8 @@ class UserUI(APIView):
user.show_community_scripts = request.data["show_community_scripts"]
user.save(update_fields=["show_community_scripts"])
if "agent_dblclick_action" in request.data:
user.agent_dblclick_action = request.data["agent_dblclick_action"]
user.save(update_fields=["agent_dblclick_action"])
return Response("ok")

View File

@ -75,6 +75,7 @@ def dashboard_info(request):
"trmm_version": settings.TRMM_VERSION,
"dark_mode": request.user.dark_mode,
"show_community_scripts": request.user.show_community_scripts,
"dbl_click_action": request.user.agent_dblclick_action,
}
)

View File

@ -473,7 +473,17 @@ export default {
// give time for store to change active row
setTimeout(() => {
this.$q.loading.hide();
this.showEditAgentModal = true;
switch (this.agentDblClickAction) {
case "editagent":
this.showEditAgentModal = true;
break;
case "takecontrol":
this.takeControl(pk);
break;
case "remotebg":
this.remoteBG(pk);
break;
}
}, 500);
},
runFavScript(scriptpk, agentpk) {
@ -694,6 +704,9 @@ export default {
},
computed: {
...mapGetters(["selectedAgentPk", "agentTableHeight"]),
agentDblClickAction() {
return this.$store.state.agentDblClickAction;
},
selectedRow() {
return this.$store.state.selectedRow;
},

View File

@ -0,0 +1,94 @@
<template>
<q-card style="min-width: 85vh">
<q-splitter v-model="splitterModel">
<template v-slot:before>
<q-tabs dense v-model="tab" vertical class="text-primary">
<q-tab name="ui" label="User Interface" />
</q-tabs>
</template>
<template v-slot:after>
<q-form @submit.prevent="editUserPrefs">
<q-card-section class="row items-center">
<div class="text-h6">Preferences</div>
<q-space />
<q-btn icon="close" flat round dense v-close-popup />
</q-card-section>
<q-tab-panels v-model="tab" animated transition-prev="jump-up" transition-next="jump-up">
<!-- UI -->
<q-tab-panel name="ui">
<div class="text-subtitle2">User Interface</div>
<hr />
<q-card-section class="row">
<div class="col-6">Agent table double-click action:</div>
<div class="col-2"></div>
<q-select
map-options
emit-value
outlined
dense
options-dense
v-model="agentDblClickAction"
:options="agentDblClickOptions"
class="col-4"
/>
</q-card-section>
</q-tab-panel>
</q-tab-panels>
<q-card-section class="row items-center">
<q-btn label="Save" color="primary" type="submit" />
</q-card-section>
</q-form>
</template>
</q-splitter>
</q-card>
</template>
<script>
import mixins from "@/mixins/mixins";
import { mapState } from "vuex";
export default {
name: "UserPreferences",
mixins: [mixins],
data() {
return {
agentDblClickAction: "",
tab: "ui",
splitterModel: 20,
agentDblClickOptions: [
{
label: "Edit Agent",
value: "editagent",
},
{
label: "Take Control",
value: "takecontrol",
},
{
label: "Remote Background",
value: "remotebg",
},
],
};
},
methods: {
getUserPrefs() {
this.$axios.get("/core/dashinfo/").then(r => {
this.agentDblClickAction = r.data.dbl_click_action;
});
},
editUserPrefs() {
const data = { agent_dblclick_action: this.agentDblClickAction };
this.$axios.patch("/accounts/users/ui/", data).then(r => {
this.notifySuccess("Preferences were saved!");
this.$emit("edited");
this.$emit("close");
});
},
},
created() {
this.getUserPrefs();
},
};
</script>

View File

@ -33,7 +33,8 @@ export default function () {
needrefresh: false,
tableHeight: "35vh",
tabHeight: "35vh",
showCommunityScripts: false
showCommunityScripts: false,
agentDblClickAction: "",
},
getters: {
loggedIn(state) {
@ -135,6 +136,9 @@ export default function () {
},
setShowCommunityScripts(state, show) {
state.showCommunityScripts = show
},
SET_AGENT_DBLCLICK_ACTION(state, action) {
state.agentDblClickAction = action
}
},
actions: {

View File

@ -73,6 +73,11 @@
<q-btn-dropdown flat no-caps stretch :label="user">
<q-list>
<q-item clickable v-ripple @click="showUserPreferencesModal = true" v-close-popup>
<q-item-section>
<q-item-label>Preferences</q-item-label>
</q-item-section>
</q-item>
<q-item to="/expired" exact>
<q-item-section>
<q-item-label>Logout</q-item-label>
@ -354,6 +359,10 @@
<q-dialog v-model="showInstallAgentModal" @hide="closeInstallAgent">
<InstallAgent @close="closeInstallAgent" :sitepk="parseInt(sitePk)" />
</q-dialog>
<!-- user preferences modal -->
<q-dialog v-model="showUserPreferencesModal">
<UserPreferences @close="showUserPreferencesModal = false" @edited="getDashInfo" />
</q-dialog>
</q-layout>
</template>
@ -369,6 +378,7 @@ import PolicyAdd from "@/components/automation/modals/PolicyAdd";
import ClientsForm from "@/components/modals/clients/ClientsForm";
import SitesForm from "@/components/modals/clients/SitesForm";
import InstallAgent from "@/components/modals/agents/InstallAgent";
import UserPreferences from "@/components/modals/coresettings/UserPreferences";
export default {
components: {
@ -380,6 +390,7 @@ export default {
ClientsForm,
SitesForm,
InstallAgent,
UserPreferences,
},
data() {
return {
@ -413,6 +424,7 @@ export default {
filterChecksFailing: false,
filterRebootNeeded: false,
currentTRMMVersion: null,
showUserPreferencesModal: false,
columns: [
{
name: "smsalert",
@ -673,7 +685,7 @@ export default {
this.darkMode = r.data.dark_mode;
this.$q.dark.set(this.darkMode);
this.currentTRMMVersion = r.data.trmm_version;
this.$store.commit("SET_AGENT_DBLCLICK_ACTION", r.data.dbl_click_action);
this.$store.commit("setShowCommunityScripts", r.data.show_community_scripts);
});
},