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