mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-09-20 07:16:05 +08:00
fix(api-autoreplies): Added logging to graylog. Autoreply docs have a created field now ZMS-127 (#633)
* Update Autoreply information api endpoint added to api docs generation * Delete Autoreply information api endpoint added to api docs generation * Request Autoreply information api endpoint added to api docs generation * autoreply now contains the created field to check when it was created. Added logging to graylog * make created timestamp second precision. Fix tests * autoreply.js add optional chaining
This commit is contained in:
parent
f19540f715
commit
f6f5f5eb65
|
@ -44,7 +44,13 @@ module.exports = (db, server) => {
|
||||||
user: userId
|
user: userId
|
||||||
},
|
},
|
||||||
response: {
|
response: {
|
||||||
200: { description: 'Success', model: Joi.object({ success: successRes, id: Joi.string().required().description('Autoreply ID') }) }
|
200: {
|
||||||
|
description: 'Success',
|
||||||
|
model: Joi.object({
|
||||||
|
success: successRes,
|
||||||
|
id: Joi.string().required().description('Autoreply ID')
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -109,11 +115,32 @@ module.exports = (db, server) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const r = await db.database.collection('autoreplies').updateOne({ user }, { $set: result.value }, { upsert: true });
|
result.value.created = new Date();
|
||||||
|
result.value.created.setMilliseconds(0);
|
||||||
|
result.value.created = result.value.created.toISOString();
|
||||||
|
|
||||||
|
const autoreplyData = await db.database
|
||||||
|
.collection('autoreplies')
|
||||||
|
.findOneAndUpdate({ user }, { $set: result.value }, { returnDocument: 'after', upsert: true });
|
||||||
|
|
||||||
|
server.loggelf({
|
||||||
|
short_message: `[AUTOREPLY] ${autoreplyData.lastErrorObject?.upserted ? 'create' : 'update'}`,
|
||||||
|
_mail_action: `${autoreplyData.lastErrorObject?.upserted ? 'Create' : 'Update'} autoreply`,
|
||||||
|
_user: user,
|
||||||
|
_autoreply_id: autoreplyData.value?._id.toString(),
|
||||||
|
_autoreply_status: autoreplyData.value?.status,
|
||||||
|
_autoreply_name: autoreplyData.value?.name,
|
||||||
|
_autoreply_subject: autoreplyData.value?.subject,
|
||||||
|
_autoreply_start: autoreplyData.value?.start,
|
||||||
|
_autoreply_end: autoreplyData.value?.end,
|
||||||
|
_autoreply_created: autoreplyData.value?.created,
|
||||||
|
_sess: result.value.sess,
|
||||||
|
_ip: result.value.ip
|
||||||
|
});
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
success: true,
|
success: true,
|
||||||
id: ((r.upsertedId && r.upsertedId._id) || '').toString()
|
id: autoreplyData.value._id.toString()
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -156,7 +183,8 @@ module.exports = (db, server) => {
|
||||||
.empty('')
|
.empty('')
|
||||||
.allow(false)
|
.allow(false)
|
||||||
.description('Datestring of the start of the autoreply or boolean false to disable start checks'),
|
.description('Datestring of the start of the autoreply or boolean false to disable start checks'),
|
||||||
end: Joi.date().empty('').allow(false).description('Datestring of the end of the autoreply or boolean false to disable end checks')
|
end: Joi.date().empty('').allow(false).description('Datestring of the end of the autoreply or boolean false to disable end checks'),
|
||||||
|
created: Joi.date().required().description('Datestring of when the Autoreply was created')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +235,8 @@ module.exports = (db, server) => {
|
||||||
text: entry.text || '',
|
text: entry.text || '',
|
||||||
html: entry.html || '',
|
html: entry.html || '',
|
||||||
start: entry.start || false,
|
start: entry.start || false,
|
||||||
end: entry.end || false
|
end: entry.end || false,
|
||||||
|
created: entry.created || entry._id?.getTimestamp() || false
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -271,7 +300,16 @@ module.exports = (db, server) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.database.collection('autoreplies').deleteOne({ user });
|
const autoreplyData = await db.database.collection('autoreplies').findOneAndDelete({ user }, { projection: { _id: true } });
|
||||||
|
|
||||||
|
server.loggelf({
|
||||||
|
short_message: '[AUTOREPLY] Delete',
|
||||||
|
_mail_action: 'Delete autoreply',
|
||||||
|
_user: user,
|
||||||
|
_autoreply_id: autoreplyData.value?._id.toString(),
|
||||||
|
_sess: result.value.sess,
|
||||||
|
_ip: result.value.ip
|
||||||
|
});
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
success: true
|
success: true
|
||||||
|
|
|
@ -11,6 +11,7 @@ chai.config.includeStack = true;
|
||||||
const config = require('wild-config');
|
const config = require('wild-config');
|
||||||
|
|
||||||
const server = supertest.agent(`http://127.0.0.1:${config.api.port}`);
|
const server = supertest.agent(`http://127.0.0.1:${config.api.port}`);
|
||||||
|
const ObjectId = require('mongodb').ObjectId;
|
||||||
|
|
||||||
describe('API tests', function () {
|
describe('API tests', function () {
|
||||||
let userId, asp, address, inbox;
|
let userId, asp, address, inbox;
|
||||||
|
@ -416,7 +417,8 @@ describe('API tests', function () {
|
||||||
text: '',
|
text: '',
|
||||||
html: '',
|
html: '',
|
||||||
start: false,
|
start: false,
|
||||||
end: false
|
end: false,
|
||||||
|
created: false
|
||||||
});
|
});
|
||||||
|
|
||||||
r = await server
|
r = await server
|
||||||
|
@ -432,6 +434,8 @@ describe('API tests', function () {
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(r.body.success).to.be.true;
|
expect(r.body.success).to.be.true;
|
||||||
|
|
||||||
|
const autoreplyId = new ObjectId(r.body._id);
|
||||||
|
|
||||||
r = await server.get(`/users/${userId}/autoreply`).expect(200);
|
r = await server.get(`/users/${userId}/autoreply`).expect(200);
|
||||||
expect(r.body).to.deep.equal({
|
expect(r.body).to.deep.equal({
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -441,7 +445,8 @@ describe('API tests', function () {
|
||||||
text: 'Away from office until Dec.19',
|
text: 'Away from office until Dec.19',
|
||||||
html: '',
|
html: '',
|
||||||
start: '2017-11-15T00:00:00.000Z',
|
start: '2017-11-15T00:00:00.000Z',
|
||||||
end: '2017-12-19T00:00:00.000Z'
|
end: '2017-12-19T00:00:00.000Z',
|
||||||
|
created: autoreplyId.getTimestamp().toISOString()
|
||||||
});
|
});
|
||||||
|
|
||||||
r = await server
|
r = await server
|
||||||
|
@ -463,7 +468,8 @@ describe('API tests', function () {
|
||||||
text: 'Away from office until Dec.19',
|
text: 'Away from office until Dec.19',
|
||||||
html: '',
|
html: '',
|
||||||
start: false,
|
start: false,
|
||||||
end: '2017-12-19T00:00:00.000Z'
|
end: '2017-12-19T00:00:00.000Z',
|
||||||
|
created: autoreplyId.getTimestamp().toISOString()
|
||||||
});
|
});
|
||||||
|
|
||||||
await server.delete(`/users/${userId}/autoreply`).expect(200);
|
await server.delete(`/users/${userId}/autoreply`).expect(200);
|
||||||
|
@ -476,7 +482,8 @@ describe('API tests', function () {
|
||||||
text: '',
|
text: '',
|
||||||
html: '',
|
html: '',
|
||||||
start: false,
|
start: false,
|
||||||
end: false
|
end: false,
|
||||||
|
created: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue