diff --git a/src/boot/axios.js b/src/boot/axios.js index 3d72b16..d47b653 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -49,6 +49,10 @@ export default function ({ router, store }) { else if (error.response.status === 401) { router.push({ path: "/expired" }); } + // perms + else if (error.response.status === 403) { + text = error.response.data.detail; + } else if (error.response.status === 400) { if (error.response.data.non_field_errors) { diff --git a/src/components/modals/admin/UserForm.vue b/src/components/modals/admin/UserForm.vue index a9f4aa9..b179c0b 100644 --- a/src/components/modals/admin/UserForm.vue +++ b/src/components/modals/admin/UserForm.vue @@ -1,68 +1,231 @@ @@ -76,16 +239,60 @@ export default { props: { pk: Number }, data() { return { - username: "", - password: "", - email: "", - first_name: "", - last_name: "", - is_active: true, + settings: { + username: "", + password: "", + email: "", + first_name: "", + last_name: "", + is_superuser: false, + is_active: true, + can_use_mesh: false, + can_uninstall_agents: false, + can_update_agents: false, + can_edit_agent: false, + can_manage_procs: false, + can_view_eventlogs: false, + can_send_cmd: false, + can_reboot_agents: false, + can_install_agents: false, + can_run_scripts: false, + can_run_bulk: false, + can_manage_notes: false, + can_edit_core_settings: false, + can_do_server_maint: false, + can_code_sign: false, + can_manage_checks: false, + can_run_checks: false, + can_manage_clients: false, + can_manage_sites: false, + can_manage_deployments: false, + can_manage_automation_policies: false, + can_manage_autotasks: false, + can_run_autotasks: false, + can_view_auditlogs: false, + can_manage_pendingactions: false, + can_view_debuglogs: false, + can_manage_scripts: false, + can_manage_alerts: false, + can_manage_winsvcs: false, + can_manage_software: false, + can_manage_winupdates: false, + can_manage_accounts: false, + }, isPwd: true, + splitterModel: 15, + tab: "detail", }; }, computed: { + disableSave() { + if (this.pk) { + return !!this.settings.username; + } else { + return !!this.settings.username && !!this.settings.password; + } + }, title() { return this.pk ? "Edit User" : "Add User"; }, @@ -96,55 +303,50 @@ export default { methods: { getUser() { this.$q.loading.show(); - this.$store.dispatch("admin/loadUser", this.pk).then(r => { this.$q.loading.hide(); - - this.username = r.data.username; - this.email = r.data.email; - this.is_active = r.data.is_active; - this.first_name = r.data.first_name; - this.last_name = r.data.last_name; + this.settings = r.data; }); }, + getPerms() { + this.$axios.get("/accounts/users/").then(r => (this.settings.perms = r.data[0].perms)); + }, + superUser(val) { + for (const prop in this.settings) { + if (this.settings.perms.indexOf(`${prop}`) > -1) { + this.settings[prop] = val; + } + } + }, onSubmit() { this.$q.loading.show(); - let formData = { - id: this.pk, - username: this.username, - email: this.email, - is_active: this.is_active, - first_name: this.first_name, - last_name: this.last_name, - }; + delete this.settings.last_login; if (this.pk) { // dont allow updating is_active if username is same as logged in user - if (formData.username === this.logged_in_user) { - delete formData.is_active; + if (this.settings.username === this.logged_in_user) { + delete this.settings.is_active; } this.$store - .dispatch("admin/editUser", formData) - .then(r => { + .dispatch("admin/editUser", this.settings) + .then(() => { this.$q.loading.hide(); this.$emit("close"); this.notifySuccess("User edited!"); }) - .catch(e => { + .catch(() => { this.$q.loading.hide(); }); } else { - formData.password = this.password; - this.$store - .dispatch("admin/addUser", formData) + .dispatch("admin/addUser", this.settings) .then(r => { this.$q.loading.hide(); this.$emit("close"); this.notifySuccess(`User ${r.data} was added!`); }) - .catch(e => { + .catch(() => { this.$q.loading.hide(); }); } @@ -154,6 +356,8 @@ export default { // If pk prop is set that means we are editting if (this.pk) { this.getUser(); + } else { + this.getPerms(); } }, }; diff --git a/src/components/modals/agents/InstallAgent.vue b/src/components/modals/agents/InstallAgent.vue index 7eb862a..e5e6188 100644 --- a/src/components/modals/agents/InstallAgent.vue +++ b/src/components/modals/agents/InstallAgent.vue @@ -199,8 +199,8 @@ export default { case 415: err = "Missing 32 bit meshagent-x86.exe. Upload it from File > Upload Mesh Agent"; break; - case 400: - err = "Exe build failed. Check debug error log for exact error message"; + case 403: + err = "You do not have permissions to perform this action"; break; default: err = "Something went wrong";