make auditsource a class

this allows us to use AuditSource for the class and auditSource for
the instances!
This commit is contained in:
Girish Ramakrishnan
2021-09-30 09:50:30 -07:00
parent 339fdfbea1
commit 445c83c8b9
22 changed files with 138 additions and 131 deletions
+6 -6
View File
@@ -13,7 +13,7 @@ exports = module.exports = {
};
const assert = require('assert'),
auditSource = require('../auditsource.js'),
AuditSource = require('../auditsource.js'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
HttpError = require('connect-lastmile').HttpError,
@@ -74,7 +74,7 @@ async function update(req, res, next) {
req.body.password = '<redacted>'; // this will prevent logs from displaying plain text password
}
const [error] = await safe(users.update(req.user, data, auditSource.fromRequest(req)));
const [error] = await safe(users.update(req.user, data, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204));
@@ -113,7 +113,7 @@ async function setPassword(req, res, next) {
if (typeof req.body.newPassword !== 'string') return next(new HttpError(400, 'newPassword must be a string'));
const [error] = await safe(users.setPassword(req.user, req.body.newPassword, auditSource.fromRequest(req)));
const [error] = await safe(users.setPassword(req.user, req.body.newPassword, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204));
@@ -122,7 +122,7 @@ async function setPassword(req, res, next) {
async function setTwoFactorAuthenticationSecret(req, res, next) {
assert.strictEqual(typeof req.user, 'object');
const [error, result] = await safe(users.setTwoFactorAuthenticationSecret(req.user.id, auditSource.fromRequest(req)));
const [error, result] = await safe(users.setTwoFactorAuthenticationSecret(req.user.id, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(201, { secret: result.secret, qrcode: result.qrcode }));
@@ -134,7 +134,7 @@ async function enableTwoFactorAuthentication(req, res, next) {
if (!req.body.totpToken || typeof req.body.totpToken !== 'string') return next(new HttpError(400, 'totpToken must be a nonempty string'));
const [error] = await safe(users.enableTwoFactorAuthentication(req.user.id, req.body.totpToken, auditSource.fromRequest(req)));
const [error] = await safe(users.enableTwoFactorAuthentication(req.user.id, req.body.totpToken, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(202, {}));
@@ -143,7 +143,7 @@ async function enableTwoFactorAuthentication(req, res, next) {
async function disableTwoFactorAuthentication(req, res, next) {
assert.strictEqual(typeof req.user, 'object');
const [error] = await safe(users.disableTwoFactorAuthentication(req.user.id, auditSource.fromRequest(req)));
const [error] = await safe(users.disableTwoFactorAuthentication(req.user.id, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(202, {}));