Added ID and uploads count columns into manage users

Updated client-side check of user's enabled status to match server-side

Removed a bunch of console.log()'s from development
This commit is contained in:
Bobby Wibowo 2018-10-12 16:42:16 +07:00
parent 5cf8480959
commit 31f44a1b91
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
4 changed files with 33 additions and 10 deletions

View File

@ -248,9 +248,28 @@ authController.listUsers = async (req, res, next) => {
.offset(25 * offset)
.select('id', 'username', 'enabled', 'fileLength', 'permission')
const userids = []
for (const user of users) {
user.groups = authController.mapPermissions(user)
delete user.permission
userids.push(user.id)
user.uploadsCount = 0
}
if (!userids.length) { return res.json({ success: true, users }) }
const maps = {}
const uploads = await db.table('files').whereIn('userid', userids)
for (const upload of uploads) {
// This is the fastest method that I can think of
if (maps[upload.userid] === undefined) { maps[upload.userid] = 0 }
maps[upload.userid]++
}
for (const user of users) {
user.uploadsCount = maps[user.id] || 0
}
return res.json({ success: true, users })

View File

@ -38,7 +38,10 @@ migration.start = async () => {
.update({
permission: permissions.superadmin
})
.then(() => console.log(`Updated root's permission to ${permissions.superadmin} (superadmin).`))
.then(rows => {
if (!rows) { return console.log('Unable to update root\'s permission into superadmin.') }
console.log(`Updated root's permission to ${permissions.superadmin} (superadmin).`)
})
console.log('Migration finished! Now start lolisafe normally')
process.exit(0)

View File

@ -96,7 +96,6 @@ page.verifyToken = function (token, reloadOnError) {
page.token = token
page.username = response.data.username
page.permissions = response.data.permissions
console.log(page.username, page.permissions)
page.prepareDashboard()
}).catch(function (error) {
console.log(error)
@ -277,7 +276,6 @@ page.getUploads = function ({ album, pageNum, all } = {}, element) {
return swal('An error occurred!', 'You can not do this!', 'error')
}
console.log(url, all)
axios.get(url, {
headers: {
all: all ? '1' : '0'
@ -1510,7 +1508,6 @@ page.getUsers = ({ pageNum } = {}, element) => {
}
const url = `api/users/${pageNum}`
console.log(url)
axios.get(url).then(function (response) {
if (response.data.success === false) {
if (response.data.description === 'No token provided') {
@ -1526,8 +1523,6 @@ page.getUsers = ({ pageNum } = {}, element) => {
return swal('An error occurred!', 'There are no more users!', 'error')
}
console.log(response.data.users)
page.currentView = 'users'
page.cache.users = {}
@ -1574,7 +1569,9 @@ page.getUsers = ({ pageNum } = {}, element) => {
<thead>
<tr>
<th><input id="selectAll" class="checkbox" type="checkbox" title="Select all users" data-action="select-all"></th>
<th style="width: 50%">Username</th>
<th>ID</th>
<th style="width: 25%">Username</th>
<th>Uploads</th>
<th>File length</th>
<th>Group</th>
<th></th>
@ -1601,10 +1598,12 @@ page.getUsers = ({ pageNum } = {}, element) => {
displayGroup = group
}
// Server-side explicitly expects either of these two values to consider a user as disabled
const enabled = user.enabled !== false && user.enabled !== 0
page.cache.users[user.id] = {
username: user.username,
groups: user.groups,
enabled: user.enabled,
enabled,
displayGroup
}
@ -1612,7 +1611,9 @@ page.getUsers = ({ pageNum } = {}, element) => {
tr.dataset.id = user.id
tr.innerHTML = `
<th class="controls"><input type="checkbox" class="checkbox" title="Select this user" data-action="select"${selected ? ' checked' : ''}></th>
<th${!user.enabled ? ' class="is-linethrough"' : ''}>${user.username}</th>
<th>${user.id}</th>
<th${enabled ? '' : ' class="is-linethrough"'}>${user.username}</th>
<th>${user.uploadsCount}</th>
<td>${user.fileLength || 'default'}</td>
<td>${displayGroup}</td>
<td class="controls" style="text-align: right">

View File

@ -15,7 +15,7 @@
v2: Images and config files (manifest.json, browserconfig.xml, etc).
v3: CSS and JS files (libs such as bulma, lazyload, etc).
#}
{% set v1 = "JxZhgFgBYY" %}
{% set v1 = "fvsYyXUQZE" %}
{% set v2 = "Ii3JYKIhb0" %}
{% set v3 = "4TRCinLWfk" %}