blob: 0ca3428d6ec73515b0ccf91e874871b79fa56c12 [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">
Derick Montague09e45cd2020-01-23 15:45:57 -06003 <page-title />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -06004 <b-row>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -08005 <b-col lg="10" class="text-right">
6 <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 Muranaka463a5702019-12-04 09:09:36 -080017 <b-col lg="10">
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080018 <b-table show-empty :fields="fields" :items="tableItems">
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060019 <template v-slot:cell(actions)="data">
20 <b-button
Yoshie Muranaka463a5702019-12-04 09:09:36 -080021 aria-label="Edit user"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080022 title="Edit user"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080023 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"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080031 title="Delete user"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080032 variant="link"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060033 :disabled="!data.value.delete"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080034 @click="initModalDelete(data.item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060035 >
Yoshie Muranaka463a5702019-12-04 09:09:36 -080036 <icon-trashcan />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060037 </b-button>
38 </template>
39 </b-table>
40 </b-col>
41 </b-row>
42 <b-row>
Yoshie Muranaka463a5702019-12-04 09:09:36 -080043 <b-col lg="8">
44 <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3">
45 View privilege role descriptions
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080046 <icon-chevron />
Yoshie Muranaka463a5702019-12-04 09:09:36 -080047 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060048 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080049 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060050 </b-collapse>
51 </b-col>
52 </b-row>
53 <!-- Modals -->
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080054 <modal-settings :settings="settings"></modal-settings>
55 <modal-user :user="activeUser" @ok="saveUser"></modal-user>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060056 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -060057</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060058
59<script>
Derick Montaguee2fd1562019-12-20 13:26:53 -060060import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
61import IconEdit from '@carbon/icons-vue/es/edit/20';
62import IconAdd from '@carbon/icons-vue/es/add--alt/20';
63import IconSettings from '@carbon/icons-vue/es/settings/20';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080064import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
Yoshie Muranaka463a5702019-12-04 09:09:36 -080065
Derick Montaguee2fd1562019-12-20 13:26:53 -060066import TableRoles from './TableRoles';
67import ModalUser from './ModalUser';
68import ModalSettings from './ModalSettings';
69import PageTitle from '../../../components/Global/PageTitle';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060070
71export default {
Derick Montague09e45cd2020-01-23 15:45:57 -060072 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060073 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -080074 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080075 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -080076 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,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080087 settings: null,
88 fields: [
89 'username',
90 'privilege',
91 'status',
92 {
93 key: 'actions',
94 label: '',
95 tdClass: 'table-cell__actions'
96 }
97 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -080098 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060099 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600100 computed: {
101 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600102 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600103 },
104 tableItems() {
105 // transform user data to table data
106 return this.allUsers.map(user => {
107 return {
108 username: user.UserName,
109 privilege: user.RoleId,
110 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600111 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600112 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600113 ? 'Enabled'
114 : 'Disabled',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600115 actions: {
116 edit: true,
Derick Montaguee2fd1562019-12-20 13:26:53 -0600117 delete: user.UserName === 'root' ? false : true
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800118 },
119 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600120 };
121 });
122 }
123 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600124 created() {
125 this.getUsers();
126 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600127 methods: {
128 getUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600129 this.$store.dispatch('localUsers/getUsers');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800130 },
131 initModalUser(user) {
132 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600133 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800134 },
135 initModalDelete(user) {
136 this.$bvModal
137 .msgBoxConfirm(
138 `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`,
139 {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600140 title: 'Delete user',
141 okTitle: 'Delete user'
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800142 }
143 )
144 .then(deleteConfirmed => {
145 if (deleteConfirmed) {
146 this.deleteUser(user);
147 }
148 });
149 },
150 initModalSettings() {
151 if (this.settings) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600152 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800153 } else {
154 // fetch settings then show modal
155 }
156 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800157 saveUser({ isNewUser, userData }) {
158 if (isNewUser) {
159 this.$store.dispatch('localUsers/createUser', userData);
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800160 } else {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800161 this.$store.dispatch('localUsers/updateUser', userData);
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800162 }
163 },
164 deleteUser({ username }) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600165 this.$store.dispatch('localUsers/deleteUser', username);
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600166 }
167 }
168};
169</script>
170
171<style lang="scss" scoped>
172h1 {
173 margin-bottom: 2rem;
174}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800175.btn.collapsed {
176 svg {
177 transform: rotate(180deg);
178 }
179}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600180</style>