blob: 5c2d7f1be8f4a41a27ebbc22e6a41030c72aa10d [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 -->
Derick Montague602e98a2020-10-21 16:20:00 -050042 <template #head(checkbox)>
Yoshie Muranaka183c2752020-02-12 11:30:49 -080043 <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>
Derick Montague602e98a2020-10-21 16:20:00 -050050 <template #cell(checkbox)="row">
Yoshie Muranaka183c2752020-02-12 11:30:49 -080051 <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 -->
Derick Montague602e98a2020-10-21 16:20:00 -050059 <template #cell(actions)="{ item }">
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080060 <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 >
Derick Montague602e98a2020-10-21 16:20:00 -050068 <template #icon>
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050069 <icon-edit
70 v-if="action.value === 'edit'"
Derick Montague602e98a2020-10-21 16:20:00 -050071 :data-test-id="`localUserManagement-tableRowAction-edit-${index}`"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050072 />
73 <icon-trashcan
74 v-if="action.value === 'delete'"
Derick Montague602e98a2020-10-21 16:20:00 -050075 :data-test-id="`localUserManagement-tableRowAction-delete-${index}`"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050076 />
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';
SurenNeware5e25e282020-07-08 15:57:23 +0530119import PageTitle from '@/components/Global/PageTitle';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800120import TableRoles from './TableRoles';
SurenNeware5e25e282020-07-08 15:57:23 +0530121import TableToolbar from '@/components/Global/TableToolbar';
122import TableRowAction from '@/components/Global/TableRowAction';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800123
SurenNeware5e25e282020-07-08 15:57:23 +0530124import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
125import 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,
Derick Montague602e98a2020-10-21 16:20:00 -0500141 TableToolbar,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800142 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700143 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Derick Montague602e98a2020-10-21 16:20:00 -0500144 beforeRouteLeave(to, from, next) {
145 this.hideLoader();
146 next();
147 },
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 {
Derick Montague602e98a2020-10-21 16:20:00 -0500153 key: 'checkbox',
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800154 },
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800155 {
156 key: 'username',
Derick Montague602e98a2020-10-21 16:20:00 -0500157 label: this.$t('pageLocalUserManagement.table.username'),
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800158 },
159 {
160 key: 'privilege',
Derick Montague602e98a2020-10-21 16:20:00 -0500161 label: this.$t('pageLocalUserManagement.table.privilege'),
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800162 },
163 {
164 key: 'status',
Derick Montague602e98a2020-10-21 16:20:00 -0500165 label: this.$t('pageLocalUserManagement.table.status'),
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800166 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800167 {
168 key: 'actions',
169 label: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500170 tdClass: 'text-right text-nowrap',
171 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800172 ],
173 tableToolbarActions: [
174 {
175 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500176 label: this.$t('global.action.delete'),
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800177 },
178 {
179 value: 'enable',
Derick Montague602e98a2020-10-21 16:20:00 -0500180 label: this.$t('global.action.enable'),
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800181 },
182 {
183 value: 'disable',
Derick Montague602e98a2020-10-21 16:20:00 -0500184 label: this.$t('global.action.disable'),
185 },
186 ],
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
Derick Montague602e98a2020-10-21 16:20:00 -0500195 return this.allUsers.map((user) => {
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600196 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,
Derick Montague602e98a2020-10-21 16:20:00 -0500208 title: this.$t('pageLocalUserManagement.editUser'),
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800209 },
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,
Derick Montague602e98a2020-10-21 16:20:00 -0500213 title: this.$tc('pageLocalUserManagement.deleteUser'),
214 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800215 ],
Derick Montague602e98a2020-10-21 16:20:00 -0500216 ...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'];
Derick Montague602e98a2020-10-21 16:20:00 -0500225 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600226 },
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 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', {
Derick Montague602e98a2020-10-21 16:20:00 -0500242 user: user.username,
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800243 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800244 {
Yoshie Muranaka29321652020-05-04 10:52:36 -0700245 title: this.$tc('pageLocalUserManagement.deleteUser'),
Derick Montague602e98a2020-10-21 16:20:00 -0500246 okTitle: this.$tc('pageLocalUserManagement.deleteUser'),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800247 }
248 )
Derick Montague602e98a2020-10-21 16:20:00 -0500249 .then((deleteConfirmed) => {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800250 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)
Derick Montague602e98a2020-10-21 16:20:00 -0500263 .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)
Derick Montague602e98a2020-10-21 16:20:00 -0500269 .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)
Derick Montague602e98a2020-10-21 16:20:00 -0500278 .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
Derick Montague602e98a2020-10-21 16:20:00 -0500299 ),
Yoshie Muranaka29321652020-05-04 10:52:36 -0700300 }
301 )
Derick Montague602e98a2020-10-21 16:20:00 -0500302 .then((deleteConfirmed) => {
Yoshie Muranaka29321652020-05-04 10:52:36 -0700303 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)
Derick Montague602e98a2020-10-21 16:20:00 -0500307 .then((messages) => {
Yoshie Muranaka29321652020-05-04 10:52:36 -0700308 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)
Derick Montague602e98a2020-10-21 16:20:00 -0500321 .then((messages) => {
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800322 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)
Derick Montague602e98a2020-10-21 16:20:00 -0500333 .then((messages) => {
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800334 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)
Derick Montague602e98a2020-10-21 16:20:00 -0500359 .then((message) => this.successToast(message))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700360 .catch(({ message }) => this.errorToast(message))
361 .finally(() => this.endLoader());
Derick Montague602e98a2020-10-21 16:20:00 -0500362 },
363 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600364};
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>