Rewrote delete into generator function

- Wasn't necessary, but thought this might fix the problem when there's no 'meta' in the reponse object
This commit is contained in:
Nazar Gargol 2019-12-17 12:12:45 +07:00 committed by Daniel Lockyer
parent 70524c55a4
commit f42f2a29a3
2 changed files with 16 additions and 19 deletions

View File

@ -83,16 +83,6 @@ export default Controller.extend({
this.set('dirtyAttributes', true);
},
deleteUser() {
return this._deleteUser()
.then(filename => this._exportDb(filename))
.then(() => {
this._deleteUserSuccess();
}, () => {
this._deleteUserFailure();
});
},
toggleDeleteUserModal() {
if (this.deleteUserActionIsVisible) {
this.toggleProperty('showDeleteUserModal');
@ -341,13 +331,6 @@ export default Controller.extend({
}
},
_deleteUser() {
if (this.deleteUserActionIsVisible) {
let user = this.user;
return user.destroyRecord();
}
},
_deleteUserSuccess() {
this.notifications.closeAlerts('user.delete');
this.store.unloadAll('post');
@ -358,7 +341,7 @@ 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) {
_exportDb(filename) {
let exportUrl = this.get('ghostPaths.url').api('db');
let downloadURL = `${exportUrl}?filename=${filename}`;
let iframe = document.getElementById('iframeDownload');
@ -373,6 +356,20 @@ export default Controller.extend({
iframe.setAttribute('src', downloadURL);
},
deleteUser: task(function *() {
try {
const result = yield this.user.destroyRecord();
if (result.get('meta') && result.get('meta.filename')) {
yield this._exportDb(result.meta.filename);
}
this._deleteUserSuccess();
} catch {
this._deleteUserFailure();
}
}),
updateSlug: task(function* (newSlug) {
let slug = this.get('user.slug');

View File

@ -70,7 +70,7 @@
{{#if this.showDeleteUserModal}}
<GhFullscreenModal @modal="delete-user"
@model={{this.user}}
@confirm={{action "deleteUser"}}
@confirm={{action (perform this.deleteUser)}}
@close={{action "toggleDeleteUserModal"}}
@modifier="action wide" />
{{/if}}