mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-09-20 15:26:03 +08:00
added api endpoint for audit info
This commit is contained in:
parent
cf8d8f28cd
commit
dde106c039
|
@ -115,6 +115,102 @@ module.exports = (db, server, auditHandler) => {
|
|||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {get} /audit/:audit Request Audit Info
|
||||
* @apiName GetAudit
|
||||
* @apiGroup Audit
|
||||
* @apiDescription This method returns information about stored audit
|
||||
* @apiHeader {String} X-Access-Token Optional access token if authentication is enabled
|
||||
* @apiHeaderExample {json} Header-Example:
|
||||
* {
|
||||
* "X-Access-Token": "59fc66a03e54454869460e45"
|
||||
* }
|
||||
*
|
||||
* @apiParam {String} audit ID of the Audit
|
||||
*
|
||||
* @apiSuccess {Boolean} success Indicates successful response
|
||||
* @apiSuccess {String} user Users unique ID.
|
||||
* @apiSuccess {String} [start] Start time as ISO date
|
||||
* @apiSuccess {String} [end] End time as ISO date
|
||||
* @apiSuccess {String} expires Expiration date. Audit data is deleted after this date
|
||||
*
|
||||
* @apiError error Description of the error
|
||||
*
|
||||
* @apiExample {curl} Example usage:
|
||||
* curl -i "http://localhost:8080/audit/59fc66a03e54454869460e45/export.mbox"
|
||||
*
|
||||
* @apiSuccessExample {text} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "success": true,
|
||||
* "id": "59fc66a03e54454869460e45",
|
||||
* "user": "59ef21aef255ed1d9d790e7a",
|
||||
* "start": "2018-11-21T14:17:15.833Z",
|
||||
* "end": "2019-11-21T14:17:15.833Z",
|
||||
* "expires": "2020-11-21T14:17:15.833Z",
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample {json} Error-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "error": "Audit not found",
|
||||
* "code": "AuditNotFoundError"
|
||||
* }
|
||||
*/
|
||||
server.get(
|
||||
'/audit/:audit',
|
||||
tools.asyncifyJson(async (req, res, next) => {
|
||||
res.charSet('utf-8');
|
||||
|
||||
const schema = Joi.object().keys({
|
||||
audit: Joi.string()
|
||||
.hex()
|
||||
.lowercase()
|
||||
.length(24)
|
||||
.required()
|
||||
});
|
||||
|
||||
const result = Joi.validate(req.params, schema, {
|
||||
abortEarly: false,
|
||||
convert: true
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
});
|
||||
return next();
|
||||
}
|
||||
|
||||
// permissions check
|
||||
req.validate(roles.can(req.role).readAny('audit'));
|
||||
|
||||
let auditData = await db.database.collection('audits').findOne({ _id: new ObjectID(req.params.audit) });
|
||||
if (!auditData) {
|
||||
res.status(404);
|
||||
res.json({
|
||||
error: 'Audit not found',
|
||||
code: 'AuditNotFoundError'
|
||||
});
|
||||
return next();
|
||||
}
|
||||
|
||||
res.status(200);
|
||||
res.json({
|
||||
success: true,
|
||||
id: auditData._id,
|
||||
user: auditData.user,
|
||||
start: auditData.start && auditData.start.toISOString(),
|
||||
end: auditData.start && auditData.start.toISOString(),
|
||||
expires: auditData.start && auditData.start.toISOString(),
|
||||
import: auditData.import
|
||||
});
|
||||
return next();
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {get} /audit/:audit/export.mbox Export Audited Emails
|
||||
* @apiName GetAuditEmails
|
||||
|
|
Loading…
Reference in a new issue