Added basic backup implementation for users DELETE endpoint

- The filename is returned to be able to fetch the backup on demand
- Wasn't able to limit exported tables as exporter doesn't support such functionality
This commit is contained in:
Nazar Gargol 2019-12-16 14:23:46 +07:00 committed by Daniel Lockyer
parent 67f856c572
commit afe11c2b06
3 changed files with 19 additions and 5 deletions

View File

@ -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

View File

@ -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');

View File

@ -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'))