blob: c08b39b960a8762e7396931da44148b619605ebe [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"
84 />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060085 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -060086</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060087
88<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -060089import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
90import IconEdit from '@carbon/icons-vue/es/edit/20';
91import IconAdd from '@carbon/icons-vue/es/add--alt/20';
92import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080093import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -080094
Derick Montaguee2fd1562019-12-20 13:26:53 -060095import ModalUser from './ModalUser';
96import ModalSettings from './ModalSettings';
97import PageTitle from '../../../components/Global/PageTitle';
Yoshie Muranaka183c2752020-02-12 11:30:49 -080098import TableRoles from './TableRoles';
99import TableToolbar from '../../../components/Global/TableToolbar';
100
101import BVTableSelectableMixin from '../../../components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800102import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800103import TableRowAction from '../../../components/Global/TableRowAction';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600104
105export default {
Derick Montague09e45cd2020-01-23 15:45:57 -0600106 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600107 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800108 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800109 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800110 IconEdit,
111 IconSettings,
112 IconTrashcan,
113 ModalSettings,
114 ModalUser,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800115 PageTitle,
Yoshie Muranaka8d129102019-12-19 09:51:55 -0800116 TableRoles,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800117 TableRowAction,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800118 TableToolbar
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800119 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800120 mixins: [BVTableSelectableMixin, BVToastMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800121 data() {
122 return {
123 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800124 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800125 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800126 key: 'checkbox'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800127 },
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800128 {
129 key: 'username',
130 label: this.$t('pageLocalUserManagement.table.username')
131 },
132 {
133 key: 'privilege',
134 label: this.$t('pageLocalUserManagement.table.privilege')
135 },
136 {
137 key: 'status',
138 label: this.$t('pageLocalUserManagement.table.status')
139 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800140 {
141 key: 'actions',
142 label: '',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800143 tdClass: 'text-right'
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800144 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800145 ],
146 tableToolbarActions: [
147 {
148 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800149 label: this.$t('global.action.delete')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800150 },
151 {
152 value: 'enable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800153 label: this.$t('global.action.enable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800154 },
155 {
156 value: 'disable',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800157 label: this.$t('global.action.disable')
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800158 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800159 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800160 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600161 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600162 computed: {
163 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600164 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600165 },
166 tableItems() {
167 // transform user data to table data
168 return this.allUsers.map(user => {
169 return {
170 username: user.UserName,
171 privilege: user.RoleId,
172 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600173 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600174 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600175 ? 'Enabled'
176 : 'Disabled',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800177 actions: [
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800178 {
179 value: 'edit',
180 enabled: true,
181 title: this.$t('pageLocalUserManagement.editUser')
182 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800183 {
184 value: 'delete',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800185 enabled: user.UserName === 'root' ? false : true,
186 title: this.$t('pageLocalUserManagement.deleteUser')
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800187 }
188 ],
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800189 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600190 };
191 });
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800192 },
193 settings() {
194 return this.$store.getters['localUsers/accountSettings'];
195 },
196 passwordRequirements() {
197 return this.$store.getters['localUsers/accountPasswordRequirements'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600198 }
199 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600200 created() {
Yoshie Muranakafb78d192020-03-03 11:55:52 -0800201 this.$store.dispatch('localUsers/getUsers');
202 this.$store.dispatch('localUsers/getAccountSettings');
Derick Montague09e45cd2020-01-23 15:45:57 -0600203 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600204 methods: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800205 initModalUser(user) {
206 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600207 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800208 },
209 initModalDelete(user) {
210 this.$bvModal
211 .msgBoxConfirm(
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800212 this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', {
213 user: user.username
214 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800215 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800216 title: this.$t('pageLocalUserManagement.deleteUser'),
217 okTitle: this.$t('pageLocalUserManagement.deleteUser')
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800218 }
219 )
220 .then(deleteConfirmed => {
221 if (deleteConfirmed) {
222 this.deleteUser(user);
223 }
224 });
225 },
226 initModalSettings() {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800227 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800228 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800229 saveUser({ isNewUser, userData }) {
230 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800231 this.$store
232 .dispatch('localUsers/createUser', userData)
233 .then(success => this.successToast(success))
234 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800235 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800236 this.$store
237 .dispatch('localUsers/updateUser', userData)
238 .then(success => this.successToast(success))
239 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800240 }
241 },
242 deleteUser({ username }) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800243 this.$store
244 .dispatch('localUsers/deleteUser', username)
245 .then(success => this.successToast(success))
246 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800247 },
248 onBatchAction(action) {
249 switch (action) {
250 case 'delete':
251 this.$store
252 .dispatch('localUsers/deleteUsers', this.selectedRows)
253 .then(messages => {
254 messages.forEach(({ type, message }) => {
255 if (type === 'success') this.successToast(message);
256 if (type === 'error') this.errorToast(message);
257 });
258 });
259 break;
260 case 'enable':
261 this.$store
262 .dispatch('localUsers/enableUsers', this.selectedRows)
263 .then(messages => {
264 messages.forEach(({ type, message }) => {
265 if (type === 'success') this.successToast(message);
266 if (type === 'error') this.errorToast(message);
267 });
268 });
269 break;
270 case 'disable':
271 this.$store
272 .dispatch('localUsers/disableUsers', this.selectedRows)
273 .then(messages => {
274 messages.forEach(({ type, message }) => {
275 if (type === 'success') this.successToast(message);
276 if (type === 'error') this.errorToast(message);
277 });
278 });
279 break;
280 default:
281 break;
282 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800283 },
284 onTableRowAction(action, row) {
285 switch (action) {
286 case 'edit':
287 this.initModalUser(row);
288 break;
289 case 'delete':
290 this.initModalDelete(row);
291 break;
292 default:
293 break;
294 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800295 },
296 saveAccountSettings(settings) {
297 this.$store
298 .dispatch('localUsers/saveAccountSettings', settings)
299 .then(message => this.successToast(message))
300 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600301 }
302 }
303};
304</script>
305
306<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800307.btn.collapsed {
308 svg {
309 transform: rotate(180deg);
310 }
311}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600312</style>