blob: 31cc3571337b8744b640158384e9a4be6076fc9a [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
SurenNeware307382e2020-07-27 20:45:14 +053033 show-empty
Yoshie Muranaka183c2752020-02-12 11:30:49 -080034 no-select-on-click
35 :fields="fields"
36 :items="tableItems"
SurenNeware307382e2020-07-27 20:45:14 +053037 :empty-text="$t('global.table.emptyMessage')"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080038 @row-selected="onRowSelected($event, tableItems.length)"
39 >
40 <!-- Checkbox column -->
41 <template v-slot:head(checkbox)>
42 <b-form-checkbox
43 v-model="tableHeaderCheckboxModel"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050044 data-test-id="localUserManagement-checkbox-tableHeaderCheckbox"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080045 :indeterminate="tableHeaderCheckboxIndeterminate"
46 @change="onChangeHeaderCheckbox($refs.table)"
47 />
48 </template>
49 <template v-slot:cell(checkbox)="row">
50 <b-form-checkbox
51 v-model="row.rowSelected"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050052 data-test-id="localUserManagement-checkbox-toggleSelectRow"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080053 @change="toggleSelectRow($refs.table, row.index)"
54 />
55 </template>
56
57 <!-- table actions column -->
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080058 <template v-slot:cell(actions)="{ item }">
59 <table-row-action
60 v-for="(action, index) in item.actions"
61 :key="index"
62 :value="action.value"
63 :enabled="action.enabled"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080064 :title="action.title"
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080065 @click:tableAction="onTableRowAction($event, item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060066 >
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080067 <template v-slot:icon>
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050068 <icon-edit
69 v-if="action.value === 'edit'"
70 :data-test-id="
71 `localUserManagement-tableRowAction-edit-${index}`
72 "
73 />
74 <icon-trashcan
75 v-if="action.value === 'delete'"
76 :data-test-id="
77 `localUserManagement-tableRowAction-delete-${index}`
78 "
79 />
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080080 </template>
81 </table-row-action>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060082 </template>
83 </b-table>
84 </b-col>
85 </b-row>
86 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080087 <b-col xl="8">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050088 <b-button
89 v-b-toggle.collapse-role-table
90 data-test-id="localUserManagement-button-viewPrivilegeRoleDescriptions"
91 variant="link"
92 class="mt-3"
93 >
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080094 <icon-chevron />
Yoshie Muranaka80735e12020-04-28 09:48:59 -070095 {{ $t('pageLocalUserManagement.viewPrivilegeRoleDescriptions') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -080096 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060097 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080098 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060099 </b-collapse>
100 </b-col>
101 </b-row>
102 <!-- Modals -->
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800103 <modal-settings :settings="settings" @ok="saveAccountSettings" />
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800104 <modal-user
105 :user="activeUser"
106 :password-requirements="passwordRequirements"
107 @ok="saveUser"
Yoshie Muranaka791622b2020-04-17 13:55:16 -0700108 @hidden="activeUser = null"
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800109 />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600110 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -0600111</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600112
113<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -0600114import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
115import IconEdit from '@carbon/icons-vue/es/edit/20';
116import IconAdd from '@carbon/icons-vue/es/add--alt/20';
117import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800118import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800119
Derick Montaguee2fd1562019-12-20 13:26:53 -0600120import ModalUser from './ModalUser';
121import ModalSettings from './ModalSettings';
SurenNeware5e25e282020-07-08 15:57:23 +0530122import PageTitle from '@/components/Global/PageTitle';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800123import TableRoles from './TableRoles';
SurenNeware5e25e282020-07-08 15:57:23 +0530124import TableToolbar from '@/components/Global/TableToolbar';
125import TableRowAction from '@/components/Global/TableRowAction';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800126
SurenNeware5e25e282020-07-08 15:57:23 +0530127import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
128import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700129import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600130
131export default {
Derick Montague09e45cd2020-01-23 15:45:57 -0600132 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600133 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800134 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800135 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800136 IconEdit,
137 IconSettings,
138 IconTrashcan,
139 ModalSettings,
140 ModalUser,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800141 PageTitle,
Yoshie Muranaka8d129102019-12-19 09:51:55 -0800142 TableRoles,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800143 TableRowAction,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800144 TableToolbar
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800145 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700146 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800147 data() {
148 return {
149 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800150 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800151 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800152 key: 'checkbox'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800153 },
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800154 {
155 key: 'username',
156 label: this.$t('pageLocalUserManagement.table.username')
157 },
158 {
159 key: 'privilege',
160 label: this.$t('pageLocalUserManagement.table.privilege')
161 },
162 {
163 key: 'status',
164 label: this.$t('pageLocalUserManagement.table.status')
165 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800166 {
167 key: 'actions',
168 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530169 tdClass: 'text-right text-nowrap'
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800170 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800171 ],
172 tableToolbarActions: [
173 {
174 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800175 label: this.$t('global.action.delete')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800176 },
177 {
178 value: 'enable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800179 label: this.$t('global.action.enable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800180 },
181 {
182 value: 'disable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800183 label: this.$t('global.action.disable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800184 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800185 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800186 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600187 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600188 computed: {
189 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600190 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600191 },
192 tableItems() {
193 // transform user data to table data
194 return this.allUsers.map(user => {
195 return {
196 username: user.UserName,
197 privilege: user.RoleId,
198 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600199 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600200 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600201 ? 'Enabled'
202 : 'Disabled',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800203 actions: [
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800204 {
205 value: 'edit',
206 enabled: true,
207 title: this.$t('pageLocalUserManagement.editUser')
208 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800209 {
210 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800211 enabled: user.UserName === 'root' ? false : true,
Yoshie Muranaka29321652020-05-04 10:52:36 -0700212 title: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800213 }
214 ],
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800215 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600216 };
217 });
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800218 },
219 settings() {
220 return this.$store.getters['localUsers/accountSettings'];
221 },
222 passwordRequirements() {
223 return this.$store.getters['localUsers/accountPasswordRequirements'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600224 }
225 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600226 created() {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700227 this.startLoader();
228 this.$store.dispatch('localUsers/getUsers').finally(() => this.endLoader());
Yoshie Muranakafb78d192020-03-03 11:55:52 -0800229 this.$store.dispatch('localUsers/getAccountSettings');
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700230 this.$store.dispatch('localUsers/getAccountRoles');
Derick Montague09e45cd2020-01-23 15:45:57 -0600231 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700232 beforeRouteLeave(to, from, next) {
233 this.hideLoader();
234 next();
235 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600236 methods: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800237 initModalUser(user) {
238 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600239 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800240 },
241 initModalDelete(user) {
242 this.$bvModal
243 .msgBoxConfirm(
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800244 this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', {
245 user: user.username
246 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800247 {
Yoshie Muranaka29321652020-05-04 10:52:36 -0700248 title: this.$tc('pageLocalUserManagement.deleteUser'),
249 okTitle: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800250 }
251 )
252 .then(deleteConfirmed => {
253 if (deleteConfirmed) {
254 this.deleteUser(user);
255 }
256 });
257 },
258 initModalSettings() {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800259 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800260 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800261 saveUser({ isNewUser, userData }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700262 this.startLoader();
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800263 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800264 this.$store
265 .dispatch('localUsers/createUser', userData)
266 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700267 .catch(({ message }) => this.errorToast(message))
268 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800269 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800270 this.$store
271 .dispatch('localUsers/updateUser', userData)
272 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700273 .catch(({ message }) => this.errorToast(message))
274 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800275 }
276 },
277 deleteUser({ username }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700278 this.startLoader();
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800279 this.$store
280 .dispatch('localUsers/deleteUser', username)
281 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700282 .catch(({ message }) => this.errorToast(message))
283 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800284 },
285 onBatchAction(action) {
286 switch (action) {
287 case 'delete':
Yoshie Muranaka29321652020-05-04 10:52:36 -0700288 this.$bvModal
289 .msgBoxConfirm(
290 this.$tc(
291 'pageLocalUserManagement.modal.batchDeleteConfirmMessage',
292 this.selectedRows.length
293 ),
294 {
295 title: this.$tc(
296 'pageLocalUserManagement.deleteUser',
297 this.selectedRows.length
298 ),
299 okTitle: this.$tc(
300 'pageLocalUserManagement.deleteUser',
301 this.selectedRows.length
302 )
303 }
304 )
305 .then(deleteConfirmed => {
306 if (deleteConfirmed) {
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700307 this.startLoader();
Yoshie Muranaka29321652020-05-04 10:52:36 -0700308 this.$store
309 .dispatch('localUsers/deleteUsers', this.selectedRows)
310 .then(messages => {
311 messages.forEach(({ type, message }) => {
312 if (type === 'success') this.successToast(message);
313 if (type === 'error') this.errorToast(message);
314 });
315 })
316 .finally(() => this.endLoader());
317 }
318 });
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800319 break;
320 case 'enable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700321 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800322 this.$store
323 .dispatch('localUsers/enableUsers', this.selectedRows)
324 .then(messages => {
325 messages.forEach(({ type, message }) => {
326 if (type === 'success') this.successToast(message);
327 if (type === 'error') this.errorToast(message);
328 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700329 })
330 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800331 break;
332 case 'disable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700333 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800334 this.$store
335 .dispatch('localUsers/disableUsers', this.selectedRows)
336 .then(messages => {
337 messages.forEach(({ type, message }) => {
338 if (type === 'success') this.successToast(message);
339 if (type === 'error') this.errorToast(message);
340 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700341 })
342 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800343 break;
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800344 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800345 },
346 onTableRowAction(action, row) {
347 switch (action) {
348 case 'edit':
349 this.initModalUser(row);
350 break;
351 case 'delete':
352 this.initModalDelete(row);
353 break;
354 default:
355 break;
356 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800357 },
358 saveAccountSettings(settings) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700359 this.startLoader();
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800360 this.$store
361 .dispatch('localUsers/saveAccountSettings', settings)
362 .then(message => this.successToast(message))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700363 .catch(({ message }) => this.errorToast(message))
364 .finally(() => this.endLoader());
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600365 }
366 }
367};
368</script>
369
370<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800371.btn.collapsed {
372 svg {
373 transform: rotate(180deg);
374 }
375}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600376</style>