blob: 8797da7792713bc18ae68189ede7b6d941b4912b [file] [log] [blame]
Derick Montaguea2988f42020-01-17 13:46:30 -06001<template>
Yoshie Muranaka74f86872020-02-10 12:28:37 -08002 <b-container fluid>
Derick Montague09e45cd2020-01-23 15:45:57 -06003 <page-title />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -06004 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -08005 <b-col xl="9" class="text-right">
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -08006 <b-button variant="link" @click="initModalSettings">
Yoshie Muranaka463a5702019-12-04 09:09:36 -08007 Account policy settings
Yoshie Muranaka996d2d52019-12-30 09:06:45 -08008 <icon-settings />
Yoshie Muranaka463a5702019-12-04 09:09:36 -08009 </b-button>
Derick Montague09e45cd2020-01-23 15:45:57 -060010 <b-button variant="primary" @click="initModalUser(null)">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080011 Add user
Yoshie Muranaka996d2d52019-12-30 09:06:45 -080012 <icon-add />
Yoshie Muranaka463a5702019-12-04 09:09:36 -080013 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060014 </b-col>
15 </b-row>
16 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080017 <b-col xl="9">
Yoshie Muranaka183c2752020-02-12 11:30:49 -080018 <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 Muranaka0e893f02020-02-18 13:39:45 -080049 <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 Muranaka35080ac2020-01-17 15:38:57 -060056 >
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080057 <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 Muranaka35080ac2020-01-17 15:38:57 -060062 </template>
63 </b-table>
64 </b-col>
65 </b-row>
66 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080067 <b-col xl="8">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080068 <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3">
69 View privilege role descriptions
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080070 <icon-chevron />
Yoshie Muranaka463a5702019-12-04 09:09:36 -080071 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060072 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080073 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060074 </b-collapse>
75 </b-col>
76 </b-row>
77 <!-- Modals -->
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080078 <modal-settings :settings="settings"></modal-settings>
79 <modal-user :user="activeUser" @ok="saveUser"></modal-user>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060080 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -060081</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060082
83<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -060084import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
85import IconEdit from '@carbon/icons-vue/es/edit/20';
86import IconAdd from '@carbon/icons-vue/es/add--alt/20';
87import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080088import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -080089
Derick Montaguee2fd1562019-12-20 13:26:53 -060090import ModalUser from './ModalUser';
91import ModalSettings from './ModalSettings';
92import PageTitle from '../../../components/Global/PageTitle';
Yoshie Muranaka183c2752020-02-12 11:30:49 -080093import TableRoles from './TableRoles';
94import TableToolbar from '../../../components/Global/TableToolbar';
95
96import BVTableSelectableMixin from '../../../components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -080097import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080098import TableRowAction from '../../../components/Global/TableRowAction';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060099
100export default {
Derick Montague09e45cd2020-01-23 15:45:57 -0600101 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600102 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800103 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800104 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800105 IconEdit,
106 IconSettings,
107 IconTrashcan,
108 ModalSettings,
109 ModalUser,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800110 PageTitle,
Yoshie Muranaka8d129102019-12-19 09:51:55 -0800111 TableRoles,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800112 TableRowAction,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800113 TableToolbar
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800114 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800115 mixins: [BVTableSelectableMixin, BVToastMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800116 data() {
117 return {
118 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800119 settings: null,
120 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800121 {
122 key: 'checkbox',
123 label: '',
124 tdClass: 'table-cell__checkbox'
125 },
126 'checkbox',
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800127 'username',
128 'privilege',
129 'status',
130 {
131 key: 'actions',
132 label: '',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800133 tdClass: 'text-right'
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800134 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800135 ],
136 tableToolbarActions: [
137 {
138 value: 'delete',
139 labelKey: 'localUserManagement.tableActions.delete'
140 },
141 {
142 value: 'enable',
143 labelKey: 'localUserManagement.tableActions.enable'
144 },
145 {
146 value: 'disable',
147 labelKey: 'localUserManagement.tableActions.disable'
148 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800149 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800150 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600151 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600152 computed: {
153 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600154 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600155 },
156 tableItems() {
157 // transform user data to table data
158 return this.allUsers.map(user => {
159 return {
160 username: user.UserName,
161 privilege: user.RoleId,
162 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600163 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600164 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600165 ? 'Enabled'
166 : 'Disabled',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800167 actions: [
168 { value: 'edit', enabled: true },
169 {
170 value: 'delete',
171 enabled: user.UserName === 'root' ? false : true
172 }
173 ],
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800174 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600175 };
176 });
177 }
178 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600179 created() {
180 this.getUsers();
181 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600182 methods: {
183 getUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600184 this.$store.dispatch('localUsers/getUsers');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800185 },
186 initModalUser(user) {
187 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600188 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800189 },
190 initModalDelete(user) {
191 this.$bvModal
192 .msgBoxConfirm(
193 `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`,
194 {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600195 title: 'Delete user',
196 okTitle: 'Delete user'
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800197 }
198 )
199 .then(deleteConfirmed => {
200 if (deleteConfirmed) {
201 this.deleteUser(user);
202 }
203 });
204 },
205 initModalSettings() {
206 if (this.settings) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600207 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800208 } else {
209 // fetch settings then show modal
210 }
211 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800212 saveUser({ isNewUser, userData }) {
213 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800214 this.$store
215 .dispatch('localUsers/createUser', userData)
216 .then(success => this.successToast(success))
217 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800218 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800219 this.$store
220 .dispatch('localUsers/updateUser', userData)
221 .then(success => this.successToast(success))
222 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800223 }
224 },
225 deleteUser({ username }) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800226 this.$store
227 .dispatch('localUsers/deleteUser', username)
228 .then(success => this.successToast(success))
229 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800230 },
231 onBatchAction(action) {
232 switch (action) {
233 case 'delete':
234 this.$store
235 .dispatch('localUsers/deleteUsers', this.selectedRows)
236 .then(messages => {
237 messages.forEach(({ type, message }) => {
238 if (type === 'success') this.successToast(message);
239 if (type === 'error') this.errorToast(message);
240 });
241 });
242 break;
243 case 'enable':
244 this.$store
245 .dispatch('localUsers/enableUsers', this.selectedRows)
246 .then(messages => {
247 messages.forEach(({ type, message }) => {
248 if (type === 'success') this.successToast(message);
249 if (type === 'error') this.errorToast(message);
250 });
251 });
252 break;
253 case 'disable':
254 this.$store
255 .dispatch('localUsers/disableUsers', this.selectedRows)
256 .then(messages => {
257 messages.forEach(({ type, message }) => {
258 if (type === 'success') this.successToast(message);
259 if (type === 'error') this.errorToast(message);
260 });
261 });
262 break;
263 default:
264 break;
265 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800266 },
267 onTableRowAction(action, row) {
268 switch (action) {
269 case 'edit':
270 this.initModalUser(row);
271 break;
272 case 'delete':
273 this.initModalDelete(row);
274 break;
275 default:
276 break;
277 }
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600278 }
279 }
280};
281</script>
282
283<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800284.btn.collapsed {
285 svg {
286 transform: rotate(180deg);
287 }
288}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600289</style>