blob: 957ea137a560720e9af009f6c0c32fc6c04b392b [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"
31 selectable
32 no-select-on-click
33 :fields="fields"
34 :items="tableItems"
35 @row-selected="onRowSelected($event, tableItems.length)"
36 >
37 <!-- Checkbox column -->
38 <template v-slot:head(checkbox)>
39 <b-form-checkbox
40 v-model="tableHeaderCheckboxModel"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050041 data-test-id="localUserManagement-checkbox-tableHeaderCheckbox"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080042 :indeterminate="tableHeaderCheckboxIndeterminate"
43 @change="onChangeHeaderCheckbox($refs.table)"
44 />
45 </template>
46 <template v-slot:cell(checkbox)="row">
47 <b-form-checkbox
48 v-model="row.rowSelected"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050049 data-test-id="localUserManagement-checkbox-toggleSelectRow"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080050 @change="toggleSelectRow($refs.table, row.index)"
51 />
52 </template>
53
54 <!-- table actions column -->
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080055 <template v-slot:cell(actions)="{ item }">
56 <table-row-action
57 v-for="(action, index) in item.actions"
58 :key="index"
59 :value="action.value"
60 :enabled="action.enabled"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080061 :title="action.title"
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080062 @click:tableAction="onTableRowAction($event, item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060063 >
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080064 <template v-slot:icon>
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050065 <icon-edit
66 v-if="action.value === 'edit'"
67 :data-test-id="
68 `localUserManagement-tableRowAction-edit-${index}`
69 "
70 />
71 <icon-trashcan
72 v-if="action.value === 'delete'"
73 :data-test-id="
74 `localUserManagement-tableRowAction-delete-${index}`
75 "
76 />
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080077 </template>
78 </table-row-action>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060079 </template>
80 </b-table>
81 </b-col>
82 </b-row>
83 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080084 <b-col xl="8">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050085 <b-button
86 v-b-toggle.collapse-role-table
87 data-test-id="localUserManagement-button-viewPrivilegeRoleDescriptions"
88 variant="link"
89 class="mt-3"
90 >
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080091 <icon-chevron />
Yoshie Muranaka80735e12020-04-28 09:48:59 -070092 {{ $t('pageLocalUserManagement.viewPrivilegeRoleDescriptions') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -080093 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060094 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080095 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060096 </b-collapse>
97 </b-col>
98 </b-row>
99 <!-- Modals -->
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800100 <modal-settings :settings="settings" @ok="saveAccountSettings" />
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800101 <modal-user
102 :user="activeUser"
103 :password-requirements="passwordRequirements"
104 @ok="saveUser"
Yoshie Muranaka791622b2020-04-17 13:55:16 -0700105 @hidden="activeUser = null"
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800106 />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600107 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -0600108</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600109
110<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -0600111import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
112import IconEdit from '@carbon/icons-vue/es/edit/20';
113import IconAdd from '@carbon/icons-vue/es/add--alt/20';
114import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800115import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800116
Derick Montaguee2fd1562019-12-20 13:26:53 -0600117import ModalUser from './ModalUser';
118import ModalSettings from './ModalSettings';
119import PageTitle from '../../../components/Global/PageTitle';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800120import TableRoles from './TableRoles';
121import TableToolbar from '../../../components/Global/TableToolbar';
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700122import TableRowAction from '../../../components/Global/TableRowAction';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800123
124import BVTableSelectableMixin from '../../../components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800125import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700126import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600127
128export default {
Derick Montague09e45cd2020-01-23 15:45:57 -0600129 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600130 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800131 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800132 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800133 IconEdit,
134 IconSettings,
135 IconTrashcan,
136 ModalSettings,
137 ModalUser,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800138 PageTitle,
Yoshie Muranaka8d129102019-12-19 09:51:55 -0800139 TableRoles,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800140 TableRowAction,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800141 TableToolbar
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800142 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700143 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800144 data() {
145 return {
146 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800147 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800148 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800149 key: 'checkbox'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800150 },
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800151 {
152 key: 'username',
153 label: this.$t('pageLocalUserManagement.table.username')
154 },
155 {
156 key: 'privilege',
157 label: this.$t('pageLocalUserManagement.table.privilege')
158 },
159 {
160 key: 'status',
161 label: this.$t('pageLocalUserManagement.table.status')
162 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800163 {
164 key: 'actions',
165 label: '',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800166 tdClass: 'text-right'
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800167 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800168 ],
169 tableToolbarActions: [
170 {
171 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800172 label: this.$t('global.action.delete')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800173 },
174 {
175 value: 'enable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800176 label: this.$t('global.action.enable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800177 },
178 {
179 value: 'disable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800180 label: this.$t('global.action.disable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800181 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800182 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800183 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600184 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600185 computed: {
186 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600187 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600188 },
189 tableItems() {
190 // transform user data to table data
191 return this.allUsers.map(user => {
192 return {
193 username: user.UserName,
194 privilege: user.RoleId,
195 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600196 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600197 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600198 ? 'Enabled'
199 : 'Disabled',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800200 actions: [
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800201 {
202 value: 'edit',
203 enabled: true,
204 title: this.$t('pageLocalUserManagement.editUser')
205 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800206 {
207 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800208 enabled: user.UserName === 'root' ? false : true,
Yoshie Muranaka29321652020-05-04 10:52:36 -0700209 title: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800210 }
211 ],
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800212 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600213 };
214 });
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800215 },
216 settings() {
217 return this.$store.getters['localUsers/accountSettings'];
218 },
219 passwordRequirements() {
220 return this.$store.getters['localUsers/accountPasswordRequirements'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600221 }
222 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600223 created() {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700224 this.startLoader();
225 this.$store.dispatch('localUsers/getUsers').finally(() => this.endLoader());
Yoshie Muranakafb78d192020-03-03 11:55:52 -0800226 this.$store.dispatch('localUsers/getAccountSettings');
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700227 this.$store.dispatch('localUsers/getAccountRoles');
Derick Montague09e45cd2020-01-23 15:45:57 -0600228 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700229 beforeRouteLeave(to, from, next) {
230 this.hideLoader();
231 next();
232 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600233 methods: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800234 initModalUser(user) {
235 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600236 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800237 },
238 initModalDelete(user) {
239 this.$bvModal
240 .msgBoxConfirm(
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800241 this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', {
242 user: user.username
243 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800244 {
Yoshie Muranaka29321652020-05-04 10:52:36 -0700245 title: this.$tc('pageLocalUserManagement.deleteUser'),
246 okTitle: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800247 }
248 )
249 .then(deleteConfirmed => {
250 if (deleteConfirmed) {
251 this.deleteUser(user);
252 }
253 });
254 },
255 initModalSettings() {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800256 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800257 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800258 saveUser({ isNewUser, userData }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700259 this.startLoader();
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800260 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800261 this.$store
262 .dispatch('localUsers/createUser', userData)
263 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700264 .catch(({ message }) => this.errorToast(message))
265 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800266 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800267 this.$store
268 .dispatch('localUsers/updateUser', userData)
269 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700270 .catch(({ message }) => this.errorToast(message))
271 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800272 }
273 },
274 deleteUser({ username }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700275 this.startLoader();
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800276 this.$store
277 .dispatch('localUsers/deleteUser', username)
278 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700279 .catch(({ message }) => this.errorToast(message))
280 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800281 },
282 onBatchAction(action) {
283 switch (action) {
284 case 'delete':
Yoshie Muranaka29321652020-05-04 10:52:36 -0700285 this.$bvModal
286 .msgBoxConfirm(
287 this.$tc(
288 'pageLocalUserManagement.modal.batchDeleteConfirmMessage',
289 this.selectedRows.length
290 ),
291 {
292 title: this.$tc(
293 'pageLocalUserManagement.deleteUser',
294 this.selectedRows.length
295 ),
296 okTitle: this.$tc(
297 'pageLocalUserManagement.deleteUser',
298 this.selectedRows.length
299 )
300 }
301 )
302 .then(deleteConfirmed => {
303 if (deleteConfirmed) {
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700304 this.startLoader();
Yoshie Muranaka29321652020-05-04 10:52:36 -0700305 this.$store
306 .dispatch('localUsers/deleteUsers', this.selectedRows)
307 .then(messages => {
308 messages.forEach(({ type, message }) => {
309 if (type === 'success') this.successToast(message);
310 if (type === 'error') this.errorToast(message);
311 });
312 })
313 .finally(() => this.endLoader());
314 }
315 });
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800316 break;
317 case 'enable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700318 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800319 this.$store
320 .dispatch('localUsers/enableUsers', this.selectedRows)
321 .then(messages => {
322 messages.forEach(({ type, message }) => {
323 if (type === 'success') this.successToast(message);
324 if (type === 'error') this.errorToast(message);
325 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700326 })
327 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800328 break;
329 case 'disable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700330 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800331 this.$store
332 .dispatch('localUsers/disableUsers', this.selectedRows)
333 .then(messages => {
334 messages.forEach(({ type, message }) => {
335 if (type === 'success') this.successToast(message);
336 if (type === 'error') this.errorToast(message);
337 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700338 })
339 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800340 break;
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800341 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800342 },
343 onTableRowAction(action, row) {
344 switch (action) {
345 case 'edit':
346 this.initModalUser(row);
347 break;
348 case 'delete':
349 this.initModalDelete(row);
350 break;
351 default:
352 break;
353 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800354 },
355 saveAccountSettings(settings) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700356 this.startLoader();
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800357 this.$store
358 .dispatch('localUsers/saveAccountSettings', settings)
359 .then(message => this.successToast(message))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700360 .catch(({ message }) => this.errorToast(message))
361 .finally(() => this.endLoader());
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600362 }
363 }
364};
365</script>
366
367<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800368.btn.collapsed {
369 svg {
370 transform: rotate(180deg);
371 }
372}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600373</style>