Skip to content

Commit b8abc7b

Browse files
committed
Admin Management Roles tab updated.
1 parent faf1000 commit b8abc7b

File tree

2 files changed

+125
-126
lines changed

2 files changed

+125
-126
lines changed

src/htdocs-admin/src/components/Roles.vue

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,16 @@
1616
<v-icon v-if="!item.children"> mdi-security </v-icon>
1717
</template>
1818
</v-treeview>
19-
<v-tooltip bottom>
20-
<template v-slot:activator="{ on, attrs }">
2119
<v-btn
22-
v-bind="attrs"
23-
v-on="on"
24-
class="mx-2"
25-
fab
20+
class="mt-6"
2621
dark
2722
x-small
2823
color="blue"
2924
@click="createRole($event)"
3025
>
3126
<v-icon dark> mdi-plus </v-icon>
27+
New Role
3228
</v-btn>
33-
</template>
34-
<span>New role!</span>
35-
</v-tooltip>
3629
</v-col>
3730

3831
<v-divider vertical></v-divider>
@@ -51,6 +44,7 @@
5144
<v-text-field
5245
prepend-inner-icon="mdi-security"
5346
type="text"
47+
:disabled="selected.name==='admin' ? true : false"
5448
outlined
5549
clearable
5650
:input-value="active"
@@ -62,6 +56,7 @@
6256
<v-tooltip bottom>
6357
<template v-slot:activator="{ on, attrs }">
6458
<v-btn
59+
v-if="!(selected.name==='admin')"
6560
v-bind="attrs"
6661
v-on="on"
6762
class="mx-2"
@@ -78,8 +73,6 @@
7873
</v-tooltip>
7974
</v-row>
8075

81-
82-
8376
<v-autocomplete
8477
v-model="selected.group1List"
8578
:items="group1ListAll"
@@ -113,6 +106,7 @@
113106
<template v-slot:default="{ active }">
114107
<v-list-item-action>
115108
<v-checkbox
109+
:disabled="selected.name==='admin' ? true : false"
116110
:input-value="active"
117111
v-model="selected.isAdmin"
118112
@change="roleChange"
@@ -134,6 +128,7 @@
134128
<template v-slot:default="{ active }">
135129
<v-list-item-action>
136130
<v-checkbox
131+
:disabled="selected.name==='admin' ? true : false"
137132
:input-value="active"
138133
v-model="selected.changePassword"
139134
@change="roleChange"
@@ -518,7 +513,7 @@ export default {
518513
.then((res) => res.json())
519514
.then((json) => {
520515
if (json.error) console.log(json);
521-
this.fetchRoles(); // refreshes roles
516+
this.fetchRoles(); // refreshes roles
522517
})
523518
.catch((err) => console.warn(err));
524519
},

src/htdocs-admin/src/components/Users.vue

Lines changed: 118 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,19 @@
1414
>
1515
<template v-slot:prepend="{ item }">
1616
<v-icon v-if="!item.children"> mdi-account </v-icon>
17-
{{item.username}}
17+
{{ item.username }}
1818
</template>
1919
</v-treeview>
20-
<v-tooltip bottom>
21-
<template v-slot:activator="{ on, attrs }">
22-
<v-btn
23-
v-bind="attrs"
24-
v-on="on"
25-
class="mx-2"
26-
fab
27-
dark
28-
x-small
29-
color="blue"
30-
@click="createUser($event)"
31-
>
32-
<v-icon dark> mdi-plus </v-icon>
33-
</v-btn>
34-
</template>
35-
<span>New user!</span>
36-
</v-tooltip>
20+
<v-btn
21+
class="mt-6"
22+
dark
23+
x-small
24+
color="blue"
25+
@click="createUser($event)"
26+
>
27+
<v-icon dark> mdi-plus </v-icon>
28+
New User
29+
</v-btn>
3730
</v-col>
3831

3932
<v-divider vertical></v-divider>
@@ -54,10 +47,10 @@
5447
flat
5548
max-width="400"
5649
>
57-
58-
<v-row class="pb-8 mx-auto" justify="space-between">
50+
<v-row class="pb-8 mx-auto" justify="space-between">
5951
<v-text-field
6052
prepend-inner-icon="mdi-account"
53+
:disabled="selected.username==='admin' ? true : false"
6154
type="text"
6255
outlined
6356
clearable
@@ -70,6 +63,7 @@
7063
<v-tooltip bottom>
7164
<template v-slot:activator="{ on, attrs }">
7265
<v-btn
66+
v-if="!(selected.username==='admin')"
7367
v-bind="attrs"
7468
v-on="on"
7569
class="mx-2"
@@ -84,100 +78,104 @@
8478
</template>
8579
<span>Delete user!</span>
8680
</v-tooltip>
87-
</v-row>
88-
89-
<v-text-field
90-
class="pb-8"
91-
prepend-inner-icon="mdi-email"
92-
type="text"
93-
outlined
94-
clearable
95-
:input-value="active"
96-
label="email"
97-
hide-details="auto"
98-
v-model="selected.email"
99-
@change="updateUser"
100-
></v-text-field>
81+
</v-row>
10182

102-
<v-text-field
103-
prepend-inner-icon="mdi-account-key"
104-
type="password"
105-
outlined
106-
clearable
107-
:input-value="active"
108-
label="password"
109-
hide-details="auto"
110-
v-model="selected.password"
111-
@change="updateUser"
112-
></v-text-field>
83+
<v-text-field
84+
class="pb-8"
85+
prepend-inner-icon="mdi-email"
86+
type="text"
87+
outlined
88+
clearable
89+
:input-value="active"
90+
label="email"
91+
hide-details="auto"
92+
v-model="selected.email"
93+
@change="updateUser"
94+
></v-text-field>
11395

114-
<v-divider></v-divider>
96+
<v-text-field
97+
prepend-inner-icon="mdi-account-key"
98+
type="password"
99+
outlined
100+
clearable
101+
:input-value="active"
102+
label="password"
103+
hide-details="auto"
104+
v-model="selected.password"
105+
@change="updateUser"
106+
></v-text-field>
115107

116-
<v-card-text>
117-
<v-icon x-large color="primary darken-2">mdi-security</v-icon>
118-
<h3 class="headline mb-2">ROLES</h3>
119-
<v-menu :load-children="fetchRoles">
120-
<template v-slot:activator="{ on: menu, attrs }">
121-
<v-tooltip bottom>
122-
<template v-slot:activator="{ on: tooltip }">
123-
<v-btn
124-
color="primary"
125-
fab
126-
dark
127-
x-small
128-
v-bind="attrs"
129-
v-on="{ ...tooltip, ...menu }"
130-
@click="fetchRoles()"
131-
>
132-
<v-icon dark> mdi-plus </v-icon>
133-
</v-btn>
134-
</template>
135-
<span>Add Role</span>
136-
</v-tooltip>
137-
</template>
138-
<v-list>
139-
<v-list-item
140-
v-for="(item, index) in roles"
141-
:key="index"
142-
@click="addRoleToUser($event, item.name)"
143-
>
144-
<v-list-item-title>{{ item.name }}</v-list-item-title>
145-
</v-list-item>
108+
<v-card class="my-4" tile>
109+
<v-card-text>
110+
<v-icon x-large color="primary darken-2">mdi-security</v-icon>
111+
<h3 class="headline mb-2">ROLES</h3>
112+
<v-menu :load-children="fetchRoles">
113+
<template v-slot:activator="{ on: menu, attrs }">
114+
<v-tooltip bottom>
115+
<template v-slot:activator="{ on: tooltip }">
116+
<v-btn
117+
color="primary"
118+
fab
119+
dark
120+
x-small
121+
v-bind="attrs"
122+
v-on="{ ...tooltip, ...menu }"
123+
@click="fetchRoles()"
124+
>
125+
<v-icon dark> mdi-plus </v-icon>
126+
</v-btn>
127+
</template>
128+
<span>Add Role</span>
129+
</v-tooltip>
130+
</template>
131+
<v-list>
132+
<v-list-item
133+
v-for="(item, index) in roles"
134+
:key="index"
135+
@click="addRoleToUser($event, item.name)"
136+
>
137+
<v-list-item-title>{{ item.name }}</v-list-item-title>
138+
</v-list-item>
139+
</v-list>
140+
</v-menu>
141+
</v-card-text>
142+
<v-card class="mx-auto" tile>
143+
<v-list nav dense>
144+
<v-list-item-group color="primary">
145+
<v-list-item v-for="(item, i) in selected.roles" :key="i">
146+
<v-list-item-icon>
147+
<v-icon>mdi-security</v-icon>
148+
</v-list-item-icon>
149+
<v-list-item-content>
150+
<v-list-item-title
151+
class="primary--text subheading font-weight-bold"
152+
v-text="item.name"
153+
></v-list-item-title>
154+
</v-list-item-content>
155+
<v-list-item-action>
156+
<v-tooltip bottom>
157+
<template v-slot:activator="{ on, attrs }">
158+
<v-btn
159+
:disabled="(selected.username==='admin' && item.name==='admin')"
160+
v-bind="attrs"
161+
v-on="on"
162+
class="mx-2"
163+
fab
164+
dark
165+
x-small
166+
color="red"
167+
@click="removeRoleFromUser($event, item.name)"
168+
>
169+
<v-icon dark> mdi-minus </v-icon>
170+
</v-btn>
171+
</template>
172+
<span>Remove role!</span>
173+
</v-tooltip>
174+
</v-list-item-action>
175+
</v-list-item>
176+
</v-list-item-group>
146177
</v-list>
147-
</v-menu>
148-
</v-card-text>
149-
<v-card class="mx-auto" max-width="400" tile>
150-
<v-list nav dense>
151-
<v-list-item-group color="primary">
152-
<v-list-item v-for="(item, i) in selected.roles" :key="i">
153-
<v-list-item-content>
154-
<v-list-item-title
155-
class="primary--text subheading font-weight-bold"
156-
v-text="item.name"
157-
></v-list-item-title>
158-
</v-list-item-content>
159-
<v-list-item-action>
160-
<v-tooltip bottom>
161-
<template v-slot:activator="{ on, attrs }">
162-
<v-btn
163-
v-bind="attrs"
164-
v-on="on"
165-
class="mx-2"
166-
fab
167-
dark
168-
x-small
169-
color="red"
170-
@click="removeRoleFromUser($event, item.name)"
171-
>
172-
<v-icon dark> mdi-minus </v-icon>
173-
</v-btn>
174-
</template>
175-
<span>Remove role!</span>
176-
</v-tooltip>
177-
</v-list-item-action>
178-
</v-list-item>
179-
</v-list-item-group>
180-
</v-list>
178+
</v-card>
181179
</v-card>
182180
</v-card>
183181
</v-scroll-y-transition>
@@ -224,6 +222,12 @@ export default {
224222
225223
methods: {
226224
async addRoleToUser(evt, roleName) {
225+
console.log(this.selected.roles)
226+
if (this.selected.roles.some(e => e.name === roleName))
227+
return
228+
229+
if (this.selected.roles.includes(roleName))
230+
return
227231
return await fetch("/Invoke/auth/userAddRole", {
228232
method: "post",
229233
headers: {
@@ -305,10 +309,10 @@ export default {
305309
async updateUser() {
306310
var userDup = Object.assign({}, this.selected);
307311
delete userDup["id"];
308-
if ("password" in userDup )
309-
if (userDup.password === "" || userDup.password===null)
310-
delete userDup["password"];
311-
this.selected.password=""
312+
if ("password" in userDup)
313+
if (userDup.password === "" || userDup.password === null)
314+
delete userDup["password"];
315+
this.selected.password = "";
312316
return await fetch("/Invoke/auth/updateUser", {
313317
method: "post",
314318
headers: {

0 commit comments

Comments
 (0)