Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZMS-130 #632

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
147 changes: 116 additions & 31 deletions lib/api/autoreply.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,57 @@ const tools = require('../tools');
const roles = require('../roles');
const { sessSchema, sessIPSchema, booleanSchema } = require('../schemas');
const { publish, AUTOREPLY_USER_DISABLED, AUTOREPLY_USER_ENABLED } = require('../events');
const { userId } = require('../schemas/request/general-schemas');
const { successRes } = require('../schemas/response/general-schemas');

module.exports = (db, server) => {
server.put(
'/users/:user/autoreply',
{
path: '/users/:user/autoreply',
tags: ['Autoreplies'],
summary: 'Update Autoreply information',
validationObjs: {
requestBody: {
status: booleanSchema.description('Is the autoreply enabled (true) or not (false)'),
name: Joi.string().allow('').trim().max(128).description('Name that is used for the From: header in autoreply message'),
subject: Joi.string()
.allow('')
.trim()
.max(2 * 1024)
.description('Subject line for the autoreply. If empty then uses subject of the original message'),
text: Joi.string()
.allow('')
.trim()
.max(128 * 1024)
.description('Plaintext formatted content of the autoreply message'),
html: Joi.string()
.allow('')
.trim()
.max(128 * 1024)
.description('HTML formatted content of the autoreply message'),
start: Joi.date().empty('').allow(false).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'),
sess: sessSchema,
ip: sessIPSchema
},
queryParams: {},
pathParams: {
user: userId
},
response: {
200: { description: 'Success', model: Joi.object({ success: successRes, id: Joi.string().required().description('Autoreply ID') }) }
}
}
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
user: Joi.string().hex().lowercase().length(24).required(),
status: booleanSchema,
name: Joi.string().allow('').trim().max(128),
subject: Joi.string()
.allow('')
.trim()
.max(2 * 1024),
text: Joi.string()
.allow('')
.trim()
.max(128 * 1024),
html: Joi.string()
.allow('')
.trim()
.max(128 * 1024),
start: Joi.date().empty('').allow(false),
end: Joi.date().empty('').allow(false),
sess: sessSchema,
ip: sessIPSchema
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;

const schema = Joi.object({
...pathParams,
...requestBody,
...queryParams
});

const result = schema.validate(req.params, {
Expand Down Expand Up @@ -95,14 +119,58 @@ module.exports = (db, server) => {
);

server.get(
'/users/:user/autoreply',
{
path: '/users/:user/autoreply',
tags: ['Autoreplies'],
summary: 'Request Autoreply information',
validationObjs: {
requestBody: {},
queryParams: {
sess: sessSchema,
ip: sessIPSchema
},
pathParams: { user: userId },
response: {
200: {
description: 'Success',
model: Joi.object({
success: successRes,
status: booleanSchema.description('Is the autoreply enabled (true) or not (false)'),
name: Joi.string().allow('').trim().max(128).description('Name that is used for the From: header in autoreply message'),
subject: Joi.string()
.allow('')
.trim()
.max(2 * 1024)
.description('Subject line for the autoreply. If empty then uses subject of the original message'),
text: Joi.string()
.allow('')
.trim()
.max(128 * 1024)
.description('Plaintext formatted content of the autoreply message'),
html: Joi.string()
.allow('')
.trim()
.max(128 * 1024)
.description('HTML formatted content of the autoreply message'),
start: Joi.date()
.empty('')
.allow(false)
.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')
})
}
}
}
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
user: Joi.string().hex().lowercase().length(24).required(),
sess: sessSchema,
ip: sessIPSchema
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;

const schema = Joi.object({
...pathParams,
...requestBody,
...queryParams
});

const result = schema.validate(req.params, {
Expand Down Expand Up @@ -145,14 +213,31 @@ module.exports = (db, server) => {
);

server.del(
'/users/:user/autoreply',
{
path: '/users/:user/autoreply',
tags: ['Autoreplies'],
summary: 'Delete Autoreply information',
validationObjs: {
requestBody: {},
queryParams: {
sess: sessSchema,
ip: sessIPSchema
},
pathParams: {
user: userId
},
reponse: { 200: { description: 'Success', model: Joi.object({ success: successRes }) } }
}
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
user: Joi.string().hex().lowercase().length(24).required(),
sess: sessSchema,
ip: sessIPSchema
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;

const schema = Joi.object({
...pathParams,
...requestBody,
...queryParams
});

const result = schema.validate(req.params, {
Expand Down