blob: d68c953465bdf6bb05f0353bbc96d29b805e1a99 [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 Muranaka35080ac2020-01-17 15:38:57 -060049 <template v-slot:cell(actions)="data">
50 <b-button
Yoshie Muranaka463a5702019-12-04 09:09:36 -080051 aria-label="Edit user"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080052 title="Edit user"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080053 variant="link"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060054 :disabled="!data.value.edit"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080055 @click="initModalUser(data.item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060056 >
Yoshie Muranaka463a5702019-12-04 09:09:36 -080057 <icon-edit />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060058 </b-button>
59 <b-button
Yoshie Muranaka463a5702019-12-04 09:09:36 -080060 aria-label="Delete user"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080061 title="Delete user"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080062 variant="link"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060063 :disabled="!data.value.delete"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080064 @click="initModalDelete(data.item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060065 >
Yoshie Muranaka463a5702019-12-04 09:09:36 -080066 <icon-trashcan />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060067 </b-button>
68 </template>
69 </b-table>
70 </b-col>
71 </b-row>
72 <b-row>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080073 <b-col xl="8">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080074 <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3">
75 View privilege role descriptions
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080076 <icon-chevron />
Yoshie Muranaka463a5702019-12-04 09:09:36 -080077 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060078 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080079 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060080 </b-collapse>
81 </b-col>
82 </b-row>
83 <!-- Modals -->
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080084 <modal-settings :settings="settings"></modal-settings>
85 <modal-user :user="activeUser" @ok="saveUser"></modal-user>
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 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 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 settings: null,
124 fields: [
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800125 {
126 key: 'checkbox',
127 label: '',
128 tdClass: 'table-cell__checkbox'
129 },
130 'checkbox',
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800131 'username',
132 'privilege',
133 'status',
134 {
135 key: 'actions',
136 label: '',
137 tdClass: 'table-cell__actions'
138 }
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800139 ],
140 tableToolbarActions: [
141 {
142 value: 'delete',
143 labelKey: 'localUserManagement.tableActions.delete'
144 },
145 {
146 value: 'enable',
147 labelKey: 'localUserManagement.tableActions.enable'
148 },
149 {
150 value: 'disable',
151 labelKey: 'localUserManagement.tableActions.disable'
152 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800153 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800154 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600155 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600156 computed: {
157 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600158 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600159 },
160 tableItems() {
161 // transform user data to table data
162 return this.allUsers.map(user => {
163 return {
164 username: user.UserName,
165 privilege: user.RoleId,
166 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600167 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600168 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600169 ? 'Enabled'
170 : 'Disabled',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600171 actions: {
172 edit: true,
Derick Montaguee2fd1562019-12-20 13:26:53 -0600173 delete: user.UserName === 'root' ? false : true
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800174 },
175 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600176 };
177 });
178 }
179 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600180 created() {
181 this.getUsers();
182 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600183 methods: {
184 getUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600185 this.$store.dispatch('localUsers/getUsers');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800186 },
187 initModalUser(user) {
188 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600189 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800190 },
191 initModalDelete(user) {
192 this.$bvModal
193 .msgBoxConfirm(
194 `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`,
195 {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600196 title: 'Delete user',
197 okTitle: 'Delete user'
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800198 }
199 )
200 .then(deleteConfirmed => {
201 if (deleteConfirmed) {
202 this.deleteUser(user);
203 }
204 });
205 },
206 initModalSettings() {
207 if (this.settings) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600208 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800209 } else {
210 // fetch settings then show modal
211 }
212 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800213 saveUser({ isNewUser, userData }) {
214 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800215 this.$store
216 .dispatch('localUsers/createUser', userData)
217 .then(success => this.successToast(success))
218 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800219 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800220 this.$store
221 .dispatch('localUsers/updateUser', userData)
222 .then(success => this.successToast(success))
223 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800224 }
225 },
226 deleteUser({ username }) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800227 this.$store
228 .dispatch('localUsers/deleteUser', username)
229 .then(success => this.successToast(success))
230 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800231 },
232 onBatchAction(action) {
233 switch (action) {
234 case 'delete':
235 this.$store
236 .dispatch('localUsers/deleteUsers', this.selectedRows)
237 .then(messages => {
238 messages.forEach(({ type, message }) => {
239 if (type === 'success') this.successToast(message);
240 if (type === 'error') this.errorToast(message);
241 });
242 });
243 break;
244 case 'enable':
245 this.$store
246 .dispatch('localUsers/enableUsers', this.selectedRows)
247 .then(messages => {
248 messages.forEach(({ type, message }) => {
249 if (type === 'success') this.successToast(message);
250 if (type === 'error') this.errorToast(message);
251 });
252 });
253 break;
254 case 'disable':
255 this.$store
256 .dispatch('localUsers/disableUsers', this.selectedRows)
257 .then(messages => {
258 messages.forEach(({ type, message }) => {
259 if (type === 'success') this.successToast(message);
260 if (type === 'error') this.errorToast(message);
261 });
262 });
263 break;
264 default:
265 break;
266 }
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600267 }
268 }
269};
270</script>
271
272<style lang="scss" scoped>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800273.btn.collapsed {
274 svg {
275 transform: rotate(180deg);
276 }
277}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600278</style>