Update controllers to use new user model

This commit is contained in:
advplyr 2024-08-10 17:15:21 -05:00
parent 202ceb02b5
commit 68ef3a07a7
20 changed files with 396 additions and 304 deletions

View file

@ -5,16 +5,16 @@ const { toNumber } = require('../utils/index')
const fileUtils = require('../utils/fileUtils')
class FileSystemController {
constructor() { }
constructor() {}
/**
*
* @param {import('express').Request} req
* @param {import('express').Response} res
*
* @param {import('express').Request} req
* @param {import('express').Response} res
*/
async getPaths(req, res) {
if (!req.user.isAdminOrUp) {
Logger.error(`[FileSystemController] Non-admin user attempting to get filesystem paths`, req.user)
if (!req.userNew.isAdminOrUp) {
Logger.error(`[FileSystemController] Non-admin user "${req.userNew.username}" attempting to get filesystem paths`)
return res.sendStatus(403)
}
@ -22,7 +22,7 @@ class FileSystemController {
const level = toNumber(req.query.level, 0)
// Validate path. Must be absolute
if (relpath && (!Path.isAbsolute(relpath) || !await fs.pathExists(relpath))) {
if (relpath && (!Path.isAbsolute(relpath) || !(await fs.pathExists(relpath)))) {
Logger.error(`[FileSystemController] Invalid path in query string "${relpath}"`)
return res.status(400).send('Invalid "path" query string')
}
@ -40,7 +40,7 @@ class FileSystemController {
return []
})
if (drives.length) {
directories = drives.map(d => {
directories = drives.map((d) => {
return {
path: d,
dirname: d,
@ -54,10 +54,10 @@ class FileSystemController {
}
// Exclude some dirs from this project to be cleaner in Docker
const excludedDirs = ['node_modules', 'client', 'server', '.git', 'static', 'build', 'dist', 'metadata', 'config', 'sys', 'proc', '.devcontainer', '.nyc_output', '.github', '.vscode'].map(dirname => {
const excludedDirs = ['node_modules', 'client', 'server', '.git', 'static', 'build', 'dist', 'metadata', 'config', 'sys', 'proc', '.devcontainer', '.nyc_output', '.github', '.vscode'].map((dirname) => {
return fileUtils.filePathToPOSIX(Path.join(global.appRoot, dirname))
})
directories = directories.filter(dir => {
directories = directories.filter((dir) => {
return !excludedDirs.includes(dir.path)
})
@ -69,8 +69,8 @@ class FileSystemController {
// POST: api/filesystem/pathexists
async checkPathExists(req, res) {
if (!req.user.canUpload) {
Logger.error(`[FileSystemController] Non-admin user attempting to check path exists`, req.user)
if (!req.userNew.canUpload) {
Logger.error(`[FileSystemController] Non-admin user "${req.userNew.username}" attempting to check path exists`)
return res.sendStatus(403)
}
@ -85,4 +85,4 @@ class FileSystemController {
})
}
}
module.exports = new FileSystemController()
module.exports = new FileSystemController()