blob: 23b06dd7fff2af0a92e8a7543342d1b39fff059e [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() {
201 this.getUsers();
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800202 this.getAccountSettings();
Derick Montague09e45cd2020-01-23 15:45:57 -0600203 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600204 methods: {
205 getUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600206 this.$store.dispatch('localUsers/getUsers');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800207 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800208 getAccountSettings() {
209 this.$store.dispatch('localUsers/getAccountSettings');
210 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800211 initModalUser(user) {
212 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600213 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800214 },
215 initModalDelete(user) {
216 this.$bvModal
217 .msgBoxConfirm(
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800218 this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', {
219 user: user.username
220 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800221 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800222 title: this.$t('pageLocalUserManagement.deleteUser'),
223 okTitle: this.$t('pageLocalUserManagement.deleteUser')
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800224 }
225 )
226 .then(deleteConfirmed => {
227 if (deleteConfirmed) {
228 this.deleteUser(user);
229 }
230 });
231 },
232 initModalSettings() {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800233 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800234 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800235 saveUser({ isNewUser, userData }) {
236 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800237 this.$store
238 .dispatch('localUsers/createUser', userData)
239 .then(success => this.successToast(success))
240 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800241 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800242 this.$store
243 .dispatch('localUsers/updateUser', userData)
244 .then(success => this.successToast(success))
245 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800246 }
247 },
248 deleteUser({ username }) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800249 this.$store
250 .dispatch('localUsers/deleteUser', username)
251 .then(success => this.successToast(success))
252 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800253 },
254 onBatchAction(action) {
255 switch (action) {
256 case 'delete':
257 this.$store
258 .dispatch('localUsers/deleteUsers', this.selectedRows)
259 .then(messages => {
260 messages.forEach(({ type, message }) => {
261 if (type === 'success') this.successToast(message);
262 if (type === 'error') this.errorToast(message);
263 });
264 });
265 break;
266 case 'enable':
267 this.$store
268 .dispatch('localUsers/enableUsers', this.selectedRows)
269 .then(messages => {
270 messages.forEach(({ type, message }) => {
271 if (type === 'success') this.successToast(message);
272 if (type === 'error') this.errorToast(message);
273 });
274 });
275 break;
276 case 'disable':
277 this.$store
278 .dispatch('localUsers/disableUsers', this.selectedRows)
279 .then(messages => {
280 messages.forEach(({ type, message }) => {
281 if (type === 'success') this.successToast(message);
282 if (type === 'error') this.errorToast(message);
283 });
284 });
285 break;
286 default:
287 break;
288 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800289 },
290 onTableRowAction(action, row) {
291 switch (action) {
292 case 'edit':
293 this.initModalUser(row);
294 break;
295 case 'delete':
296 this.initModalDelete(row);
297 break;
298 default:
299 break;
300 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800301 },
302 saveAccountSettings(settings) {
303 this.$store
304 .dispatch('localUsers/saveAccountSettings', settings)
305 .then(message => this.successToast(message))
306 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600307 }
308 }
309};
310</script>
311
312<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800313.btn.collapsed {
314 svg {
315 transform: rotate(180deg);
316 }
317}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600318</style>