Another batch of important updates and fixes

This commit is contained in:
Luka Romih
2026-02-23 15:29:58 +01:00
parent d0e53fee3b
commit fd02e25719
40 changed files with 216 additions and 71 deletions
+10
View File
@@ -0,0 +1,10 @@
const db = require('../db')
const Misc = {}
// Log a successful honeypot catch.
Misc.logHoneypotCatch = async body => {
await db.query('INSERT INTO honeypot_log (body_content) VALUES ($1)', [body])
}
module.exports = Misc
+11 -3
View File
@@ -330,7 +330,15 @@ User.fetchDeserializedDataById = async userId => {
}
// Fetch all registered users on the portal
User.fetchAll = async (resultsPerPage, page) => {
User.fetchAll = async (resultsPerPage, page, hideInactive) => {
// hideInactive was added to hide bot spammed accounts. Using the 'inactive' status might be more appropriate as a filtering criteria in the future.
const whereClause = `WHERE status ${
hideInactive
? `= 'active' OR (status = 'registered' AND NOW() - time_registered < '${ACTIVATION_TOKEN_VALID_DAYS} days')`
: "<> 'closed'"
}`
const {
rows: [{ result }]
} = await db.query(
@@ -339,7 +347,7 @@ User.fetchAll = async (resultsPerPage, page) => {
'pages_total', (
SELECT CEIL(COUNT(*) / $1::float)
FROM "user"
WHERE status <> 'closed'
${whereClause}
),
'results', ARRAY(
SELECT jsonb_build_object(
@@ -349,7 +357,7 @@ User.fetchAll = async (resultsPerPage, page) => {
'status', status
)
FROM "user"
WHERE status <> 'closed'
${whereClause}
ORDER BY username
LIMIT $1
OFFSET $2