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