Skip to content

Commit 60b6636

Browse files
committed
added Delete a User, Return recovery info for a deleted User, Cancel user deletion task - endpoints to API generation
1 parent c8e05ac commit 60b6636

File tree

1 file changed

+118
-16
lines changed

1 file changed

+118
-16
lines changed

lib/api/users.js

Lines changed: 118 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,15 +2208,54 @@ module.exports = (db, server, userHandler, settingsHandler) => {
22082208
);
22092209

22102210
server.del(
2211-
'/users/:user',
2211+
{
2212+
path: '/users/:user',
2213+
summary: 'Delete a User',
2214+
description:
2215+
'This method deletes user and address entries from DB and schedules a background task to delete messages. You can call this method several times even if the user has already been deleted, in case there are still some pending messages.',
2216+
tags: ['Users'],
2217+
validationObjs: {
2218+
requestBody: {},
2219+
queryParams: {
2220+
deleteAfter: Joi.date()
2221+
.empty('')
2222+
.allow(false)
2223+
.default(false)
2224+
.description(
2225+
'Delete user entry from registry but keep all user data until provided date. User account is fully recoverable up to that date.'
2226+
),
2227+
sess: sessSchema,
2228+
ip: sessIPSchema
2229+
},
2230+
pathParams: {
2231+
user: userId
2232+
},
2233+
response: {
2234+
200: {
2235+
description: 'Success',
2236+
model: Joi.object({
2237+
success: successRes,
2238+
code: Joi.string().example('TaskScheduled').description('Task code. Should be TaskScheduled'),
2239+
user: Joi.string().description('User ID'),
2240+
addresses: Joi.object({
2241+
deleted: Joi.number().description('Number of deleted addresses')
2242+
}),
2243+
deleteAfter: Joi.date().description('Delete after date'),
2244+
task: Joi.string().description('Task ID')
2245+
})
2246+
}
2247+
}
2248+
}
2249+
},
22122250
tools.responseWrapper(async (req, res) => {
22132251
res.charSet('utf-8');
22142252

2215-
const schema = Joi.object().keys({
2216-
user: Joi.string().hex().lowercase().length(24).required(),
2217-
deleteAfter: Joi.date().empty('').allow(false).default(false),
2218-
sess: sessSchema,
2219-
ip: sessIPSchema
2253+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
2254+
2255+
const schema = Joi.object({
2256+
...pathParams,
2257+
...requestBody,
2258+
...queryParams
22202259
});
22212260

22222261
const result = schema.validate(req.params, {
@@ -2262,14 +2301,44 @@ module.exports = (db, server, userHandler, settingsHandler) => {
22622301
);
22632302

22642303
server.get(
2265-
'/users/:user/restore',
2304+
{
2305+
path: '/users/:user/restore',
2306+
summary: 'Return recovery info for a deleted user',
2307+
tags: ['Users'],
2308+
validationObjs: {
2309+
requestBody: {},
2310+
queryParams: {
2311+
sess: sessSchema,
2312+
ip: sessIPSchema
2313+
},
2314+
pathParams: {
2315+
user: userId
2316+
},
2317+
response: {
2318+
200: {
2319+
description: 'Success',
2320+
model: Joi.object({
2321+
success: successRes,
2322+
user: Joi.string().description('ID of the deleted User').required(),
2323+
username: Joi.string().description('Username of the User').required(),
2324+
storageUsed: Joi.number().description('Calculated quota usage for the user').required(),
2325+
tags: Joi.array().items(Joi.string()).description('List of tags associated with the User').required(),
2326+
deleted: Joi.date().description('Datestring of the time the user was deleted').required(),
2327+
recoverableAddresses: Joi.array().items(Joi.string()).description('List of email addresses that can be restored').required()
2328+
})
2329+
}
2330+
}
2331+
}
2332+
},
22662333
tools.responseWrapper(async (req, res) => {
22672334
res.charSet('utf-8');
22682335

2269-
const schema = Joi.object().keys({
2270-
user: Joi.string().hex().lowercase().length(24).required(),
2271-
sess: sessSchema,
2272-
ip: sessIPSchema
2336+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
2337+
2338+
const schema = Joi.object({
2339+
...pathParams,
2340+
...requestBody,
2341+
...queryParams
22732342
});
22742343

22752344
const result = schema.validate(req.params, {
@@ -2318,14 +2387,47 @@ module.exports = (db, server, userHandler, settingsHandler) => {
23182387
);
23192388

23202389
server.post(
2321-
'/users/:user/restore',
2390+
{
2391+
path: '/users/:user/restore',
2392+
summary: 'Cancel user deletion task',
2393+
description:
2394+
'Use this endpoint to cancel a timed deletion task scheduled by DELETE /user/{id}. If user data is not yet deleted then the account is fully recovered, except any email addresses that might have been already recycled',
2395+
tags: ['Users'],
2396+
validationObjs: {
2397+
requestBody: {
2398+
sess: sessSchema,
2399+
ip: sessIPSchema
2400+
},
2401+
queryParams: {},
2402+
pathParams: {
2403+
user: userId
2404+
},
2405+
response: {
2406+
200: {
2407+
description: 'Success',
2408+
model: Joi.object({
2409+
success: successRes,
2410+
code: Joi.string().required().description('Task status code'),
2411+
user: Joi.string().description('User ID'),
2412+
task: Joi.string().description('Existing task id'),
2413+
addresses: Joi.object({
2414+
recovered: Joi.number().description('Number of recovered addresses'),
2415+
main: Joi.string().description('Main address')
2416+
})
2417+
})
2418+
}
2419+
}
2420+
}
2421+
},
23222422
tools.responseWrapper(async (req, res) => {
23232423
res.charSet('utf-8');
23242424

2325-
const schema = Joi.object().keys({
2326-
user: Joi.string().hex().lowercase().length(24).required(),
2327-
sess: sessSchema,
2328-
ip: sessIPSchema
2425+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
2426+
2427+
const schema = Joi.object({
2428+
...pathParams,
2429+
...requestBody,
2430+
...queryParams
23292431
});
23302432

23312433
const result = schema.validate(req.params, {

0 commit comments

Comments
 (0)