blob: 6a8300b7271bfc2e0c3ec7ab4589e46c4556b295 [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">
7 <icon-settings />
8 Account policy settings
9 </b-button>
10 <b-button @click="initModalUser(null)" variant="primary">
11 <icon-add />
12 Add user
13 </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>
Yoshie Muranaka463a5702019-12-04 09:09:36 -080062import 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";
66
67import TableRoles from "./TableRoles";
68import ModalUser from "./ModalUser";
69import ModalSettings from "./ModalSettings";
Yoshie Muranaka8d129102019-12-19 09:51:55 -080070import PageTitle from "../../../components/Global/PageTitle";
Yoshie Muranaka35080ac2020-01-17 15:38:57 -060071
72export default {
73 name: "local-users",
74 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() {
95 return this.$store.getters["localUsers/allUsers"];
96 },
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
104 ? "Locked"
105 : user.Enabled
106 ? "Enabled"
107 : "Disabled",
108 actions: {
109 edit: true,
110 delete: user.UserName === "root" ? false : true
111 }
112 };
113 });
114 }
115 },
116 methods: {
117 getUsers() {
118 this.$store.dispatch("localUsers/getUsers");
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800119 },
120 initModalUser(user) {
121 this.activeUser = user;
122 this.$bvModal.show("modal-user");
123 },
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 {
129 title: "Delete user",
130 okTitle: "Delete user"
131 }
132 )
133 .then(deleteConfirmed => {
134 if (deleteConfirmed) {
135 this.deleteUser(user);
136 }
137 });
138 },
139 initModalSettings() {
140 if (this.settings) {
141 this.$bvModal.show("modal-settings");
142 } else {
143 // fetch settings then show modal
144 }
145 },
146 saveUser({ newUser, form }) {
147 if (newUser) {
148 this.$store.dispatch("localUsers/createUser", form);
149 } else {
150 this.$store.dispatch("localUsers/updateUser", form);
151 }
152 },
153 deleteUser({ username }) {
154 this.$store.dispatch("localUsers/deleteUser", username);
155 },
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>