mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-03 00:15:11 +03:00
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:
parent
67f856c572
commit
afe11c2b06
@ -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
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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'))
|
||||
|
Loading…
Reference in New Issue
Block a user