Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 2 | <b-container class="ml-0"> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 3 | <b-row> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 4 | <b-col lg="10"> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 5 | <h1>Local user management</h1> |
| 6 | </b-col> |
| 7 | </b-row> |
| 8 | <b-row> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 9 | <b-col lg="10"> |
| 10 | <b-button @click="initModalSettings" variant="link"> |
| 11 | <icon-settings /> |
| 12 | Account policy settings |
| 13 | </b-button> |
| 14 | <b-button @click="initModalUser(null)" variant="primary"> |
| 15 | <icon-add /> |
| 16 | Add user |
| 17 | </b-button> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 18 | </b-col> |
| 19 | </b-row> |
| 20 | <b-row> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 21 | <b-col lg="10"> |
| 22 | <b-table bordered show-empty head-variant="dark" :items="tableItems"> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 23 | <template v-slot:head(actions)="data"></template> |
| 24 | <template v-slot:cell(actions)="data"> |
| 25 | <b-button |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 26 | aria-label="Edit user" |
| 27 | variant="link" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 28 | :disabled="!data.value.edit" |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 29 | @click="initModalUser(data.item)" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 30 | > |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 31 | <icon-edit /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 32 | </b-button> |
| 33 | <b-button |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 34 | aria-label="Delete user" |
| 35 | variant="link" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 36 | :disabled="!data.value.delete" |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 37 | @click="initModalDelete(data.item)" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 38 | > |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 39 | <icon-trashcan /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 40 | </b-button> |
| 41 | </template> |
| 42 | </b-table> |
| 43 | </b-col> |
| 44 | </b-row> |
| 45 | <b-row> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 46 | <b-col lg="8"> |
| 47 | <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3"> |
| 48 | View privilege role descriptions |
| 49 | </b-button> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 50 | <b-collapse id="collapse-role-table" class="mt-3"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 51 | <table-roles /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 52 | </b-collapse> |
| 53 | </b-col> |
| 54 | </b-row> |
| 55 | <!-- Modals --> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 56 | <modal-settings v-bind:settings="settings"></modal-settings> |
| 57 | <modal-user |
| 58 | v-bind:user="activeUser" |
| 59 | @ok="saveUser" |
| 60 | @hidden="clearActiveUser" |
| 61 | ></modal-user> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 62 | </b-container> |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 63 | </template> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 64 | |
| 65 | <script> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 66 | import IconTrashcan from "@carbon/icons-vue/es/trash-can/20"; |
| 67 | import IconEdit from "@carbon/icons-vue/es/edit/20"; |
| 68 | import IconAdd from "@carbon/icons-vue/es/add--alt/20"; |
| 69 | import IconSettings from "@carbon/icons-vue/es/settings/20"; |
| 70 | |
| 71 | import TableRoles from "./TableRoles"; |
| 72 | import ModalUser from "./ModalUser"; |
| 73 | import ModalSettings from "./ModalSettings"; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 74 | |
| 75 | export default { |
| 76 | name: "local-users", |
| 77 | components: { |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 78 | IconAdd, |
| 79 | IconEdit, |
| 80 | IconSettings, |
| 81 | IconTrashcan, |
| 82 | ModalSettings, |
| 83 | ModalUser, |
| 84 | TableRoles |
| 85 | }, |
| 86 | data() { |
| 87 | return { |
| 88 | activeUser: null, |
| 89 | settings: null |
| 90 | }; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 91 | }, |
| 92 | created() { |
| 93 | this.getUsers(); |
| 94 | }, |
| 95 | computed: { |
| 96 | allUsers() { |
| 97 | return this.$store.getters["localUsers/allUsers"]; |
| 98 | }, |
| 99 | tableItems() { |
| 100 | // transform user data to table data |
| 101 | return this.allUsers.map(user => { |
| 102 | return { |
| 103 | username: user.UserName, |
| 104 | privilege: user.RoleId, |
| 105 | status: user.Locked |
| 106 | ? "Locked" |
| 107 | : user.Enabled |
| 108 | ? "Enabled" |
| 109 | : "Disabled", |
| 110 | actions: { |
| 111 | edit: true, |
| 112 | delete: user.UserName === "root" ? false : true |
| 113 | } |
| 114 | }; |
| 115 | }); |
| 116 | } |
| 117 | }, |
| 118 | methods: { |
| 119 | getUsers() { |
| 120 | this.$store.dispatch("localUsers/getUsers"); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame^] | 121 | }, |
| 122 | initModalUser(user) { |
| 123 | this.activeUser = user; |
| 124 | this.$bvModal.show("modal-user"); |
| 125 | }, |
| 126 | initModalDelete(user) { |
| 127 | this.$bvModal |
| 128 | .msgBoxConfirm( |
| 129 | `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`, |
| 130 | { |
| 131 | title: "Delete user", |
| 132 | okTitle: "Delete user" |
| 133 | } |
| 134 | ) |
| 135 | .then(deleteConfirmed => { |
| 136 | if (deleteConfirmed) { |
| 137 | this.deleteUser(user); |
| 138 | } |
| 139 | }); |
| 140 | }, |
| 141 | initModalSettings() { |
| 142 | if (this.settings) { |
| 143 | this.$bvModal.show("modal-settings"); |
| 144 | } else { |
| 145 | // fetch settings then show modal |
| 146 | } |
| 147 | }, |
| 148 | saveUser({ newUser, form }) { |
| 149 | if (newUser) { |
| 150 | this.$store.dispatch("localUsers/createUser", form); |
| 151 | } else { |
| 152 | this.$store.dispatch("localUsers/updateUser", form); |
| 153 | } |
| 154 | }, |
| 155 | deleteUser({ username }) { |
| 156 | this.$store.dispatch("localUsers/deleteUser", username); |
| 157 | }, |
| 158 | clearActiveUser() { |
| 159 | this.activeUser = null; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | }; |
| 163 | </script> |
| 164 | |
| 165 | <style lang="scss" scoped> |
| 166 | h1 { |
| 167 | margin-bottom: 2rem; |
| 168 | } |
| 169 | </style> |