blob: 9978f4a75008c697e255474fe6e57666f3d1d152 [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
Sukanya Pandeyfde429e2020-09-14 20:48:39 +053035 hover
Yoshie Muranaka183c2752020-02-12 11:30:49 -080036 :fields="fields"
37 :items="tableItems"
SurenNeware307382e2020-07-27 20:45:14 +053038 :empty-text="$t('global.table.emptyMessage')"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080039 @row-selected="onRowSelected($event, tableItems.length)"
40 >
41 <!-- Checkbox column -->
42 <template v-slot:head(checkbox)>
43 <b-form-checkbox
44 v-model="tableHeaderCheckboxModel"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050045 data-test-id="localUserManagement-checkbox-tableHeaderCheckbox"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080046 :indeterminate="tableHeaderCheckboxIndeterminate"
47 @change="onChangeHeaderCheckbox($refs.table)"
48 />
49 </template>
50 <template v-slot:cell(checkbox)="row">
51 <b-form-checkbox
52 v-model="row.rowSelected"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050053 data-test-id="localUserManagement-checkbox-toggleSelectRow"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080054 @change="toggleSelectRow($refs.table, row.index)"
55 />
56 </template>
57
58 <!-- table actions column -->
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080059 <template v-slot:cell(actions)="{ item }">
60 <table-row-action
61 v-for="(action, index) in item.actions"
62 :key="index"
63 :value="action.value"
64 :enabled="action.enabled"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080065 :title="action.title"
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080066 @click:tableAction="onTableRowAction($event, item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060067 >
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080068 <template v-slot:icon>
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050069 <icon-edit
70 v-if="action.value === 'edit'"
71 :data-test-id="
72 `localUserManagement-tableRowAction-edit-${index}`
73 "
74 />
75 <icon-trashcan
76 v-if="action.value === 'delete'"
77 :data-test-id="
78 `localUserManagement-tableRowAction-delete-${index}`
79 "
80 />
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080081 </template>
82 </table-row-action>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060083 </template>
84 </b-table>
85 </b-col>
86 </b-row>
87 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080088 <b-col xl="8">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050089 <b-button
90 v-b-toggle.collapse-role-table
91 data-test-id="localUserManagement-button-viewPrivilegeRoleDescriptions"
92 variant="link"
93 class="mt-3"
94 >
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080095 <icon-chevron />
Yoshie Muranaka80735e12020-04-28 09:48:59 -070096 {{ $t('pageLocalUserManagement.viewPrivilegeRoleDescriptions') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -080097 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060098 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080099 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600100 </b-collapse>
101 </b-col>
102 </b-row>
103 <!-- Modals -->
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800104 <modal-settings :settings="settings" @ok="saveAccountSettings" />
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800105 <modal-user
106 :user="activeUser"
107 :password-requirements="passwordRequirements"
108 @ok="saveUser"
Yoshie Muranaka791622b2020-04-17 13:55:16 -0700109 @hidden="activeUser = null"
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800110 />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600111 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -0600112</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600113
114<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -0600115import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
116import IconEdit from '@carbon/icons-vue/es/edit/20';
117import IconAdd from '@carbon/icons-vue/es/add--alt/20';
118import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800119import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800120
Derick Montaguee2fd1562019-12-20 13:26:53 -0600121import ModalUser from './ModalUser';
122import ModalSettings from './ModalSettings';
SurenNeware5e25e282020-07-08 15:57:23 +0530123import PageTitle from '@/components/Global/PageTitle';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800124import TableRoles from './TableRoles';
SurenNeware5e25e282020-07-08 15:57:23 +0530125import TableToolbar from '@/components/Global/TableToolbar';
126import TableRowAction from '@/components/Global/TableRowAction';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800127
SurenNeware5e25e282020-07-08 15:57:23 +0530128import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
129import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700130import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600131
132export default {
Derick Montague09e45cd2020-01-23 15:45:57 -0600133 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600134 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800135 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800136 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800137 IconEdit,
138 IconSettings,
139 IconTrashcan,
140 ModalSettings,
141 ModalUser,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800142 PageTitle,
Yoshie Muranaka8d129102019-12-19 09:51:55 -0800143 TableRoles,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800144 TableRowAction,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800145 TableToolbar
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800146 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700147 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800148 data() {
149 return {
150 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800151 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800152 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800153 key: 'checkbox'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800154 },
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800155 {
156 key: 'username',
157 label: this.$t('pageLocalUserManagement.table.username')
158 },
159 {
160 key: 'privilege',
161 label: this.$t('pageLocalUserManagement.table.privilege')
162 },
163 {
164 key: 'status',
165 label: this.$t('pageLocalUserManagement.table.status')
166 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800167 {
168 key: 'actions',
169 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530170 tdClass: 'text-right text-nowrap'
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800171 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800172 ],
173 tableToolbarActions: [
174 {
175 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800176 label: this.$t('global.action.delete')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800177 },
178 {
179 value: 'enable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800180 label: this.$t('global.action.enable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800181 },
182 {
183 value: 'disable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800184 label: this.$t('global.action.disable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800185 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800186 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800187 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600188 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600189 computed: {
190 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600191 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600192 },
193 tableItems() {
194 // transform user data to table data
195 return this.allUsers.map(user => {
196 return {
197 username: user.UserName,
198 privilege: user.RoleId,
199 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600200 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600201 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600202 ? 'Enabled'
203 : 'Disabled',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800204 actions: [
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800205 {
206 value: 'edit',
207 enabled: true,
208 title: this.$t('pageLocalUserManagement.editUser')
209 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800210 {
211 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800212 enabled: user.UserName === 'root' ? false : true,
Yoshie Muranaka29321652020-05-04 10:52:36 -0700213 title: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800214 }
215 ],
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800216 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600217 };
218 });
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800219 },
220 settings() {
221 return this.$store.getters['localUsers/accountSettings'];
222 },
223 passwordRequirements() {
224 return this.$store.getters['localUsers/accountPasswordRequirements'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600225 }
226 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600227 created() {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700228 this.startLoader();
229 this.$store.dispatch('localUsers/getUsers').finally(() => this.endLoader());
Yoshie Muranakafb78d192020-03-03 11:55:52 -0800230 this.$store.dispatch('localUsers/getAccountSettings');
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700231 this.$store.dispatch('localUsers/getAccountRoles');
Derick Montague09e45cd2020-01-23 15:45:57 -0600232 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700233 beforeRouteLeave(to, from, next) {
234 this.hideLoader();
235 next();
236 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600237 methods: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800238 initModalUser(user) {
239 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600240 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800241 },
242 initModalDelete(user) {
243 this.$bvModal
244 .msgBoxConfirm(
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800245 this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', {
246 user: user.username
247 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800248 {
Yoshie Muranaka29321652020-05-04 10:52:36 -0700249 title: this.$tc('pageLocalUserManagement.deleteUser'),
250 okTitle: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800251 }
252 )
253 .then(deleteConfirmed => {
254 if (deleteConfirmed) {
255 this.deleteUser(user);
256 }
257 });
258 },
259 initModalSettings() {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800260 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800261 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800262 saveUser({ isNewUser, userData }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700263 this.startLoader();
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800264 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800265 this.$store
266 .dispatch('localUsers/createUser', userData)
267 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700268 .catch(({ message }) => this.errorToast(message))
269 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800270 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800271 this.$store
272 .dispatch('localUsers/updateUser', userData)
273 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700274 .catch(({ message }) => this.errorToast(message))
275 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800276 }
277 },
278 deleteUser({ username }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700279 this.startLoader();
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800280 this.$store
281 .dispatch('localUsers/deleteUser', username)
282 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700283 .catch(({ message }) => this.errorToast(message))
284 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800285 },
286 onBatchAction(action) {
287 switch (action) {
288 case 'delete':
Yoshie Muranaka29321652020-05-04 10:52:36 -0700289 this.$bvModal
290 .msgBoxConfirm(
291 this.$tc(
292 'pageLocalUserManagement.modal.batchDeleteConfirmMessage',
293 this.selectedRows.length
294 ),
295 {
296 title: this.$tc(
297 'pageLocalUserManagement.deleteUser',
298 this.selectedRows.length
299 ),
300 okTitle: this.$tc(
301 'pageLocalUserManagement.deleteUser',
302 this.selectedRows.length
303 )
304 }
305 )
306 .then(deleteConfirmed => {
307 if (deleteConfirmed) {
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700308 this.startLoader();
Yoshie Muranaka29321652020-05-04 10:52:36 -0700309 this.$store
310 .dispatch('localUsers/deleteUsers', this.selectedRows)
311 .then(messages => {
312 messages.forEach(({ type, message }) => {
313 if (type === 'success') this.successToast(message);
314 if (type === 'error') this.errorToast(message);
315 });
316 })
317 .finally(() => this.endLoader());
318 }
319 });
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800320 break;
321 case 'enable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700322 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800323 this.$store
324 .dispatch('localUsers/enableUsers', this.selectedRows)
325 .then(messages => {
326 messages.forEach(({ type, message }) => {
327 if (type === 'success') this.successToast(message);
328 if (type === 'error') this.errorToast(message);
329 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700330 })
331 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800332 break;
333 case 'disable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700334 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800335 this.$store
336 .dispatch('localUsers/disableUsers', this.selectedRows)
337 .then(messages => {
338 messages.forEach(({ type, message }) => {
339 if (type === 'success') this.successToast(message);
340 if (type === 'error') this.errorToast(message);
341 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700342 })
343 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800344 break;
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800345 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800346 },
347 onTableRowAction(action, row) {
348 switch (action) {
349 case 'edit':
350 this.initModalUser(row);
351 break;
352 case 'delete':
353 this.initModalDelete(row);
354 break;
355 default:
356 break;
357 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800358 },
359 saveAccountSettings(settings) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700360 this.startLoader();
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800361 this.$store
362 .dispatch('localUsers/saveAccountSettings', settings)
363 .then(message => this.successToast(message))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700364 .catch(({ message }) => this.errorToast(message))
365 .finally(() => this.endLoader());
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600366 }
367 }
368};
369</script>
370
371<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800372.btn.collapsed {
373 svg {
374 transform: rotate(180deg);
375 }
376}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600377</style>