blob: 97b00e497265c2dd047d09a90cb13ff290d195a1 [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 Muranaka463a5702019-12-04 09:09:36 -08007 Account policy settings
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 Muranaka463a5702019-12-04 09:09:36 -080011 Add user
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"
55 @click:tableAction="onTableRowAction($event, item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060056 >
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080057 <template v-slot:icon>
58 <icon-edit v-if="action.value === 'edit'" />
59 <icon-trashcan v-if="action.value === 'delete'" />
60 </template>
61 </table-row-action>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060062 </template>
63 </b-table>
64 </b-col>
65 </b-row>
66 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080067 <b-col xl="8">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080068 <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3">
69 View privilege role descriptions
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080070 <icon-chevron />
Yoshie Muranaka463a5702019-12-04 09:09:36 -080071 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060072 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080073 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060074 </b-collapse>
75 </b-col>
76 </b-row>
77 <!-- Modals -->
Yoshie Muranaka52b02232020-02-20 08:00:45 -080078 <modal-settings :settings="settings" />
79 <modal-user
80 :user="activeUser"
81 :password-requirements="passwordRequirements"
82 @ok="saveUser"
83 />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060084 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -060085</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060086
87<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -060088import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
89import IconEdit from '@carbon/icons-vue/es/edit/20';
90import IconAdd from '@carbon/icons-vue/es/add--alt/20';
91import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080092import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -080093
Derick Montaguee2fd1562019-12-20 13:26:53 -060094import ModalUser from './ModalUser';
95import ModalSettings from './ModalSettings';
96import PageTitle from '../../../components/Global/PageTitle';
Yoshie Muranaka183c2752020-02-12 11:30:49 -080097import TableRoles from './TableRoles';
98import TableToolbar from '../../../components/Global/TableToolbar';
99
100import BVTableSelectableMixin from '../../../components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800101import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800102import TableRowAction from '../../../components/Global/TableRowAction';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600103
104export default {
Derick Montague09e45cd2020-01-23 15:45:57 -0600105 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600106 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800107 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800108 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800109 IconEdit,
110 IconSettings,
111 IconTrashcan,
112 ModalSettings,
113 ModalUser,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800114 PageTitle,
Yoshie Muranaka8d129102019-12-19 09:51:55 -0800115 TableRoles,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800116 TableRowAction,
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800117 TableToolbar
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800118 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800119 mixins: [BVTableSelectableMixin, BVToastMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800120 data() {
121 return {
122 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800123 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800124 {
125 key: 'checkbox',
126 label: '',
127 tdClass: 'table-cell__checkbox'
128 },
129 'checkbox',
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800130 'username',
131 'privilege',
132 'status',
133 {
134 key: 'actions',
135 label: '',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800136 tdClass: 'text-right'
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800137 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800138 ],
139 tableToolbarActions: [
140 {
141 value: 'delete',
142 labelKey: 'localUserManagement.tableActions.delete'
143 },
144 {
145 value: 'enable',
146 labelKey: 'localUserManagement.tableActions.enable'
147 },
148 {
149 value: 'disable',
150 labelKey: 'localUserManagement.tableActions.disable'
151 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800152 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800153 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600154 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600155 computed: {
156 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600157 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600158 },
159 tableItems() {
160 // transform user data to table data
161 return this.allUsers.map(user => {
162 return {
163 username: user.UserName,
164 privilege: user.RoleId,
165 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600166 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600167 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600168 ? 'Enabled'
169 : 'Disabled',
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800170 actions: [
171 { value: 'edit', enabled: true },
172 {
173 value: 'delete',
174 enabled: user.UserName === 'root' ? false : true
175 }
176 ],
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800177 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600178 };
179 });
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800180 },
181 settings() {
182 return this.$store.getters['localUsers/accountSettings'];
183 },
184 passwordRequirements() {
185 return this.$store.getters['localUsers/accountPasswordRequirements'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600186 }
187 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600188 created() {
189 this.getUsers();
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800190 this.getAccountSettings();
Derick Montague09e45cd2020-01-23 15:45:57 -0600191 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600192 methods: {
193 getUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600194 this.$store.dispatch('localUsers/getUsers');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800195 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800196 getAccountSettings() {
197 this.$store.dispatch('localUsers/getAccountSettings');
198 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800199 initModalUser(user) {
200 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600201 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800202 },
203 initModalDelete(user) {
204 this.$bvModal
205 .msgBoxConfirm(
206 `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`,
207 {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600208 title: 'Delete user',
209 okTitle: 'Delete user'
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800210 }
211 )
212 .then(deleteConfirmed => {
213 if (deleteConfirmed) {
214 this.deleteUser(user);
215 }
216 });
217 },
218 initModalSettings() {
219 if (this.settings) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600220 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800221 } else {
222 // fetch settings then show modal
223 }
224 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800225 saveUser({ isNewUser, userData }) {
226 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800227 this.$store
228 .dispatch('localUsers/createUser', userData)
229 .then(success => this.successToast(success))
230 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800231 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800232 this.$store
233 .dispatch('localUsers/updateUser', userData)
234 .then(success => this.successToast(success))
235 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800236 }
237 },
238 deleteUser({ username }) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800239 this.$store
240 .dispatch('localUsers/deleteUser', username)
241 .then(success => this.successToast(success))
242 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800243 },
244 onBatchAction(action) {
245 switch (action) {
246 case 'delete':
247 this.$store
248 .dispatch('localUsers/deleteUsers', this.selectedRows)
249 .then(messages => {
250 messages.forEach(({ type, message }) => {
251 if (type === 'success') this.successToast(message);
252 if (type === 'error') this.errorToast(message);
253 });
254 });
255 break;
256 case 'enable':
257 this.$store
258 .dispatch('localUsers/enableUsers', 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 'disable':
267 this.$store
268 .dispatch('localUsers/disableUsers', 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 default:
277 break;
278 }
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800279 },
280 onTableRowAction(action, row) {
281 switch (action) {
282 case 'edit':
283 this.initModalUser(row);
284 break;
285 case 'delete':
286 this.initModalDelete(row);
287 break;
288 default:
289 break;
290 }
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600291 }
292 }
293};
294</script>
295
296<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800297.btn.collapsed {
298 svg {
299 transform: rotate(180deg);
300 }
301}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600302</style>