blob: c6716798b4e24b6d55e9da17c9bddc6401f86edf [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 Muranaka35080ac2020-01-17 15:38:57 -06003 <b-row>
Yoshie Muranaka463a5702019-12-04 09:09:36 -08004 <b-col lg="10">
Yoshie Muranaka35080ac2020-01-17 15:38:57 -06005 <h1>Local user management</h1>
6 </b-col>
7 </b-row>
8 <b-row>
Yoshie Muranaka463a5702019-12-04 09:09:36 -08009 <b-col lg="10">
10 <b-button @click="initModalSettings" variant="link">
11 <icon-settings />
12 Account policy settings
13 </b-button>
14 <b-button @click="initModalUser(null)" variant="primary">
15 <icon-add />
16 Add user
17 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060018 </b-col>
19 </b-row>
20 <b-row>
Yoshie Muranaka463a5702019-12-04 09:09:36 -080021 <b-col lg="10">
22 <b-table bordered show-empty head-variant="dark" :items="tableItems">
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060023 <template v-slot:head(actions)="data"></template>
24 <template v-slot:cell(actions)="data">
25 <b-button
Yoshie Muranaka463a5702019-12-04 09:09:36 -080026 aria-label="Edit user"
27 variant="link"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060028 :disabled="!data.value.edit"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080029 @click="initModalUser(data.item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060030 >
Yoshie Muranaka463a5702019-12-04 09:09:36 -080031 <icon-edit />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060032 </b-button>
33 <b-button
Yoshie Muranaka463a5702019-12-04 09:09:36 -080034 aria-label="Delete user"
35 variant="link"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060036 :disabled="!data.value.delete"
Yoshie Muranaka463a5702019-12-04 09:09:36 -080037 @click="initModalDelete(data.item)"
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060038 >
Yoshie Muranaka463a5702019-12-04 09:09:36 -080039 <icon-trashcan />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060040 </b-button>
41 </template>
42 </b-table>
43 </b-col>
44 </b-row>
45 <b-row>
Yoshie Muranaka463a5702019-12-04 09:09:36 -080046 <b-col lg="8">
47 <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3">
48 View privilege role descriptions
49 </b-button>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060050 <b-collapse id="collapse-role-table" class="mt-3">
Yoshie Muranaka463a5702019-12-04 09:09:36 -080051 <table-roles />
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060052 </b-collapse>
53 </b-col>
54 </b-row>
55 <!-- Modals -->
Yoshie Muranaka463a5702019-12-04 09:09:36 -080056 <modal-settings v-bind:settings="settings"></modal-settings>
57 <modal-user
58 v-bind:user="activeUser"
59 @ok="saveUser"
60 @hidden="clearActiveUser"
61 ></modal-user>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060062 </b-container>
Derick Montaguea2988f42020-01-17 13:46:30 -060063</template>
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060064
65<script>
Yoshie Muranaka463a5702019-12-04 09:09:36 -080066import IconTrashcan from "@carbon/icons-vue/es/trash-can/20";
67import IconEdit from "@carbon/icons-vue/es/edit/20";
68import IconAdd from "@carbon/icons-vue/es/add--alt/20";
69import IconSettings from "@carbon/icons-vue/es/settings/20";
70
71import TableRoles from "./TableRoles";
72import ModalUser from "./ModalUser";
73import ModalSettings from "./ModalSettings";
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060074
75export default {
76 name: "local-users",
77 components: {
Yoshie Muranaka463a5702019-12-04 09:09:36 -080078 IconAdd,
79 IconEdit,
80 IconSettings,
81 IconTrashcan,
82 ModalSettings,
83 ModalUser,
84 TableRoles
85 },
86 data() {
87 return {
88 activeUser: null,
89 settings: null
90 };
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060091 },
92 created() {
93 this.getUsers();
94 },
95 computed: {
96 allUsers() {
97 return this.$store.getters["localUsers/allUsers"];
98 },
99 tableItems() {
100 // transform user data to table data
101 return this.allUsers.map(user => {
102 return {
103 username: user.UserName,
104 privilege: user.RoleId,
105 status: user.Locked
106 ? "Locked"
107 : user.Enabled
108 ? "Enabled"
109 : "Disabled",
110 actions: {
111 edit: true,
112 delete: user.UserName === "root" ? false : true
113 }
114 };
115 });
116 }
117 },
118 methods: {
119 getUsers() {
120 this.$store.dispatch("localUsers/getUsers");
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800121 },
122 initModalUser(user) {
123 this.activeUser = user;
124 this.$bvModal.show("modal-user");
125 },
126 initModalDelete(user) {
127 this.$bvModal
128 .msgBoxConfirm(
129 `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`,
130 {
131 title: "Delete user",
132 okTitle: "Delete user"
133 }
134 )
135 .then(deleteConfirmed => {
136 if (deleteConfirmed) {
137 this.deleteUser(user);
138 }
139 });
140 },
141 initModalSettings() {
142 if (this.settings) {
143 this.$bvModal.show("modal-settings");
144 } else {
145 // fetch settings then show modal
146 }
147 },
148 saveUser({ newUser, form }) {
149 if (newUser) {
150 this.$store.dispatch("localUsers/createUser", form);
151 } else {
152 this.$store.dispatch("localUsers/updateUser", form);
153 }
154 },
155 deleteUser({ username }) {
156 this.$store.dispatch("localUsers/deleteUser", username);
157 },
158 clearActiveUser() {
159 this.activeUser = null;
Yoshie Muranaka35080ac2020-01-17 15:38:57 -0600160 }
161 }
162};
163</script>
164
165<style lang="scss" scoped>
166h1 {
167 margin-bottom: 2rem;
168}
169</style>