blob: 6ca43f328f48cde6412388690725c31e6640c30d [file] [log] [blame]
Derick Montaguea2988f42020-01-17 13:46:30 -06001<template>
Yoshie Muranaka463a5702019-12-04 09:09:36 -08002 <b-container class="ml-0">
Yoshie Muranaka8d129102019-12-19 09:51:55 -08003 <PageTitle />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -06004 <b-row>
Yoshie Muranaka463a5702019-12-04 09:09:36 -08005 <b-col lg="10">
6 <b-button @click="initModalSettings" variant="link">
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>
10 <b-button @click="initModalUser(null)" variant="primary">
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 Muranaka463a5702019-12-04 09:09:36 -080017 <b-col lg="10">
18 <b-table bordered show-empty head-variant="dark" :items="tableItems">
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060019 <template v-slot:head(actions)="data"></template>
20 <template v-slot:cell(actions)="data">
21 <b-button
Yoshie Muranaka463a5702019-12-04 09:09:36 -080022 aria-label="Edit user"
23 variant="link"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060024 :disabled="!data.value.edit"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080025 @click="initModalUser(data.item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060026 >
Yoshie Muranaka463a5702019-12-04 09:09:36 -080027 <icon-edit />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060028 </b-button>
29 <b-button
Yoshie Muranaka463a5702019-12-04 09:09:36 -080030 aria-label="Delete user"
31 variant="link"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060032 :disabled="!data.value.delete"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080033 @click="initModalDelete(data.item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060034 >
Yoshie Muranaka463a5702019-12-04 09:09:36 -080035 <icon-trashcan />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060036 </b-button>
37 </template>
38 </b-table>
39 </b-col>
40 </b-row>
41 <b-row>
Yoshie Muranaka463a5702019-12-04 09:09:36 -080042 <b-col lg="8">
43 <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3">
44 View privilege role descriptions
45 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060046 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080047 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060048 </b-collapse>
49 </b-col>
50 </b-row>
51 <!-- Modals -->
Yoshie Muranaka463a5702019-12-04 09:09:36 -080052 <modal-settings v-bind:settings="settings"></modal-settings>
53 <modal-user
54 v-bind:user="activeUser"
55 @ok="saveUser"
56 @hidden="clearActiveUser"
57 ></modal-user>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060058 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -060059</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060060
61<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -060062import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
63import IconEdit from '@carbon/icons-vue/es/edit/20';
64import IconAdd from '@carbon/icons-vue/es/add--alt/20';
65import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -080066
Derick Montaguee2fd1562019-12-20 13:26:53 -060067import TableRoles from './TableRoles';
68import ModalUser from './ModalUser';
69import ModalSettings from './ModalSettings';
70import PageTitle from '../../../components/Global/PageTitle';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060071
72export default {
Derick Montaguee2fd1562019-12-20 13:26:53 -060073 name: 'local-users',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060074 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -080075 IconAdd,
76 IconEdit,
77 IconSettings,
78 IconTrashcan,
79 ModalSettings,
80 ModalUser,
Yoshie Muranaka8d129102019-12-19 09:51:55 -080081 TableRoles,
82 PageTitle
Yoshie Muranaka463a5702019-12-04 09:09:36 -080083 },
84 data() {
85 return {
86 activeUser: null,
87 settings: null
88 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060089 },
90 created() {
91 this.getUsers();
92 },
93 computed: {
94 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -060095 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060096 },
97 tableItems() {
98 // transform user data to table data
99 return this.allUsers.map(user => {
100 return {
101 username: user.UserName,
102 privilege: user.RoleId,
103 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600104 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600105 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600106 ? 'Enabled'
107 : 'Disabled',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600108 actions: {
109 edit: true,
Derick Montaguee2fd1562019-12-20 13:26:53 -0600110 delete: user.UserName === 'root' ? false : true
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600111 }
112 };
113 });
114 }
115 },
116 methods: {
117 getUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600118 this.$store.dispatch('localUsers/getUsers');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800119 },
120 initModalUser(user) {
121 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600122 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800123 },
124 initModalDelete(user) {
125 this.$bvModal
126 .msgBoxConfirm(
127 `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`,
128 {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600129 title: 'Delete user',
130 okTitle: 'Delete user'
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800131 }
132 )
133 .then(deleteConfirmed => {
134 if (deleteConfirmed) {
135 this.deleteUser(user);
136 }
137 });
138 },
139 initModalSettings() {
140 if (this.settings) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600141 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800142 } else {
143 // fetch settings then show modal
144 }
145 },
146 saveUser({ newUser, form }) {
147 if (newUser) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600148 this.$store.dispatch('localUsers/createUser', form);
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800149 } else {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600150 this.$store.dispatch('localUsers/updateUser', form);
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800151 }
152 },
153 deleteUser({ username }) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600154 this.$store.dispatch('localUsers/deleteUser', username);
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800155 },
156 clearActiveUser() {
157 this.activeUser = null;
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600158 }
159 }
160};
161</script>
162
163<style lang="scss" scoped>
164h1 {
165 margin-bottom: 2rem;
166}
167</style>