Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 2 | <b-container fluid> |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 3 | <page-title /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 4 | <b-row> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 5 | <b-col xl="9" class="text-right"> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 6 | <b-button variant="link" @click="initModalSettings"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 7 | Account policy settings |
Yoshie Muranaka | 996d2d5 | 2019-12-30 09:06:45 -0800 | [diff] [blame] | 8 | <icon-settings /> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 9 | </b-button> |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 10 | <b-button variant="primary" @click="initModalUser(null)"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 11 | Add user |
Yoshie Muranaka | 996d2d5 | 2019-12-30 09:06:45 -0800 | [diff] [blame] | 12 | <icon-add /> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 13 | </b-button> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 14 | </b-col> |
| 15 | </b-row> |
| 16 | <b-row> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 17 | <b-col xl="9"> |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 18 | <table-toolbar |
| 19 | ref="toolbar" |
| 20 | :selected-items-count="selectedRows.length" |
| 21 | :actions="tableToolbarActions" |
| 22 | @clearSelected="clearSelectedRows($refs.table)" |
| 23 | @batchAction="onBatchAction" |
| 24 | /> |
| 25 | <b-table |
| 26 | ref="table" |
| 27 | selectable |
| 28 | no-select-on-click |
| 29 | :fields="fields" |
| 30 | :items="tableItems" |
| 31 | @row-selected="onRowSelected($event, tableItems.length)" |
| 32 | > |
| 33 | <!-- Checkbox column --> |
| 34 | <template v-slot:head(checkbox)> |
| 35 | <b-form-checkbox |
| 36 | v-model="tableHeaderCheckboxModel" |
| 37 | :indeterminate="tableHeaderCheckboxIndeterminate" |
| 38 | @change="onChangeHeaderCheckbox($refs.table)" |
| 39 | /> |
| 40 | </template> |
| 41 | <template v-slot:cell(checkbox)="row"> |
| 42 | <b-form-checkbox |
| 43 | v-model="row.rowSelected" |
| 44 | @change="toggleSelectRow($refs.table, row.index)" |
| 45 | /> |
| 46 | </template> |
| 47 | |
| 48 | <!-- table actions column --> |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 49 | <template v-slot:cell(actions)="{ item }"> |
| 50 | <table-row-action |
| 51 | v-for="(action, index) in item.actions" |
| 52 | :key="index" |
| 53 | :value="action.value" |
| 54 | :enabled="action.enabled" |
| 55 | @click:tableAction="onTableRowAction($event, item)" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 56 | > |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 57 | <template v-slot:icon> |
| 58 | <icon-edit v-if="action.value === 'edit'" /> |
| 59 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 60 | </template> |
| 61 | </table-row-action> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 62 | </template> |
| 63 | </b-table> |
| 64 | </b-col> |
| 65 | </b-row> |
| 66 | <b-row> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 67 | <b-col xl="8"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 68 | <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3"> |
| 69 | View privilege role descriptions |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 70 | <icon-chevron /> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 71 | </b-button> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 72 | <b-collapse id="collapse-role-table" class="mt-3"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 73 | <table-roles /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 74 | </b-collapse> |
| 75 | </b-col> |
| 76 | </b-row> |
| 77 | <!-- Modals --> |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame^] | 78 | <modal-settings :settings="settings" /> |
| 79 | <modal-user |
| 80 | :user="activeUser" |
| 81 | :password-requirements="passwordRequirements" |
| 82 | @ok="saveUser" |
| 83 | /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 84 | </b-container> |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 85 | </template> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 86 | |
| 87 | <script> |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 88 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 89 | import IconEdit from '@carbon/icons-vue/es/edit/20'; |
| 90 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| 91 | import IconSettings from '@carbon/icons-vue/es/settings/20'; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 92 | import IconChevron from '@carbon/icons-vue/es/chevron--up/20'; |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 93 | |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 94 | import ModalUser from './ModalUser'; |
| 95 | import ModalSettings from './ModalSettings'; |
| 96 | import PageTitle from '../../../components/Global/PageTitle'; |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 97 | import TableRoles from './TableRoles'; |
| 98 | import TableToolbar from '../../../components/Global/TableToolbar'; |
| 99 | |
| 100 | import BVTableSelectableMixin from '../../../components/Mixins/BVTableSelectableMixin'; |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 101 | import BVToastMixin from '../../../components/Mixins/BVToastMixin'; |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 102 | import TableRowAction from '../../../components/Global/TableRowAction'; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 103 | |
| 104 | export default { |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 105 | name: 'LocalUsers', |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 106 | components: { |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 107 | IconAdd, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 108 | IconChevron, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 109 | IconEdit, |
| 110 | IconSettings, |
| 111 | IconTrashcan, |
| 112 | ModalSettings, |
| 113 | ModalUser, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 114 | PageTitle, |
Yoshie Muranaka | 8d12910 | 2019-12-19 09:51:55 -0800 | [diff] [blame] | 115 | TableRoles, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 116 | TableRowAction, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 117 | TableToolbar |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 118 | }, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 119 | mixins: [BVTableSelectableMixin, BVToastMixin], |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 120 | data() { |
| 121 | return { |
| 122 | activeUser: null, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 123 | fields: [ |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 124 | { |
| 125 | key: 'checkbox', |
| 126 | label: '', |
| 127 | tdClass: 'table-cell__checkbox' |
| 128 | }, |
| 129 | 'checkbox', |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 130 | 'username', |
| 131 | 'privilege', |
| 132 | 'status', |
| 133 | { |
| 134 | key: 'actions', |
| 135 | label: '', |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 136 | tdClass: 'text-right' |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 137 | } |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 138 | ], |
| 139 | tableToolbarActions: [ |
| 140 | { |
| 141 | value: 'delete', |
| 142 | labelKey: 'localUserManagement.tableActions.delete' |
| 143 | }, |
| 144 | { |
| 145 | value: 'enable', |
| 146 | labelKey: 'localUserManagement.tableActions.enable' |
| 147 | }, |
| 148 | { |
| 149 | value: 'disable', |
| 150 | labelKey: 'localUserManagement.tableActions.disable' |
| 151 | } |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 152 | ] |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 153 | }; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 154 | }, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 155 | computed: { |
| 156 | allUsers() { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 157 | return this.$store.getters['localUsers/allUsers']; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 158 | }, |
| 159 | tableItems() { |
| 160 | // transform user data to table data |
| 161 | return this.allUsers.map(user => { |
| 162 | return { |
| 163 | username: user.UserName, |
| 164 | privilege: user.RoleId, |
| 165 | status: user.Locked |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 166 | ? 'Locked' |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 167 | : user.Enabled |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 168 | ? 'Enabled' |
| 169 | : 'Disabled', |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 170 | actions: [ |
| 171 | { value: 'edit', enabled: true }, |
| 172 | { |
| 173 | value: 'delete', |
| 174 | enabled: user.UserName === 'root' ? false : true |
| 175 | } |
| 176 | ], |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 177 | ...user |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 178 | }; |
| 179 | }); |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame^] | 180 | }, |
| 181 | settings() { |
| 182 | return this.$store.getters['localUsers/accountSettings']; |
| 183 | }, |
| 184 | passwordRequirements() { |
| 185 | return this.$store.getters['localUsers/accountPasswordRequirements']; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 186 | } |
| 187 | }, |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 188 | created() { |
| 189 | this.getUsers(); |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame^] | 190 | this.getAccountSettings(); |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 191 | }, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 192 | methods: { |
| 193 | getUsers() { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 194 | this.$store.dispatch('localUsers/getUsers'); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 195 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame^] | 196 | getAccountSettings() { |
| 197 | this.$store.dispatch('localUsers/getAccountSettings'); |
| 198 | }, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 199 | initModalUser(user) { |
| 200 | this.activeUser = user; |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 201 | this.$bvModal.show('modal-user'); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 202 | }, |
| 203 | initModalDelete(user) { |
| 204 | this.$bvModal |
| 205 | .msgBoxConfirm( |
| 206 | `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`, |
| 207 | { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 208 | title: 'Delete user', |
| 209 | okTitle: 'Delete user' |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 210 | } |
| 211 | ) |
| 212 | .then(deleteConfirmed => { |
| 213 | if (deleteConfirmed) { |
| 214 | this.deleteUser(user); |
| 215 | } |
| 216 | }); |
| 217 | }, |
| 218 | initModalSettings() { |
| 219 | if (this.settings) { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 220 | this.$bvModal.show('modal-settings'); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 221 | } else { |
| 222 | // fetch settings then show modal |
| 223 | } |
| 224 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 225 | saveUser({ isNewUser, userData }) { |
| 226 | if (isNewUser) { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 227 | this.$store |
| 228 | .dispatch('localUsers/createUser', userData) |
| 229 | .then(success => this.successToast(success)) |
| 230 | .catch(({ message }) => this.errorToast(message)); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 231 | } else { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 232 | this.$store |
| 233 | .dispatch('localUsers/updateUser', userData) |
| 234 | .then(success => this.successToast(success)) |
| 235 | .catch(({ message }) => this.errorToast(message)); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 236 | } |
| 237 | }, |
| 238 | deleteUser({ username }) { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 239 | this.$store |
| 240 | .dispatch('localUsers/deleteUser', username) |
| 241 | .then(success => this.successToast(success)) |
| 242 | .catch(({ message }) => this.errorToast(message)); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 243 | }, |
| 244 | onBatchAction(action) { |
| 245 | switch (action) { |
| 246 | case 'delete': |
| 247 | this.$store |
| 248 | .dispatch('localUsers/deleteUsers', this.selectedRows) |
| 249 | .then(messages => { |
| 250 | messages.forEach(({ type, message }) => { |
| 251 | if (type === 'success') this.successToast(message); |
| 252 | if (type === 'error') this.errorToast(message); |
| 253 | }); |
| 254 | }); |
| 255 | break; |
| 256 | case 'enable': |
| 257 | this.$store |
| 258 | .dispatch('localUsers/enableUsers', this.selectedRows) |
| 259 | .then(messages => { |
| 260 | messages.forEach(({ type, message }) => { |
| 261 | if (type === 'success') this.successToast(message); |
| 262 | if (type === 'error') this.errorToast(message); |
| 263 | }); |
| 264 | }); |
| 265 | break; |
| 266 | case 'disable': |
| 267 | this.$store |
| 268 | .dispatch('localUsers/disableUsers', this.selectedRows) |
| 269 | .then(messages => { |
| 270 | messages.forEach(({ type, message }) => { |
| 271 | if (type === 'success') this.successToast(message); |
| 272 | if (type === 'error') this.errorToast(message); |
| 273 | }); |
| 274 | }); |
| 275 | break; |
| 276 | default: |
| 277 | break; |
| 278 | } |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 279 | }, |
| 280 | onTableRowAction(action, row) { |
| 281 | switch (action) { |
| 282 | case 'edit': |
| 283 | this.initModalUser(row); |
| 284 | break; |
| 285 | case 'delete': |
| 286 | this.initModalDelete(row); |
| 287 | break; |
| 288 | default: |
| 289 | break; |
| 290 | } |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | }; |
| 294 | </script> |
| 295 | |
| 296 | <style lang="scss" scoped> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 297 | .btn.collapsed { |
| 298 | svg { |
| 299 | transform: rotate(180deg); |
| 300 | } |
| 301 | } |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 302 | </style> |