CJVT updates August and September 2026
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* global __ */
|
||||
|
||||
const { getInstanceSetting } = require('../../models/helpers')
|
||||
const { getInstanceSetting, intoDbArray } = require('../../models/helpers')
|
||||
const Dictionary = require('../../models/dictionary')
|
||||
const cache = require('../../models/cache')
|
||||
const { promisify } = require('util')
|
||||
@@ -194,6 +194,53 @@ exports.statusChangeCheckAndAct = {
|
||||
}
|
||||
}
|
||||
|
||||
// Whitelist of admin dictionary-list sortable columns, keeping req.query
|
||||
// values from ever reaching raw SQL - see models/dictionary.js
|
||||
// fetchAllAdminDictionaries.
|
||||
const DICTIONARY_LIST_SORT_COLUMNS = [
|
||||
'id',
|
||||
'name',
|
||||
'status',
|
||||
'timeCreated',
|
||||
'timeModified'
|
||||
]
|
||||
|
||||
// Resolves the admin dictionary-list sort params from a request query,
|
||||
// defaulting to id/desc when absent or invalid.
|
||||
exports.resolveDictionarySort = (querySort, queryDir) => ({
|
||||
sortBy: DICTIONARY_LIST_SORT_COLUMNS.includes(querySort) ? querySort : 'id',
|
||||
sortDir: queryDir === 'asc' ? 'asc' : 'desc'
|
||||
})
|
||||
|
||||
const DICTIONARY_STATUSES = ['closed', 'reviewed', 'published']
|
||||
exports.DICTIONARY_STATUSES = DICTIONARY_STATUSES
|
||||
|
||||
// Keeps only numeric-looking id strings, matching the option values the
|
||||
// admin filter selects render (real DB smallint ids) - drops anything else
|
||||
// rather than letting it reach a ::smallint[] cast in SQL.
|
||||
const toNumericIdArray = ids => {
|
||||
if (!ids) return null
|
||||
const numericIds = ids.filter(id => /^\d+$/.test(id))
|
||||
return numericIds.length > 0 ? numericIds : null
|
||||
}
|
||||
|
||||
// Parses/whitelists the admin dictionary-list search+filter params from a
|
||||
// request query. A filter category left unselected resolves to null ("no
|
||||
// filter"), never an empty array (which would match zero rows in SQL).
|
||||
exports.parseDictionaryListFilters = query => {
|
||||
const rawStatuses = intoDbArray(query.status)
|
||||
const statuses = rawStatuses
|
||||
? rawStatuses.filter(value => DICTIONARY_STATUSES.includes(value))
|
||||
: null
|
||||
return {
|
||||
nameQuery: typeof query.q === 'string' ? query.q.trim() : '',
|
||||
primaryDomainIds: toNumericIdArray(intoDbArray(query.pd)),
|
||||
secondaryDomainIds: toNumericIdArray(intoDbArray(query.sd)),
|
||||
languageIds: toNumericIdArray(intoDbArray(query.lang)),
|
||||
statuses: statuses && statuses.length > 0 ? statuses : null
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function used by statusChangeCheckAndAct methods.
|
||||
async function renderAndSendStatusChangeEmails(
|
||||
appRef,
|
||||
|
||||
Reference in New Issue
Block a user