blob: e71387da30e992c25369a285540d3b43687ee6bd [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 Muranaka0fc91e72020-02-05 11:23:06 -080070import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060071
72export default {
Derick Montague09e45cd2020-01-23 15:45:57 -060073 name: 'LocalUsers',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060074 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -080075 IconAdd,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080076 IconChevron,
Yoshie Muranaka463a5702019-12-04 09:09:36 -080077 IconEdit,
78 IconSettings,
79 IconTrashcan,
80 ModalSettings,
81 ModalUser,
Yoshie Muranaka8d129102019-12-19 09:51:55 -080082 TableRoles,
83 PageTitle
Yoshie Muranaka463a5702019-12-04 09:09:36 -080084 },
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -080085 mixins: [BVToastMixin],
Yoshie Muranaka463a5702019-12-04 09:09:36 -080086 data() {
87 return {
88 activeUser: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080089 settings: null,
90 fields: [
91 'username',
92 'privilege',
93 'status',
94 {
95 key: 'actions',
96 label: '',
97 tdClass: 'table-cell__actions'
98 }
99 ]
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800100 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600101 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600102 computed: {
103 allUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600104 return this.$store.getters['localUsers/allUsers'];
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600105 },
106 tableItems() {
107 // transform user data to table data
108 return this.allUsers.map(user => {
109 return {
110 username: user.UserName,
111 privilege: user.RoleId,
112 status: user.Locked
Derick Montaguee2fd1562019-12-20 13:26:53 -0600113 ? 'Locked'
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600114 : user.Enabled
Derick Montaguee2fd1562019-12-20 13:26:53 -0600115 ? 'Enabled'
116 : 'Disabled',
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600117 actions: {
118 edit: true,
Derick Montaguee2fd1562019-12-20 13:26:53 -0600119 delete: user.UserName === 'root' ? false : true
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800120 },
121 ...user
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600122 };
123 });
124 }
125 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600126 created() {
127 this.getUsers();
128 },
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600129 methods: {
130 getUsers() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600131 this.$store.dispatch('localUsers/getUsers');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800132 },
133 initModalUser(user) {
134 this.activeUser = user;
Derick Montaguee2fd1562019-12-20 13:26:53 -0600135 this.$bvModal.show('modal-user');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800136 },
137 initModalDelete(user) {
138 this.$bvModal
139 .msgBoxConfirm(
140 `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`,
141 {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600142 title: 'Delete user',
143 okTitle: 'Delete user'
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800144 }
145 )
146 .then(deleteConfirmed => {
147 if (deleteConfirmed) {
148 this.deleteUser(user);
149 }
150 });
151 },
152 initModalSettings() {
153 if (this.settings) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600154 this.$bvModal.show('modal-settings');
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800155 } else {
156 // fetch settings then show modal
157 }
158 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800159 saveUser({ isNewUser, userData }) {
160 if (isNewUser) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800161 this.$store
162 .dispatch('localUsers/createUser', userData)
163 .then(success => this.successToast(success))
164 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800165 } else {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800166 this.$store
167 .dispatch('localUsers/updateUser', userData)
168 .then(success => this.successToast(success))
169 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800170 }
171 },
172 deleteUser({ username }) {
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800173 this.$store
174 .dispatch('localUsers/deleteUser', username)
175 .then(success => this.successToast(success))
176 .catch(({ message }) => this.errorToast(message));
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600177 }
178 }
179};
180</script>
181
182<style lang="scss" scoped>
183h1 {
184 margin-bottom: 2rem;
185}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800186.btn.collapsed {
187 svg {
188 transform: rotate(180deg);
189 }
190}
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600191</style>