From 49ccc6b66d648406d014b0fa1add0aeb310e1194 Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Mon, 16 Dec 2019 20:33:20 +0700 Subject: [PATCH] Basic flow for triggering db export on user deletion --- app/controllers/staff/user.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/controllers/staff/user.js b/app/controllers/staff/user.js index 57b2f947c..0713516d9 100644 --- a/app/controllers/staff/user.js +++ b/app/controllers/staff/user.js @@ -84,11 +84,13 @@ export default Controller.extend({ }, deleteUser() { - return this._deleteUser().then(() => { - this._deleteUserSuccess(); - }, () => { - this._deleteUserFailure(); - }); + return this._deleteUser() + .then(filename => this._exportDb(filename)) + .then(() => { + this._deleteUserSuccess(); + }, () => { + this._deleteUserFailure(); + }); }, toggleDeleteUserModal() { @@ -356,6 +358,21 @@ export default Controller.extend({ this.notifications.showAlert('The user could not be deleted. Please try again.', {type: 'error', key: 'user.delete.failed'}); }, + async _exportDb(filename) { + let exportUrl = this.get('ghostPaths.url').api('db'); + let downloadURL = `${exportUrl}?filename=${filename}`; + let iframe = document.getElementById('iframeDownload'); + + if (!iframe) { + iframe = document.createElement('iframe'); + iframe.id = 'iframeDownload'; + iframe.style.display = 'none'; + document.body.append(iframe); + } + + iframe.setAttribute('src', downloadURL); + }, + updateSlug: task(function* (newSlug) { let slug = this.get('user.slug');