blob: 8c7cc7fcf7b1f2f8b132139deec2ea3f7e0c97d7 [file] [log] [blame]
Derick Montaguea2988f42020-01-17 13:46:30 -06001<template>
Yoshie Muranaka74f86872020-02-10 12:28:37 -08002 <b-container fluid>
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 Muranakaeaa04802020-02-28 13:21:27 -08007 {{ $t('pageLocalUserManagement.accountPolicySettings') }}
Yoshie Muranaka996d2d52019-12-30 09:06:45 -08008 <icon-settings />
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 Muranakaeaa04802020-02-28 13:21:27 -080011 {{ $t('pageLocalUserManagement.addUser') }}
Yoshie Muranaka996d2d52019-12-30 09:06:45 -080012 <icon-add />
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 Muranakaeaa04802020-02-28 13:21:27 -080070 {{ $t('pageLocalUserManagement.viewPrivilegeRoleDescriptions') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080071 <icon-chevron />
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';
101
102import BVTableSelectableMixin from '../../../components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800103import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800104import TableRowAction from '../../../components/Global/TableRowAction';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600105
106export default {
Derick Montague09e45cd2020-01-23 15:45:57 -0600107 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600108 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800109 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800110 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800111 IconEdit,
112 IconSettings,
113 IconTrashcan,
114 ModalSettings,
115 ModalUser,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800116 PageTitle,
Yoshie Muranaka8d129102019-12-19 09:51:55 -0800117 TableRoles,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800118 TableRowAction,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800119 TableToolbar
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800120 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800121 mixins: [BVTableSelectableMixin, BVToastMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800122 data() {
123 return {
124 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800125 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800126 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800127 key: 'checkbox'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800128 },
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800129 {
130 key: 'username',
131 label: this.$t('pageLocalUserManagement.table.username')
132 },
133 {
134 key: 'privilege',
135 label: this.$t('pageLocalUserManagement.table.privilege')
136 },
137 {
138 key: 'status',
139 label: this.$t('pageLocalUserManagement.table.status')
140 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800141 {
142 key: 'actions',
143 label: '',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800144 tdClass: 'text-right'
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800145 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800146 ],
147 tableToolbarActions: [
148 {
149 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800150 label: this.$t('global.action.delete')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800151 },
152 {
153 value: 'enable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800154 label: this.$t('global.action.enable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800155 },
156 {
157 value: 'disable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800158 label: this.$t('global.action.disable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800159 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800160 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800161 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600162 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600163 computed: {
164 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600165 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600166 },
167 tableItems() {
168 // transform user data to table data
169 return this.allUsers.map(user => {
170 return {
171 username: user.UserName,
172 privilege: user.RoleId,
173 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600174 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600175 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600176 ? 'Enabled'
177 : 'Disabled',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800178 actions: [
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800179 {
180 value: 'edit',
181 enabled: true,
182 title: this.$t('pageLocalUserManagement.editUser')
183 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800184 {
185 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800186 enabled: user.UserName === 'root' ? false : true,
187 title: this.$t('pageLocalUserManagement.deleteUser')
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800188 }
189 ],
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800190 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600191 };
192 });
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800193 },
194 settings() {
195 return this.$store.getters['localUsers/accountSettings'];
196 },
197 passwordRequirements() {
198 return this.$store.getters['localUsers/accountPasswordRequirements'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600199 }
200 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600201 created() {
Yoshie Muranakafb78d192020-03-03 11:55:52 -0800202 this.$store.dispatch('localUsers/getUsers');
203 this.$store.dispatch('localUsers/getAccountSettings');
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700204 this.$store.dispatch('localUsers/getAccountRoles');
Derick Montague09e45cd2020-01-23 15:45:57 -0600205 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600206 methods: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800207 initModalUser(user) {
208 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600209 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800210 },
211 initModalDelete(user) {
212 this.$bvModal
213 .msgBoxConfirm(
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800214 this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', {
215 user: user.username
216 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800217 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800218 title: this.$t('pageLocalUserManagement.deleteUser'),
219 okTitle: this.$t('pageLocalUserManagement.deleteUser')
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800220 }
221 )
222 .then(deleteConfirmed => {
223 if (deleteConfirmed) {
224 this.deleteUser(user);
225 }
226 });
227 },
228 initModalSettings() {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800229 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800230 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800231 saveUser({ isNewUser, userData }) {
232 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800233 this.$store
234 .dispatch('localUsers/createUser', userData)
235 .then(success => this.successToast(success))
236 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800237 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800238 this.$store
239 .dispatch('localUsers/updateUser', userData)
240 .then(success => this.successToast(success))
241 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800242 }
243 },
244 deleteUser({ username }) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800245 this.$store
246 .dispatch('localUsers/deleteUser', username)
247 .then(success => this.successToast(success))
248 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800249 },
250 onBatchAction(action) {
251 switch (action) {
252 case 'delete':
253 this.$store
254 .dispatch('localUsers/deleteUsers', this.selectedRows)
255 .then(messages => {
256 messages.forEach(({ type, message }) => {
257 if (type === 'success') this.successToast(message);
258 if (type === 'error') this.errorToast(message);
259 });
260 });
261 break;
262 case 'enable':
263 this.$store
264 .dispatch('localUsers/enableUsers', this.selectedRows)
265 .then(messages => {
266 messages.forEach(({ type, message }) => {
267 if (type === 'success') this.successToast(message);
268 if (type === 'error') this.errorToast(message);
269 });
270 });
271 break;
272 case 'disable':
273 this.$store
274 .dispatch('localUsers/disableUsers', this.selectedRows)
275 .then(messages => {
276 messages.forEach(({ type, message }) => {
277 if (type === 'success') this.successToast(message);
278 if (type === 'error') this.errorToast(message);
279 });
280 });
281 break;
282 default:
283 break;
284 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800285 },
286 onTableRowAction(action, row) {
287 switch (action) {
288 case 'edit':
289 this.initModalUser(row);
290 break;
291 case 'delete':
292 this.initModalDelete(row);
293 break;
294 default:
295 break;
296 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800297 },
298 saveAccountSettings(settings) {
299 this.$store
300 .dispatch('localUsers/saveAccountSettings', settings)
301 .then(message => this.successToast(message))
302 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600303 }
304 }
305};
306</script>
307
308<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800309.btn.collapsed {
310 svg {
311 transform: rotate(180deg);
312 }
313}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600314</style>