blob: cf7cc221ef3d794c389c4164d520299d67a20cb9 [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>
Derick Montague09e45cd2020-01-23 15:45:57 -060010 <b-button variant="primary" @click="initModalUser(null)">
Yoshie Muranaka996d2d52019-12-30 09:06:45 -080011 <icon-add />
Yoshie Muranaka80735e12020-04-28 09:48:59 -070012 {{ $t('pageLocalUserManagement.addUser') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -080013 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060014 </b-col>
15 </b-row>
16 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080017 <b-col xl="9">
Yoshie Muranaka183c2752020-02-12 11:30:49 -080018 <table-toolbar
19 ref="toolbar"
20 :selected-items-count="selectedRows.length"
21 :actions="tableToolbarActions"
22 @clearSelected="clearSelectedRows($refs.table)"
23 @batchAction="onBatchAction"
24 />
25 <b-table
26 ref="table"
27 selectable
28 no-select-on-click
29 :fields="fields"
30 :items="tableItems"
31 @row-selected="onRowSelected($event, tableItems.length)"
32 >
33 <!-- Checkbox column -->
34 <template v-slot:head(checkbox)>
35 <b-form-checkbox
36 v-model="tableHeaderCheckboxModel"
37 :indeterminate="tableHeaderCheckboxIndeterminate"
38 @change="onChangeHeaderCheckbox($refs.table)"
39 />
40 </template>
41 <template v-slot:cell(checkbox)="row">
42 <b-form-checkbox
43 v-model="row.rowSelected"
44 @change="toggleSelectRow($refs.table, row.index)"
45 />
46 </template>
47
48 <!-- table actions column -->
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080049 <template v-slot:cell(actions)="{ item }">
50 <table-row-action
51 v-for="(action, index) in item.actions"
52 :key="index"
53 :value="action.value"
54 :enabled="action.enabled"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080055 :title="action.title"
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080056 @click:tableAction="onTableRowAction($event, item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060057 >
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080058 <template v-slot:icon>
59 <icon-edit v-if="action.value === 'edit'" />
60 <icon-trashcan v-if="action.value === 'delete'" />
61 </template>
62 </table-row-action>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060063 </template>
64 </b-table>
65 </b-col>
66 </b-row>
67 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080068 <b-col xl="8">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080069 <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3">
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080070 <icon-chevron />
Yoshie Muranaka80735e12020-04-28 09:48:59 -070071 {{ $t('pageLocalUserManagement.viewPrivilegeRoleDescriptions') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -080072 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060073 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080074 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060075 </b-collapse>
76 </b-col>
77 </b-row>
78 <!-- Modals -->
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080079 <modal-settings :settings="settings" @ok="saveAccountSettings" />
Yoshie Muranaka52b02232020-02-20 08:00:45 -080080 <modal-user
81 :user="activeUser"
82 :password-requirements="passwordRequirements"
83 @ok="saveUser"
Yoshie Muranaka791622b2020-04-17 13:55:16 -070084 @hidden="activeUser = null"
Yoshie Muranaka52b02232020-02-20 08:00:45 -080085 />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060086 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -060087</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060088
89<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -060090import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
91import IconEdit from '@carbon/icons-vue/es/edit/20';
92import IconAdd from '@carbon/icons-vue/es/add--alt/20';
93import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080094import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -080095
Derick Montaguee2fd1562019-12-20 13:26:53 -060096import ModalUser from './ModalUser';
97import ModalSettings from './ModalSettings';
98import PageTitle from '../../../components/Global/PageTitle';
Yoshie Muranaka183c2752020-02-12 11:30:49 -080099import TableRoles from './TableRoles';
100import TableToolbar from '../../../components/Global/TableToolbar';
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700101import TableRowAction from '../../../components/Global/TableRowAction';
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800102
103import BVTableSelectableMixin from '../../../components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800104import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700105import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600106
107export default {
Derick Montague09e45cd2020-01-23 15:45:57 -0600108 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600109 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800110 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800111 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800112 IconEdit,
113 IconSettings,
114 IconTrashcan,
115 ModalSettings,
116 ModalUser,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800117 PageTitle,
Yoshie Muranaka8d129102019-12-19 09:51:55 -0800118 TableRoles,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800119 TableRowAction,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800120 TableToolbar
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800121 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700122 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800123 data() {
124 return {
125 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800126 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800127 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800128 key: 'checkbox'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800129 },
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800130 {
131 key: 'username',
132 label: this.$t('pageLocalUserManagement.table.username')
133 },
134 {
135 key: 'privilege',
136 label: this.$t('pageLocalUserManagement.table.privilege')
137 },
138 {
139 key: 'status',
140 label: this.$t('pageLocalUserManagement.table.status')
141 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800142 {
143 key: 'actions',
144 label: '',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800145 tdClass: 'text-right'
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800146 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800147 ],
148 tableToolbarActions: [
149 {
150 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800151 label: this.$t('global.action.delete')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800152 },
153 {
154 value: 'enable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800155 label: this.$t('global.action.enable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800156 },
157 {
158 value: 'disable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800159 label: this.$t('global.action.disable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800160 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800161 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800162 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600163 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600164 computed: {
165 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600166 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600167 },
168 tableItems() {
169 // transform user data to table data
170 return this.allUsers.map(user => {
171 return {
172 username: user.UserName,
173 privilege: user.RoleId,
174 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600175 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600176 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600177 ? 'Enabled'
178 : 'Disabled',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800179 actions: [
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800180 {
181 value: 'edit',
182 enabled: true,
183 title: this.$t('pageLocalUserManagement.editUser')
184 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800185 {
186 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800187 enabled: user.UserName === 'root' ? false : true,
Yoshie Muranaka29321652020-05-04 10:52:36 -0700188 title: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800189 }
190 ],
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800191 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600192 };
193 });
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800194 },
195 settings() {
196 return this.$store.getters['localUsers/accountSettings'];
197 },
198 passwordRequirements() {
199 return this.$store.getters['localUsers/accountPasswordRequirements'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600200 }
201 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600202 created() {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700203 this.startLoader();
204 this.$store.dispatch('localUsers/getUsers').finally(() => this.endLoader());
Yoshie Muranakafb78d192020-03-03 11:55:52 -0800205 this.$store.dispatch('localUsers/getAccountSettings');
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700206 this.$store.dispatch('localUsers/getAccountRoles');
Derick Montague09e45cd2020-01-23 15:45:57 -0600207 },
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700208 beforeRouteLeave(to, from, next) {
209 this.hideLoader();
210 next();
211 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600212 methods: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800213 initModalUser(user) {
214 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600215 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800216 },
217 initModalDelete(user) {
218 this.$bvModal
219 .msgBoxConfirm(
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800220 this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', {
221 user: user.username
222 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800223 {
Yoshie Muranaka29321652020-05-04 10:52:36 -0700224 title: this.$tc('pageLocalUserManagement.deleteUser'),
225 okTitle: this.$tc('pageLocalUserManagement.deleteUser')
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800226 }
227 )
228 .then(deleteConfirmed => {
229 if (deleteConfirmed) {
230 this.deleteUser(user);
231 }
232 });
233 },
234 initModalSettings() {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800235 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800236 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800237 saveUser({ isNewUser, userData }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700238 this.startLoader();
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800239 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800240 this.$store
241 .dispatch('localUsers/createUser', userData)
242 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700243 .catch(({ message }) => this.errorToast(message))
244 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800245 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800246 this.$store
247 .dispatch('localUsers/updateUser', userData)
248 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700249 .catch(({ message }) => this.errorToast(message))
250 .finally(() => this.endLoader());
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800251 }
252 },
253 deleteUser({ username }) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700254 this.startLoader();
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800255 this.$store
256 .dispatch('localUsers/deleteUser', username)
257 .then(success => this.successToast(success))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700258 .catch(({ message }) => this.errorToast(message))
259 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800260 },
261 onBatchAction(action) {
262 switch (action) {
263 case 'delete':
Yoshie Muranaka29321652020-05-04 10:52:36 -0700264 this.$bvModal
265 .msgBoxConfirm(
266 this.$tc(
267 'pageLocalUserManagement.modal.batchDeleteConfirmMessage',
268 this.selectedRows.length
269 ),
270 {
271 title: this.$tc(
272 'pageLocalUserManagement.deleteUser',
273 this.selectedRows.length
274 ),
275 okTitle: this.$tc(
276 'pageLocalUserManagement.deleteUser',
277 this.selectedRows.length
278 )
279 }
280 )
281 .then(deleteConfirmed => {
282 if (deleteConfirmed) {
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700283 this.startLoader();
Yoshie Muranaka29321652020-05-04 10:52:36 -0700284 this.$store
285 .dispatch('localUsers/deleteUsers', this.selectedRows)
286 .then(messages => {
287 messages.forEach(({ type, message }) => {
288 if (type === 'success') this.successToast(message);
289 if (type === 'error') this.errorToast(message);
290 });
291 })
292 .finally(() => this.endLoader());
293 }
294 });
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800295 break;
296 case 'enable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700297 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800298 this.$store
299 .dispatch('localUsers/enableUsers', this.selectedRows)
300 .then(messages => {
301 messages.forEach(({ type, message }) => {
302 if (type === 'success') this.successToast(message);
303 if (type === 'error') this.errorToast(message);
304 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700305 })
306 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800307 break;
308 case 'disable':
Yoshie Muranaka8e4b5c32020-05-27 14:10:52 -0700309 this.startLoader();
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800310 this.$store
311 .dispatch('localUsers/disableUsers', this.selectedRows)
312 .then(messages => {
313 messages.forEach(({ type, message }) => {
314 if (type === 'success') this.successToast(message);
315 if (type === 'error') this.errorToast(message);
316 });
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700317 })
318 .finally(() => this.endLoader());
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800319 break;
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800320 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800321 },
322 onTableRowAction(action, row) {
323 switch (action) {
324 case 'edit':
325 this.initModalUser(row);
326 break;
327 case 'delete':
328 this.initModalDelete(row);
329 break;
330 default:
331 break;
332 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800333 },
334 saveAccountSettings(settings) {
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700335 this.startLoader();
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800336 this.$store
337 .dispatch('localUsers/saveAccountSettings', settings)
338 .then(message => this.successToast(message))
Yoshie Muranaka346be2a2020-04-28 11:12:14 -0700339 .catch(({ message }) => this.errorToast(message))
340 .finally(() => this.endLoader());
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600341 }
342 }
343};
344</script>
345
346<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800347.btn.collapsed {
348 svg {
349 transform: rotate(180deg);
350 }
351}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600352</style>