make auditsource a class
this allows us to use AuditSource for the class and auditSource for the instances!
This commit is contained in:
@@ -26,7 +26,7 @@ exports = module.exports = {
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
auditSource = require('../auditsource.js'),
|
||||
AuditSource = require('../auditsource.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
cloudron = require('../cloudron.js'),
|
||||
constants = require('../constants.js'),
|
||||
@@ -72,7 +72,7 @@ async function login(req, res, next) {
|
||||
async function logout(req, res) {
|
||||
assert.strictEqual(typeof req.access_token, 'string');
|
||||
|
||||
eventlog.add(eventlog.ACTION_USER_LOGOUT, auditSource.fromRequest(req), { userId: req.user.id, user: users.removePrivateFields(req.user) });
|
||||
eventlog.add(eventlog.ACTION_USER_LOGOUT, AuditSource.fromRequest(req), { userId: req.user.id, user: users.removePrivateFields(req.user) });
|
||||
|
||||
await safe(tokens.delByAccessToken(req.access_token));
|
||||
res.redirect('/login.html');
|
||||
@@ -81,7 +81,7 @@ async function logout(req, res) {
|
||||
async function passwordResetRequest(req, res, next) {
|
||||
if (!req.body.identifier || typeof req.body.identifier !== 'string') return next(new HttpError(401, 'A identifier must be non-empty string'));
|
||||
|
||||
const [error, result] = await safe(users.sendPasswordResetByIdentifier(req.body.identifier, auditSource.fromRequest(req)));
|
||||
const [error, result] = await safe(users.sendPasswordResetByIdentifier(req.body.identifier, AuditSource.fromRequest(req)));
|
||||
if (error && error.reason !== BoxError.NOT_FOUND) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, { resetLink: result }));
|
||||
@@ -109,7 +109,7 @@ async function passwordReset(req, res, next) {
|
||||
if (!userObject.username) return next(new HttpError(409, 'No username set'));
|
||||
|
||||
// setPassword clears the resetToken
|
||||
[error] = await safe(users.setPassword(userObject, req.body.password, auditSource.fromRequest(req)));
|
||||
[error] = await safe(users.setPassword(userObject, req.body.password, AuditSource.fromRequest(req)));
|
||||
if (error && error.reason === BoxError.BAD_FIELD) return next(new HttpError(400, error.message));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
@@ -137,7 +137,7 @@ async function setupAccount(req, res, next) {
|
||||
// if you fix the duration here, the emails and UI have to be fixed as well
|
||||
if (Date.now() - userObject.resetTokenCreationTime > 7 * 24 * 60 * 60 * 1000) return next(new HttpError(401, 'Token expired'));
|
||||
|
||||
const [setupAccountError, accessToken] = await safe(users.setupAccount(userObject, req.body, auditSource.fromRequest(req)));
|
||||
const [setupAccountError, accessToken] = await safe(users.setupAccount(userObject, req.body, AuditSource.fromRequest(req)));
|
||||
if (setupAccountError) return next(BoxError.toHttpError(setupAccountError));
|
||||
|
||||
next(new HttpSuccess(201, { accessToken }));
|
||||
@@ -182,7 +182,7 @@ async function update(req, res, next) {
|
||||
if ('skipBackup' in req.body && typeof req.body.skipBackup !== 'boolean') return next(new HttpError(400, 'skipBackup must be a boolean'));
|
||||
|
||||
// this only initiates the update, progress can be checked via the progress route
|
||||
const [error, taskId] = await safe(updater.updateToLatest(req.body, auditSource.fromRequest(req)));
|
||||
const [error, taskId] = await safe(updater.updateToLatest(req.body, AuditSource.fromRequest(req)));
|
||||
if (error && error.reason === BoxError.NOT_FOUND) return next(new HttpError(422, error.message));
|
||||
if (error && error.reason === BoxError.BAD_STATE) return next(new HttpError(409, error.message));
|
||||
if (error) return next(new HttpError(500, error));
|
||||
@@ -265,7 +265,7 @@ async function getLogStream(req, res, next) {
|
||||
async function updateDashboardDomain(req, res, next) {
|
||||
if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
||||
|
||||
const [error] = await safe(cloudron.updateDashboardDomain(req.body.domain, auditSource.fromRequest(req)));
|
||||
const [error] = await safe(cloudron.updateDashboardDomain(req.body.domain, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204, {}));
|
||||
@@ -274,7 +274,7 @@ async function updateDashboardDomain(req, res, next) {
|
||||
async function prepareDashboardDomain(req, res, next) {
|
||||
if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
||||
|
||||
const [error, taskId] = await safe(cloudron.prepareDashboardDomain(req.body.domain, auditSource.fromRequest(req)));
|
||||
const [error, taskId] = await safe(cloudron.prepareDashboardDomain(req.body.domain, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
@@ -283,7 +283,7 @@ async function prepareDashboardDomain(req, res, next) {
|
||||
async function renewCerts(req, res, next) {
|
||||
if ('domain' in req.body && typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
||||
|
||||
const [error, taskId] = await safe(cloudron.renewCerts({ domain: req.body.domain || null }, auditSource.fromRequest(req)));
|
||||
const [error, taskId] = await safe(cloudron.renewCerts({ domain: req.body.domain || null }, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
|
||||
Reference in New Issue
Block a user