blob: 7906072edec63930e8ce00341301cc4789484a7c [file] [log] [blame]
Derick Montaguea2988f42020-01-17 13:46:30 -06001<template>
Yoshie Muranaka3111b6f2020-04-21 19:48:38 -07002 <b-container fluid="xl">
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 Muranaka996d2d52019-12-30 09:06:45 -08007 <icon-settings />
Yoshie Muranaka80735e12020-04-28 09:48:59 -07008 {{ $t('pageLocalUserManagement.accountPolicySettings') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -08009 </b-button>
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050010 <b-button
11 variant="primary"
12 data-test-id="localUserManagement-button-addUser"
13 @click="initModalUser(null)"
14 >
Yoshie Muranaka996d2d52019-12-30 09:06:45 -080015 <icon-add />
Yoshie Muranaka80735e12020-04-28 09:48:59 -070016 {{ $t('pageLocalUserManagement.addUser') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -080017 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060018 </b-col>
19 </b-row>
20 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080021 <b-col xl="9">
Yoshie Muranaka183c2752020-02-12 11:30:49 -080022 <table-toolbar
23 ref="toolbar"
24 :selected-items-count="selectedRows.length"
25 :actions="tableToolbarActions"
26 @clearSelected="clearSelectedRows($refs.table)"
27 @batchAction="onBatchAction"
28 />
29 <b-table
30 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053031 responsive="md"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080032 selectable
33 no-select-on-click
34 :fields="fields"
35 :items="tableItems"
36 @row-selected="onRowSelected($event, tableItems.length)"
37 >
38 <!-- Checkbox column -->
39 <template v-slot:head(checkbox)>
40 <b-form-checkbox
41 v-model="tableHeaderCheckboxModel"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050042 data-test-id="localUserManagement-checkbox-tableHeaderCheckbox"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080043 :indeterminate="tableHeaderCheckboxIndeterminate"
44 @change="onChangeHeaderCheckbox($refs.table)"
45 />
46 </template>
47 <template v-slot:cell(checkbox)="row">
48 <b-form-checkbox
49 v-model="row.rowSelected"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050050 data-test-id="localUserManagement-checkbox-toggleSelectRow"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080051 @change="toggleSelectRow($refs.table, row.index)"
52 />
53 </template>
54
55 <!-- table actions column -->
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080056 <template v-slot:cell(actions)="{ item }">
57 <table-row-action
58 v-for="(action, index) in item.actions"
59 :key="index"
60 :value="action.value"
61 :enabled="action.enabled"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080062 :title="action.title"
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080063 @click:tableAction="onTableRowAction($event, item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060064 >
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080065 <template v-slot:icon>
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050066 <icon-edit
67 v-if="action.value === 'edit'"
68 :data-test-id="
69 `localUserManagement-tableRowAction-edit-${index}`
70 "
71 />
72 <icon-trashcan
73 v-if="action.value === 'delete'"
74 :data-test-id="
75 `localUserManagement-tableRowAction-delete-${index}`
76 "
77 />
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080078 </template>
79 </table-row-action>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060080 </template>
81 </b-table>
82 </b-col>
83 </b-row>
84 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080085 <b-col xl="8">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050086 <b-button
87 v-b-toggle.collapse-role-table
88 data-test-id="localUserManagement-button-viewPrivilegeRoleDescriptions"
89 variant="link"
90 class="mt-3"
91 >
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080092 <icon-chevron />
Yoshie Muranaka80735e12020-04-28 09:48:59 -070093 {{ $t('pageLocalUserManagement.viewPrivilegeRoleDescriptions') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -080094 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060095 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080096 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060097 </b-collapse>
98 </b-col>
99 </b-row>
100 <!-- Modals -->
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800101 <modal-settings :settings="settings" @ok="saveAccountSettings" />
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800102 <modal-user
103 :user="activeUser"
104 :password-requirements="passwordRequirements"
105 @ok="saveUser"
Yoshie Muranaka791622b2020-04-17 13:55:16 -0700106 @hidden="activeUser = null"
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800107 />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600108 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -0600109</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600110
111<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -0600112import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
113import IconEdit from '@carbon/icons-vue/es/edit/20';
114import IconAdd from '@carbon/icons-vue/es/add--alt/20';
115import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800116import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800117
Derick Montaguee2fd1562019-12-20 13:26:53 -0600118import ModalUser from './ModalUser';
119import ModalSettings from './ModalSettings';
SurenNeware5e25e282020-07-08 15:57:23 +0530120import PageTitle from '@/components/Global/PageTitle';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800121import TableRoles from './TableRoles';
SurenNeware5e25e282020-07-08 15:57:23 +0530122import TableToolbar from '@/components/Global/TableToolbar';
123import TableRowAction from '@/components/Global/TableRowAction';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800124
SurenNeware5e25e282020-07-08 15:57:23 +0530125import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
126import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700127import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600128
129export default {
Derick Montague09e45cd2020-01-23 15:45:57 -0600130 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600131 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800132 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800133 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800134 IconEdit,
135 IconSettings,
136 IconTrashcan,
137 ModalSettings,
138 ModalUser,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800139 PageTitle,
Yoshie Muranaka8d129102019-12-19 09:51:55 -0800140 TableRoles,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800141 TableRowAction,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800142 TableToolbar
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800143 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700144 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800145 data() {
146 return {
147 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800148 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800149 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800150 key: 'checkbox'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800151 },
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800152 {
153 key: 'username',
154 label: this.$t('pageLocalUserManagement.table.username')
155 },
156 {
157 key: 'privilege',
158 label: this.$t('pageLocalUserManagement.table.privilege')
159 },
160 {
161 key: 'status',
162 label: this.$t('pageLocalUserManagement.table.status')
163 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800164 {
165 key: 'actions',
166 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530167 tdClass: 'text-right text-nowrap'
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800168 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800169 ],
170 tableToolbarActions: [
171 {
172 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800173 label: this.$t('global.action.delete')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800174 },
175 {
176 value: 'enable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800177 label: this.$t('global.action.enable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800178 },
179 {
180 value: 'disable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800181 label: this.$t('global.action.disable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800182 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800183 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800184 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600185 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600186 computed: {
187 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600188 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600189 },
190 tableItems() {
191 // transform user data to table data
192 return this.allUsers.map(user => {
193 return {
194 username: user.UserName,
195 privilege: user.RoleId,
196 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600197 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600198 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600199 ? 'Enabled'
200 : 'Disabled',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800201 actions: [
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800202 {
203 value: 'edit',
204 enabled: true,
205 title: this.$t('pageLocalUserManagement.editUser')
206 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800207 {
208 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800209 enabled: user.UserName === 'root' ? false : true,
Yoshie Muranaka29321652020-05-04 10:52:36 -0700210 title: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800211 }
212 ],
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800213 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600214 };
215 });
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800216 },
217 settings() {
218 return this.$store.getters['localUsers/accountSettings'];
219 },
220 passwordRequirements() {
221 return this.$store.getters['localUsers/accountPasswordRequirements'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600222 }
223 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600224 created() {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700225 this.startLoader();
226 this.$store.dispatch('localUsers/getUsers').finally(() => this.endLoader());
Yoshie Muranakafb78d192020-03-03 11:55:52 -0800227 this.$store.dispatch('localUsers/getAccountSettings');
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700228 this.$store.dispatch('localUsers/getAccountRoles');
Derick Montague09e45cd2020-01-23 15:45:57 -0600229 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700230 beforeRouteLeave(to, from, next) {
231 this.hideLoader();
232 next();
233 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600234 methods: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800235 initModalUser(user) {
236 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600237 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800238 },
239 initModalDelete(user) {
240 this.$bvModal
241 .msgBoxConfirm(
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800242 this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', {
243 user: user.username
244 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800245 {
Yoshie Muranaka29321652020-05-04 10:52:36 -0700246 title: this.$tc('pageLocalUserManagement.deleteUser'),
247 okTitle: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800248 }
249 )
250 .then(deleteConfirmed => {
251 if (deleteConfirmed) {
252 this.deleteUser(user);
253 }
254 });
255 },
256 initModalSettings() {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800257 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800258 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800259 saveUser({ isNewUser, userData }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700260 this.startLoader();
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800261 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800262 this.$store
263 .dispatch('localUsers/createUser', userData)
264 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700265 .catch(({ message }) => this.errorToast(message))
266 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800267 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800268 this.$store
269 .dispatch('localUsers/updateUser', userData)
270 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700271 .catch(({ message }) => this.errorToast(message))
272 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800273 }
274 },
275 deleteUser({ username }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700276 this.startLoader();
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800277 this.$store
278 .dispatch('localUsers/deleteUser', username)
279 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700280 .catch(({ message }) => this.errorToast(message))
281 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800282 },
283 onBatchAction(action) {
284 switch (action) {
285 case 'delete':
Yoshie Muranaka29321652020-05-04 10:52:36 -0700286 this.$bvModal
287 .msgBoxConfirm(
288 this.$tc(
289 'pageLocalUserManagement.modal.batchDeleteConfirmMessage',
290 this.selectedRows.length
291 ),
292 {
293 title: this.$tc(
294 'pageLocalUserManagement.deleteUser',
295 this.selectedRows.length
296 ),
297 okTitle: this.$tc(
298 'pageLocalUserManagement.deleteUser',
299 this.selectedRows.length
300 )
301 }
302 )
303 .then(deleteConfirmed => {
304 if (deleteConfirmed) {
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700305 this.startLoader();
Yoshie Muranaka29321652020-05-04 10:52:36 -0700306 this.$store
307 .dispatch('localUsers/deleteUsers', this.selectedRows)
308 .then(messages => {
309 messages.forEach(({ type, message }) => {
310 if (type === 'success') this.successToast(message);
311 if (type === 'error') this.errorToast(message);
312 });
313 })
314 .finally(() => this.endLoader());
315 }
316 });
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800317 break;
318 case 'enable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700319 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800320 this.$store
321 .dispatch('localUsers/enableUsers', this.selectedRows)
322 .then(messages => {
323 messages.forEach(({ type, message }) => {
324 if (type === 'success') this.successToast(message);
325 if (type === 'error') this.errorToast(message);
326 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700327 })
328 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800329 break;
330 case 'disable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700331 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800332 this.$store
333 .dispatch('localUsers/disableUsers', this.selectedRows)
334 .then(messages => {
335 messages.forEach(({ type, message }) => {
336 if (type === 'success') this.successToast(message);
337 if (type === 'error') this.errorToast(message);
338 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700339 })
340 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800341 break;
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800342 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800343 },
344 onTableRowAction(action, row) {
345 switch (action) {
346 case 'edit':
347 this.initModalUser(row);
348 break;
349 case 'delete':
350 this.initModalDelete(row);
351 break;
352 default:
353 break;
354 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800355 },
356 saveAccountSettings(settings) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700357 this.startLoader();
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800358 this.$store
359 .dispatch('localUsers/saveAccountSettings', settings)
360 .then(message => this.successToast(message))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700361 .catch(({ message }) => this.errorToast(message))
362 .finally(() => this.endLoader());
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600363 }
364 }
365};
366</script>
367
368<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800369.btn.collapsed {
370 svg {
371 transform: rotate(180deg);
372 }
373}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600374</style>