diff --git a/core/server/api/canary/users.js b/core/server/api/canary/users.js index 955df58754..f9cb703c3e 100644 --- a/core/server/api/canary/users.js +++ b/core/server/api/canary/users.js @@ -1,5 +1,6 @@ const Promise = require('bluebird'); const common = require('../../lib/common'); +const backupDatabase = require('../../data/db/backup'); const models = require('../../models'); const permissionsService = require('../../services/permissions'); const ALLOWED_INCLUDES = ['count.posts', 'permissions', 'roles', 'roles.permissions']; @@ -106,7 +107,6 @@ module.exports = { }, destroy: { - statusCode: 204, headers: { cacheInvalidate: true }, @@ -121,7 +121,9 @@ module.exports = { } }, permissions: true, - query(frame) { + async query(frame) { + const filename = await backupDatabase(); + return models.Base.transaction((t) => { frame.options.transacting = t; @@ -129,7 +131,7 @@ module.exports = { models.Post.destroyByAuthor(frame.options) ]).then(() => { return models.User.destroy(Object.assign({status: 'all'}, frame.options)); - }).return(null); + }).return(filename); }).catch((err) => { return Promise.reject(new common.errors.NoPermissionError({ err: err diff --git a/core/server/api/canary/utils/serializers/output/users.js b/core/server/api/canary/utils/serializers/output/users.js index 1a9257c4d9..79516dcf12 100644 --- a/core/server/api/canary/utils/serializers/output/users.js +++ b/core/server/api/canary/utils/serializers/output/users.js @@ -25,6 +25,16 @@ module.exports = { this.read(...arguments); }, + destroy(filename, apiConfig, frame) { + debug('destroy'); + + frame.response = { + meta: { + filename: filename + } + }; + }, + changePassword(models, apiConfig, frame) { debug('changePassword'); diff --git a/core/test/acceptance/admin/users_spec.js b/core/test/acceptance/admin/users_spec.js index 55de36edee..ba719b319b 100644 --- a/core/test/acceptance/admin/users_spec.js +++ b/core/test/acceptance/admin/users_spec.js @@ -250,9 +250,11 @@ describe('User API', function () { return request .delete(localUtils.API.getApiQuery(`users/${userId}`)) .set('Origin', config.get('url')) - .expect(204); + .expect(200); }) - .then(() => { + .then((res) => { + should.exist(res.body.meta.filename); + return request .get(localUtils.API.getApiQuery(`users/${userId}/`)) .set('Origin', config.get('url'))