-
Notifications
You must be signed in to change notification settings - Fork 4
/
users.vue
179 lines (153 loc) · 3.69 KB
/
users.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
<div class="users">
<h1>Users</h1>
<table>
<tr>
<th class="column-name">User name</th>
<th class="column-id">ID</th>
<th class="column-role">Role</th>
</tr>
<tr v-for="user in users">
<td class="column-name">
{{user.user}}
</td>
<td class="column-id">
{{user.id}}
</td>
<td class="column-role">
<template v-if="roles.find(role => role.role === user.role).static">
{{roles.find(role => role.role === user.role).name}}
</template>
<select v-else>
<option v-for="role in roles" @click="!role.static && use(user, role.role)" :disabled="role.static" :selected="role.role === user.role">
{{role.name}}
<template v-if="role.default">(default)</template>
<template v-if="role.static">
<template v-if="role.autoGranted">(auto-granted)</template>
<template v-else>(granted by admin)</template>
</template>
</option>
</select>
</td>
</tr>
<tr v-if="siteInfo.settings.own || isModerator">
<td class="column-name">
<i>New user</i>
</td>
<td class="column-id no-padding">
<input type="text" placeholder="Fill in user ID" :class="{'input-error': newId === 'Please, fill in user ID'}" required v-model="newId">
</td>
<td class="column-role">
<div class="icons">
<span class="icon" @click="next">
<icon name="caret-square-right" />
Next
</span>
</div>
</td>
</tr>
</table>
<div class="desc">
Role description:
<div v-for="role in roles">
<b>
{{role.name}}
<i v-if="role.default">(default)</i>
<i v-if="role.static">
<template v-if="role.autoGranted">(auto-granted)</template>
<template v-else>(granted by admin)</template>
</i>
</b>
—
{{role.description}}
</div>
</div>
</div>
</template>
<style lang="sass" scoped>
@import "../global.sass"
.users
padding: 16px
.column-user
width: 25%
.column-id
width: 50%
.column-role
width: 25%
.input-error
color: #803
.icons
float: right
.icon
cursor: pointer
margin-left: 8px
color: lighten(#803, 10%)
.desc
margin-top: 32px
margin-bottom: -8px
font-family: Verdana, Arial, sans-serif
font-size: 16px
</style>
<script type="text/javascript">
import {zeroAuth} from "../../../zero";
import Users from "../../../libs/users.js";
import roles from "./roles";
export default {
name: "admin-users",
data() {
return {
newId: "",
siteInfo: {
settings: {
own: false
}
}
};
},
mounted() {
this.$eventBus.$on("setSiteInfo", this.setSiteInfo);
this.$eventBus.$emit("needSiteInfo");
},
destroyed() {
this.$eventBus.$off("setSiteInfo", this.setSiteInfo);
},
computed: {
roles() {
return roles(this.siteInfo);
}
},
asyncComputed: {
async users() {
return await Users.getAllRules();
},
async isModerator() {
const auth = zeroAuth.getAuth();
if(!auth) {
return false;
}
return await Users.hasRoleByAddress(auth.address, "moderator");
}
},
methods: {
setSiteInfo(siteInfo) {
this.siteInfo = siteInfo;
},
async next() {
if(!this.newId || this.newId === "Please, fill in user ID") {
this.newId = "Please, fill in user ID";
return;
}
let user = {id: this.newId, role: "user"};
user.certUserId = await Users.addressToCertUserId(user.id);
user.user = user.certUserId.replace(/@.*/, "");
user.roleId = ["admin", "moderator", "author", "user", "banned"].indexOf(user.role);
this.users.push(user);
this.newId = "";
},
async use(user, role) {
await Users.setRoleByAddress(user.id, role);
user.role = role;
}
}
};
</script>