blob: b9df58f5b395bcf84343254c019971a70a36566b [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');
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700203 this.$store.dispatch('localUsers/getAccountRoles');
Derick Montague09e45cd2020-01-23 15:45:57 -0600204 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600205 methods: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800206 initModalUser(user) {
207 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600208 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800209 },
210 initModalDelete(user) {
211 this.$bvModal
212 .msgBoxConfirm(
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800213 this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', {
214 user: user.username
215 }),
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800216 {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800217 title: this.$t('pageLocalUserManagement.deleteUser'),
218 okTitle: this.$t('pageLocalUserManagement.deleteUser')
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800219 }
220 )
221 .then(deleteConfirmed => {
222 if (deleteConfirmed) {
223 this.deleteUser(user);
224 }
225 });
226 },
227 initModalSettings() {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800228 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800229 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800230 saveUser({ isNewUser, userData }) {
231 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800232 this.$store
233 .dispatch('localUsers/createUser', userData)
234 .then(success => this.successToast(success))
235 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800236 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800237 this.$store
238 .dispatch('localUsers/updateUser', userData)
239 .then(success => this.successToast(success))
240 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800241 }
242 },
243 deleteUser({ username }) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800244 this.$store
245 .dispatch('localUsers/deleteUser', username)
246 .then(success => this.successToast(success))
247 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800248 },
249 onBatchAction(action) {
250 switch (action) {
251 case 'delete':
252 this.$store
253 .dispatch('localUsers/deleteUsers', this.selectedRows)
254 .then(messages => {
255 messages.forEach(({ type, message }) => {
256 if (type === 'success') this.successToast(message);
257 if (type === 'error') this.errorToast(message);
258 });
259 });
260 break;
261 case 'enable':
262 this.$store
263 .dispatch('localUsers/enableUsers', this.selectedRows)
264 .then(messages => {
265 messages.forEach(({ type, message }) => {
266 if (type === 'success') this.successToast(message);
267 if (type === 'error') this.errorToast(message);
268 });
269 });
270 break;
271 case 'disable':
272 this.$store
273 .dispatch('localUsers/disableUsers', this.selectedRows)
274 .then(messages => {
275 messages.forEach(({ type, message }) => {
276 if (type === 'success') this.successToast(message);
277 if (type === 'error') this.errorToast(message);
278 });
279 });
280 break;
281 default:
282 break;
283 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800284 },
285 onTableRowAction(action, row) {
286 switch (action) {
287 case 'edit':
288 this.initModalUser(row);
289 break;
290 case 'delete':
291 this.initModalDelete(row);
292 break;
293 default:
294 break;
295 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800296 },
297 saveAccountSettings(settings) {
298 this.$store
299 .dispatch('localUsers/saveAccountSettings', settings)
300 .then(message => this.successToast(message))
301 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600302 }
303 }
304};
305</script>
306
307<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800308.btn.collapsed {
309 svg {
310 transform: rotate(180deg);
311 }
312}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600313</style>